|
|
3b386f |
commit aa70d0563256b8ea053203177f756bca33b5cf37
|
|
|
3b386f |
Author: Anton Blanchard via Libc-alpha <libc-alpha@sourceware.org>
|
|
|
3b386f |
Date: Thu May 14 09:08:35 2020 +1000
|
|
|
3b386f |
|
|
|
3b386f |
powerpc: Optimized stpcpy for POWER9
|
|
|
3b386f |
|
|
|
3b386f |
Add stpcpy support to the POWER9 strcpy. This is up to 40% faster on
|
|
|
3b386f |
small strings and up to 90% faster on long relatively unaligned strings,
|
|
|
3b386f |
compared to the POWER8 version. A few examples:
|
|
|
3b386f |
|
|
|
3b386f |
__stpcpy_power9 __stpcpy_power8
|
|
|
3b386f |
Length 20, alignments in bytes 4/ 4: 2.58246 4.8788
|
|
|
3b386f |
Length 1024, alignments in bytes 1/ 6: 24.8186 47.8528
|
|
|
3b386f |
|
|
|
3b386f |
diff --git a/sysdeps/powerpc/powerpc64/le/power9/stpcpy.S b/sysdeps/powerpc/powerpc64/le/power9/stpcpy.S
|
|
|
3b386f |
new file mode 100644
|
|
|
3b386f |
index 0000000000000000..44425cb1e80ea198
|
|
|
3b386f |
--- /dev/null
|
|
|
3b386f |
+++ b/sysdeps/powerpc/powerpc64/le/power9/stpcpy.S
|
|
|
3b386f |
@@ -0,0 +1,24 @@
|
|
|
3b386f |
+/* Optimized stpcpy implementation for PowerPC64/POWER9.
|
|
|
3b386f |
+ Copyright (C) 2015-2020 Free Software Foundation, Inc.
|
|
|
3b386f |
+ This file is part of the GNU C Library.
|
|
|
3b386f |
+
|
|
|
3b386f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
3b386f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
3b386f |
+ License as published by the Free Software Foundation; either
|
|
|
3b386f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
3b386f |
+
|
|
|
3b386f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
3b386f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
3b386f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
3b386f |
+ Lesser General Public License for more details.
|
|
|
3b386f |
+
|
|
|
3b386f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
3b386f |
+ License along with the GNU C Library; if not, see
|
|
|
3b386f |
+ <https://www.gnu.org/licenses/>. */
|
|
|
3b386f |
+
|
|
|
3b386f |
+#define USE_AS_STPCPY
|
|
|
3b386f |
+#include <sysdeps/powerpc/powerpc64/le/power9/strcpy.S>
|
|
|
3b386f |
+
|
|
|
3b386f |
+weak_alias (__stpcpy, stpcpy)
|
|
|
3b386f |
+libc_hidden_def (__stpcpy)
|
|
|
3b386f |
+libc_hidden_builtin_def (stpcpy)
|
|
|
3b386f |
diff --git a/sysdeps/powerpc/powerpc64/le/power9/strcpy.S b/sysdeps/powerpc/powerpc64/le/power9/strcpy.S
|
|
|
3b386f |
index 5749228054667b2d..ce8f50329177fd06 100644
|
|
|
3b386f |
--- a/sysdeps/powerpc/powerpc64/le/power9/strcpy.S
|
|
|
3b386f |
+++ b/sysdeps/powerpc/powerpc64/le/power9/strcpy.S
|
|
|
3b386f |
@@ -18,19 +18,35 @@
|
|
|
3b386f |
|
|
|
3b386f |
#include <sysdep.h>
|
|
|
3b386f |
|
|
|
3b386f |
-#ifndef STRCPY
|
|
|
3b386f |
-# define STRCPY strcpy
|
|
|
3b386f |
-#endif
|
|
|
3b386f |
+#ifdef USE_AS_STPCPY
|
|
|
3b386f |
+# ifndef STPCPY
|
|
|
3b386f |
+# define FUNC_NAME __stpcpy
|
|
|
3b386f |
+# else
|
|
|
3b386f |
+# define FUNC_NAME STPCPY
|
|
|
3b386f |
+# endif
|
|
|
3b386f |
+#else
|
|
|
3b386f |
+# ifndef STRCPY
|
|
|
3b386f |
+# define FUNC_NAME strcpy
|
|
|
3b386f |
+# else
|
|
|
3b386f |
+# define FUNC_NAME STRCPY
|
|
|
3b386f |
+# endif
|
|
|
3b386f |
+#endif /* !USE_AS_STPCPY */
|
|
|
3b386f |
|
|
|
3b386f |
/* Implements the function
|
|
|
3b386f |
|
|
|
3b386f |
char * [r3] strcpy (char *dest [r3], const char *src [r4])
|
|
|
3b386f |
|
|
|
3b386f |
+ or
|
|
|
3b386f |
+
|
|
|
3b386f |
+ char * [r3] stpcpy (char *dest [r3], const char *src [r4])
|
|
|
3b386f |
+
|
|
|
3b386f |
+ if USE_AS_STPCPY is defined.
|
|
|
3b386f |
+
|
|
|
3b386f |
The implementation can load bytes past a null terminator, but only
|
|
|
3b386f |
up to the next 16B boundary, so it never crosses a page. */
|
|
|
3b386f |
|
|
|
3b386f |
.machine power9
|
|
|
3b386f |
-ENTRY_TOCLESS (STRCPY, 4)
|
|
|
3b386f |
+ENTRY_TOCLESS (FUNC_NAME, 4)
|
|
|
3b386f |
CALL_MCOUNT 2
|
|
|
3b386f |
|
|
|
3b386f |
/* NULL string optimisation */
|
|
|
3b386f |
@@ -53,8 +69,8 @@ ENTRY_TOCLESS (STRCPY, 4)
|
|
|
3b386f |
vperm v0,v18,v0,v1
|
|
|
3b386f |
|
|
|
3b386f |
vcmpequb v6,v0,v18 /* 0xff if byte is NULL, 0x00 otherwise */
|
|
|
3b386f |
- vctzlsbb r8,v6 /* Number of trailing zeroes */
|
|
|
3b386f |
- addi r8,r8,1 /* Add null terminator */
|
|
|
3b386f |
+ vctzlsbb r7,v6 /* Number of trailing zeroes */
|
|
|
3b386f |
+ addi r8,r7,1 /* Add null terminator */
|
|
|
3b386f |
|
|
|
3b386f |
/* r8 = bytes including null
|
|
|
3b386f |
r9 = bytes to get source 16B aligned
|
|
|
3b386f |
@@ -68,6 +84,11 @@ ENTRY_TOCLESS (STRCPY, 4)
|
|
|
3b386f |
sldi r10,r8,56 /* stxvl wants size in top 8 bits */
|
|
|
3b386f |
stxvl 32+v0,r11,r10 /* Partial store */
|
|
|
3b386f |
|
|
|
3b386f |
+#ifdef USE_AS_STPCPY
|
|
|
3b386f |
+ /* stpcpy returns the dest address plus the size not counting the
|
|
|
3b386f |
+ final '\0'. */
|
|
|
3b386f |
+ add r3,r11,r7
|
|
|
3b386f |
+#endif
|
|
|
3b386f |
blr
|
|
|
3b386f |
|
|
|
3b386f |
L(no_null):
|
|
|
3b386f |
@@ -106,28 +127,43 @@ L(loop):
|
|
|
3b386f |
|
|
|
3b386f |
L(tail1):
|
|
|
3b386f |
vctzlsbb r8,v6
|
|
|
3b386f |
- addi r8,r8,1
|
|
|
3b386f |
- sldi r9,r8,56 /* stxvl wants size in top 8 bits */
|
|
|
3b386f |
+ addi r9,r8,1
|
|
|
3b386f |
+ sldi r9,r9,56 /* stxvl wants size in top 8 bits */
|
|
|
3b386f |
stxvl 32+v0,r11,r9
|
|
|
3b386f |
+#ifdef USE_AS_STPCPY
|
|
|
3b386f |
+ /* stpcpy returns the dest address plus the size not counting the
|
|
|
3b386f |
+ final '\0'. */
|
|
|
3b386f |
+ add r3,r11,r8
|
|
|
3b386f |
+#endif
|
|
|
3b386f |
blr
|
|
|
3b386f |
|
|
|
3b386f |
L(tail2):
|
|
|
3b386f |
stxv 32+v0,0(r11)
|
|
|
3b386f |
vctzlsbb r8,v6 /* Number of trailing zeroes */
|
|
|
3b386f |
- addi r8,r8,1 /* Add null terminator */
|
|
|
3b386f |
- sldi r10,r8,56 /* stxvl wants size in top 8 bits */
|
|
|
3b386f |
+ addi r9,r8,1 /* Add null terminator */
|
|
|
3b386f |
+ sldi r10,r9,56 /* stxvl wants size in top 8 bits */
|
|
|
3b386f |
addi r11,r11,16
|
|
|
3b386f |
stxvl 32+v1,r11,r10 /* Partial store */
|
|
|
3b386f |
+#ifdef USE_AS_STPCPY
|
|
|
3b386f |
+ /* stpcpy returns the dest address plus the size not counting the
|
|
|
3b386f |
+ final '\0'. */
|
|
|
3b386f |
+ add r3,r11,r8
|
|
|
3b386f |
+#endif
|
|
|
3b386f |
blr
|
|
|
3b386f |
|
|
|
3b386f |
L(tail3):
|
|
|
3b386f |
stxv 32+v0,0(r11)
|
|
|
3b386f |
stxv 32+v1,16(r11)
|
|
|
3b386f |
vctzlsbb r8,v6 /* Number of trailing zeroes */
|
|
|
3b386f |
- addi r8,r8,1 /* Add null terminator */
|
|
|
3b386f |
- sldi r10,r8,56 /* stxvl wants size in top 8 bits */
|
|
|
3b386f |
+ addi r9,r8,1 /* Add null terminator */
|
|
|
3b386f |
+ sldi r10,r9,56 /* stxvl wants size in top 8 bits */
|
|
|
3b386f |
addi r11,r11,32
|
|
|
3b386f |
stxvl 32+v2,r11,r10 /* Partial store */
|
|
|
3b386f |
+#ifdef USE_AS_STPCPY
|
|
|
3b386f |
+ /* stpcpy returns the dest address plus the size not counting the
|
|
|
3b386f |
+ final '\0'. */
|
|
|
3b386f |
+ add r3,r11,r8
|
|
|
3b386f |
+#endif
|
|
|
3b386f |
blr
|
|
|
3b386f |
|
|
|
3b386f |
L(tail4):
|
|
|
3b386f |
@@ -135,10 +171,17 @@ L(tail4):
|
|
|
3b386f |
stxv 32+v1,16(r11)
|
|
|
3b386f |
stxv 32+v2,32(r11)
|
|
|
3b386f |
vctzlsbb r8,v6 /* Number of trailing zeroes */
|
|
|
3b386f |
- addi r8,r8,1 /* Add null terminator */
|
|
|
3b386f |
- sldi r10,r8,56 /* stxvl wants size in top 8 bits */
|
|
|
3b386f |
+ addi r9,r8,1 /* Add null terminator */
|
|
|
3b386f |
+ sldi r10,r9,56 /* stxvl wants size in top 8 bits */
|
|
|
3b386f |
addi r11,r11,48
|
|
|
3b386f |
stxvl 32+v3,r11,r10 /* Partial store */
|
|
|
3b386f |
+#ifdef USE_AS_STPCPY
|
|
|
3b386f |
+ /* stpcpy returns the dest address plus the size not counting the
|
|
|
3b386f |
+ final '\0'. */
|
|
|
3b386f |
+ add r3,r11,r8
|
|
|
3b386f |
+#endif
|
|
|
3b386f |
blr
|
|
|
3b386f |
-END (STRCPY)
|
|
|
3b386f |
+END (FUNC_NAME)
|
|
|
3b386f |
+#ifndef USE_AS_STPCPY
|
|
|
3b386f |
libc_hidden_builtin_def (strcpy)
|
|
|
3b386f |
+#endif
|
|
|
3b386f |
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
|
|
|
3b386f |
index 17057bcbd694a710..cada6b19bf3c8fab 100644
|
|
|
3b386f |
--- a/sysdeps/powerpc/powerpc64/multiarch/Makefile
|
|
|
3b386f |
+++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile
|
|
|
3b386f |
@@ -32,7 +32,7 @@ sysdep_routines += memcpy-power8-cached memcpy-power7 memcpy-a2 memcpy-power6 \
|
|
|
3b386f |
strncase-power8
|
|
|
3b386f |
|
|
|
3b386f |
ifneq (,$(filter %le,$(config-machine)))
|
|
|
3b386f |
-sysdep_routines += strcmp-power9 strncmp-power9 strcpy-power9
|
|
|
3b386f |
+sysdep_routines += strcmp-power9 strncmp-power9 strcpy-power9 stpcpy-power9
|
|
|
3b386f |
endif
|
|
|
3b386f |
CFLAGS-strncase-power7.c += -mcpu=power7 -funroll-loops
|
|
|
3b386f |
CFLAGS-strncase_l-power7.c += -mcpu=power7 -funroll-loops
|
|
|
3b386f |
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
|
|
|
3b386f |
index 2857fa8f36599afd..b0abc6b61dc15f19 100644
|
|
|
3b386f |
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
|
|
|
3b386f |
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
|
|
|
3b386f |
@@ -98,6 +98,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
|
|
|
3b386f |
|
|
|
3b386f |
/* Support sysdeps/powerpc/powerpc64/multiarch/stpcpy.c. */
|
|
|
3b386f |
IFUNC_IMPL (i, name, stpcpy,
|
|
|
3b386f |
+#ifdef __LITTLE_ENDIAN__
|
|
|
3b386f |
+ IFUNC_IMPL_ADD (array, i, strncmp, hwcap2 & PPC_FEATURE2_ARCH_3_00,
|
|
|
3b386f |
+ __stpcpy_power9)
|
|
|
3b386f |
+#endif
|
|
|
3b386f |
IFUNC_IMPL_ADD (array, i, stpcpy, hwcap2 & PPC_FEATURE2_ARCH_2_07,
|
|
|
3b386f |
__stpcpy_power8)
|
|
|
3b386f |
IFUNC_IMPL_ADD (array, i, stpcpy, hwcap & PPC_FEATURE_HAS_VSX,
|
|
|
3b386f |
diff --git a/sysdeps/powerpc/powerpc64/multiarch/stpcpy-power9.S b/sysdeps/powerpc/powerpc64/multiarch/stpcpy-power9.S
|
|
|
3b386f |
new file mode 100644
|
|
|
3b386f |
index 0000000000000000..a728d49fd2575e00
|
|
|
3b386f |
--- /dev/null
|
|
|
3b386f |
+++ b/sysdeps/powerpc/powerpc64/multiarch/stpcpy-power9.S
|
|
|
3b386f |
@@ -0,0 +1,24 @@
|
|
|
3b386f |
+/* Optimized stpcpy implementation for POWER9/PPC64.
|
|
|
3b386f |
+ Copyright (C) 2015-2020 Free Software Foundation, Inc.
|
|
|
3b386f |
+ This file is part of the GNU C Library.
|
|
|
3b386f |
+
|
|
|
3b386f |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
3b386f |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
3b386f |
+ License as published by the Free Software Foundation; either
|
|
|
3b386f |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
3b386f |
+
|
|
|
3b386f |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
3b386f |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
3b386f |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
3b386f |
+ Lesser General Public License for more details.
|
|
|
3b386f |
+
|
|
|
3b386f |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
3b386f |
+ License along with the GNU C Library; if not, see
|
|
|
3b386f |
+ <https://www.gnu.org/licenses/>. */
|
|
|
3b386f |
+
|
|
|
3b386f |
+#define STPCPY __stpcpy_power9
|
|
|
3b386f |
+
|
|
|
3b386f |
+#undef libc_hidden_builtin_def
|
|
|
3b386f |
+#define libc_hidden_builtin_def(name)
|
|
|
3b386f |
+
|
|
|
3b386f |
+#include <sysdeps/powerpc/powerpc64/le/power9/stpcpy.S>
|
|
|
3b386f |
diff --git a/sysdeps/powerpc/powerpc64/multiarch/stpcpy.c b/sysdeps/powerpc/powerpc64/multiarch/stpcpy.c
|
|
|
3b386f |
index 34c889644133d757..8ce58572e0f27c7f 100644
|
|
|
3b386f |
--- a/sysdeps/powerpc/powerpc64/multiarch/stpcpy.c
|
|
|
3b386f |
+++ b/sysdeps/powerpc/powerpc64/multiarch/stpcpy.c
|
|
|
3b386f |
@@ -26,13 +26,20 @@
|
|
|
3b386f |
extern __typeof (__stpcpy) __stpcpy_ppc attribute_hidden;
|
|
|
3b386f |
extern __typeof (__stpcpy) __stpcpy_power7 attribute_hidden;
|
|
|
3b386f |
extern __typeof (__stpcpy) __stpcpy_power8 attribute_hidden;
|
|
|
3b386f |
+# ifdef __LITTLE_ENDIAN__
|
|
|
3b386f |
+extern __typeof (__stpcpy) __stpcpy_power9 attribute_hidden;
|
|
|
3b386f |
+# endif
|
|
|
3b386f |
|
|
|
3b386f |
libc_ifunc_hidden (__stpcpy, __stpcpy,
|
|
|
3b386f |
- (hwcap2 & PPC_FEATURE2_ARCH_2_07)
|
|
|
3b386f |
- ? __stpcpy_power8
|
|
|
3b386f |
- : (hwcap & PPC_FEATURE_HAS_VSX)
|
|
|
3b386f |
- ? __stpcpy_power7
|
|
|
3b386f |
- : __stpcpy_ppc);
|
|
|
3b386f |
+# ifdef __LITTLE_ENDIAN__
|
|
|
3b386f |
+ (hwcap2 & PPC_FEATURE2_ARCH_3_00)
|
|
|
3b386f |
+ ? __stpcpy_power9 :
|
|
|
3b386f |
+# endif
|
|
|
3b386f |
+ (hwcap2 & PPC_FEATURE2_ARCH_2_07)
|
|
|
3b386f |
+ ? __stpcpy_power8
|
|
|
3b386f |
+ : (hwcap & PPC_FEATURE_HAS_VSX)
|
|
|
3b386f |
+ ? __stpcpy_power7
|
|
|
3b386f |
+ : __stpcpy_ppc);
|
|
|
3b386f |
|
|
|
3b386f |
weak_alias (__stpcpy, stpcpy)
|
|
|
3b386f |
libc_hidden_def (__stpcpy)
|