Page MenuHomeFreeBSD

D15369.1777299082.diff
No OneTemporary

Size
9 KB
Referenced Files
None
Subscribers
None

D15369.1777299082.diff

Index: lib/libc/powerpc64/string/Makefile.inc
===================================================================
--- /dev/null
+++ lib/libc/powerpc64/string/Makefile.inc
@@ -0,0 +1,6 @@
+# $FreeBSD$
+
+MDSRCS+= \
+ strncpy_arch_2_05.S \
+ strncpy.c \
+ strncpy_resolver.c
Index: lib/libc/powerpc64/string/strncpy.c
===================================================================
--- lib/libc/powerpc64/string/strncpy.c
+++ lib/libc/powerpc64/string/strncpy.c
@@ -1,11 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
+ * Copyright (c) 2019 Leandro Lupori
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -15,14 +9,13 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * 3. Neither the name of the author nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -32,33 +25,9 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strncpy.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <string.h>
-
-/*
- * Copy src to dst, truncating or null-padding to always copy n bytes.
- * Return dst.
- */
-char *
-strncpy(char * __restrict dst, const char * __restrict src, size_t n)
-{
- if (n != 0) {
- char *d = dst;
- const char *s = src;
-
- do {
- if ((*d++ = *s++) == '\0') {
- /* NUL pad the remaining n-1 bytes */
- while (--n != 0)
- *d++ = '\0';
- break;
- }
- } while (--n != 0);
- }
- return (dst);
-}
+#define WEAK_STRNCPY
+#include "../../string/strncpy.c"
Index: lib/libc/powerpc64/string/strncpy_arch_2_05.S
===================================================================
--- /dev/null
+++ lib/libc/powerpc64/string/strncpy_arch_2_05.S
@@ -0,0 +1,131 @@
+/*-
+ * Copyright (c) 2018 Instituto de Pesquisas Eldorado
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the author nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <machine/asm.h>
+__FBSDID("$FreeBSD$");
+
+ENTRY(__strncpy_arch_2_05)
+ stdu %r1,-40(%r1)
+ mflr %r0
+ std %r0,16(%r1)
+ std %r3,32(%r1)
+
+ xor %r6,%r6,%r6 /* fixed 0 reg */
+
+/* align loop */
+ addi %r3,%r3,-1
+.Lalign_loop:
+ /* len? */
+ cmpdi %r5,0
+ beq .Lexit
+ /* aligned? */
+ andi. %r0,%r4,7
+ beq .Ldw_copy
+ /* copy */
+ lbz %r7,0(%r4)
+ stbu %r7,1(%r3)
+ addi %r4,%r4,1
+ addi %r5,%r5,-1
+ /* zero? */
+ cmpdi %r7,0
+ beq .Lzero
+ b .Lalign_loop
+
+/* dword copy loop */
+.Ldw_copy:
+ /* prepare src and dst to use load/store and update */
+ addi %r3,%r3,-7
+ addi %r4,%r4,-8
+.Ldw_copy_loop:
+ cmpdi %r5,8
+ blt .Lbyte_copy
+
+ ldu %r0,8(%r4)
+ /* check for 0 */
+ cmpb %r7,%r0,%r6
+ cmpdi %r7,0
+ bne .Lbyte_copy_and_zero
+ /* copy to dst */
+ stdu %r0,8(%r3)
+ addi %r5,%r5,-8
+ b .Ldw_copy_loop
+
+/* Copy remaining src bytes, zero-out buffer
+ * Note: r5 will be >= 8
+ */
+.Lbyte_copy_and_zero:
+ addi %r3,%r3,7
+ addi %r4,%r4,-1
+.Lbyte_copy_and_zero_loop:
+ lbzu %r7,1(%r4)
+ stbu %r7,1(%r3)
+ addi %r5,%r5,-1
+ cmpdi %r7,0
+ beq .Lzero
+ b .Lbyte_copy_and_zero_loop
+
+/* zero-out remaining dst bytes */
+.Lzero:
+ addi %r3,%r3,1
+ li %r4,0
+ /* r5 has len already */
+ bl memset
+ nop
+ b .Lexit
+
+/* copy remaining (< 8) bytes */
+.Lbyte_copy:
+ cmpdi %r5,0
+ beq .Lexit
+ addi %r3,%r3,7
+ addi %r4,%r4,7
+ mtctr %r5
+.Lbyte_copy_loop:
+ lbzu %r7,1(%r4)
+ stbu %r7,1(%r3)
+ cmpdi %r7,0
+ /* 0 found: zero out remaining bytes */
+ beq .Lbyte_copy_zero
+ bdnz .Lbyte_copy_loop
+ b .Lexit
+.Lbyte_copy_zero_loop:
+ stbu %r6,1(%r3)
+.Lbyte_copy_zero:
+ bdnz .Lbyte_copy_zero_loop
+
+.Lexit:
+ /* epilogue */
+ ld %r3,32(%r1)
+ ld %r0,16(%r1)
+ mtlr %r0
+ addi %r1,%r1,40
+ blr
+
+END(__strncpy_arch_2_05)
+
+ .section .note.GNU-stack,"",%progbits
Index: lib/libc/powerpc64/string/strncpy_resolver.c
===================================================================
--- lib/libc/powerpc64/string/strncpy_resolver.c
+++ lib/libc/powerpc64/string/strncpy_resolver.c
@@ -1,11 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Chris Torek.
+ * Copyright (c) 2019 Leandro Lupori
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -15,14 +9,13 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * 3. Neither the name of the author nor the names of its contributors may
+ * be used to endorse or promote products derived from this software
*
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -32,33 +25,24 @@
* SUCH DAMAGE.
*/
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)strncpy.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
+
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <string.h>
+#include <machine/cpu.h>
+#include <machine/ifunc.h>
-/*
- * Copy src to dst, truncating or null-padding to always copy n bytes.
- * Return dst.
- */
char *
-strncpy(char * __restrict dst, const char * __restrict src, size_t n)
-{
- if (n != 0) {
- char *d = dst;
- const char *s = src;
+__strncpy_arch_2_05(char * restrict dst, const char * restrict src, size_t len);
+
+char *
+__strncpy(char * restrict dst, const char * restrict src, size_t len);
- do {
- if ((*d++ = *s++) == '\0') {
- /* NUL pad the remaining n-1 bytes */
- while (--n != 0)
- *d++ = '\0';
- break;
- }
- } while (--n != 0);
- }
- return (dst);
+DEFINE_UIFUNC(, char *, strncpy,
+ (char * restrict, const char * restrict, size_t))
+{
+ if (hwcap & PPC_FEATURE_ARCH_2_05)
+ return (__strncpy_arch_2_05);
+ else
+ return (__strncpy);
}
Index: lib/libc/string/strncpy.c
===================================================================
--- lib/libc/string/strncpy.c
+++ lib/libc/string/strncpy.c
@@ -44,8 +44,17 @@
* Copy src to dst, truncating or null-padding to always copy n bytes.
* Return dst.
*/
+#ifdef WEAK_STRNCPY
+__weak_reference(__strncpy, strncpy);
+#endif
+
char *
-strncpy(char * __restrict dst, const char * __restrict src, size_t n)
+#ifdef WEAK_STRNCPY
+__strncpy
+#else
+strncpy
+#endif
+(char * __restrict dst, const char * __restrict src, size_t n)
{
if (n != 0) {
char *d = dst;

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 27, 2:11 PM (15 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28440751
Default Alt Text
D15369.1777299082.diff (9 KB)

Event Timeline