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