|
|
e354a5 |
commit a23bd00f9d810c28d9e83ce1d7cf53968375937d
|
|
|
e354a5 |
Author: Paul E. Murphy <murphyp@linux.vnet.ibm.com>
|
|
|
e354a5 |
Date: Mon May 18 11:16:06 2020 -0500
|
|
|
e354a5 |
|
|
|
e354a5 |
powerpc64le: add optimized strlen for P9
|
|
|
e354a5 |
|
|
|
e354a5 |
This started as a trivial change to Anton's rawmemchr. I got
|
|
|
e354a5 |
carried away. This is a hybrid between P8's asympotically
|
|
|
e354a5 |
faster 64B checks with extremely efficient small string checks
|
|
|
e354a5 |
e.g <64B (and sometimes a little bit more depending on alignment).
|
|
|
e354a5 |
|
|
|
e354a5 |
The second trick is to align to 64B by running a 48B checking loop
|
|
|
e354a5 |
16B at a time until we naturally align to 64B (i.e checking 48/96/144
|
|
|
e354a5 |
bytes/iteration based on the alignment after the first 5 comparisons).
|
|
|
e354a5 |
This allieviates the need to check page boundaries.
|
|
|
e354a5 |
|
|
|
e354a5 |
Finally, explicly use the P7 strlen with the runtime loader when building
|
|
|
e354a5 |
P9. We need to be cautious about vector/vsx extensions here on P9 only
|
|
|
e354a5 |
builds.
|
|
|
e354a5 |
|
|
|
e354a5 |
diff --git a/sysdeps/powerpc/powerpc64/le/power9/rtld-strlen.S b/sysdeps/powerpc/powerpc64/le/power9/rtld-strlen.S
|
|
|
e354a5 |
new file mode 100644
|
|
|
e354a5 |
index 0000000000000000..e9d83323acacfbca
|
|
|
e354a5 |
--- /dev/null
|
|
|
e354a5 |
+++ b/sysdeps/powerpc/powerpc64/le/power9/rtld-strlen.S
|
|
|
e354a5 |
@@ -0,0 +1 @@
|
|
|
e354a5 |
+#include <sysdeps/powerpc/powerpc64/power7/strlen.S>
|
|
|
e354a5 |
diff --git a/sysdeps/powerpc/powerpc64/le/power9/strlen.S b/sysdeps/powerpc/powerpc64/le/power9/strlen.S
|
|
|
e354a5 |
new file mode 100644
|
|
|
e354a5 |
index 0000000000000000..66a9b79647eebbd8
|
|
|
e354a5 |
--- /dev/null
|
|
|
e354a5 |
+++ b/sysdeps/powerpc/powerpc64/le/power9/strlen.S
|
|
|
e354a5 |
@@ -0,0 +1,213 @@
|
|
|
e354a5 |
+/* Optimized strlen implementation for PowerPC64/POWER9.
|
|
|
e354a5 |
+ Copyright (C) 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 |
+#include <sysdep.h>
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+#ifndef STRLEN
|
|
|
e354a5 |
+# define STRLEN __strlen
|
|
|
e354a5 |
+# define DEFINE_STRLEN_HIDDEN_DEF 1
|
|
|
e354a5 |
+#endif
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+/* Implements the function
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ int [r3] strlen (const void *s [r3])
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ The implementation can load bytes past a matching byte, but only
|
|
|
e354a5 |
+ up to the next 64B boundary, so it never crosses a page. */
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+.machine power9
|
|
|
e354a5 |
+ENTRY_TOCLESS (STRLEN, 4)
|
|
|
e354a5 |
+ CALL_MCOUNT 2
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ vspltisb v18,0
|
|
|
e354a5 |
+ vspltisb v19,-1
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ neg r5,r3
|
|
|
e354a5 |
+ rldicl r9,r5,0,60 /* How many bytes to get source 16B aligned? */
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Align data and fill bytes not loaded with non matching char. */
|
|
|
e354a5 |
+ lvx v0,0,r3
|
|
|
e354a5 |
+ lvsr v1,0,r3
|
|
|
e354a5 |
+ vperm v0,v19,v0,v1
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ vcmpequb. v6,v0,v18
|
|
|
e354a5 |
+ beq cr6,L(aligned)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ vctzlsbb r3,v6
|
|
|
e354a5 |
+ blr
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Test 64B 16B at a time. The 64B vector loop is optimized for
|
|
|
e354a5 |
+ longer strings. Likewise, we check a multiple of 64B to avoid
|
|
|
e354a5 |
+ breaking the alignment calculation below. */
|
|
|
e354a5 |
+L(aligned):
|
|
|
e354a5 |
+ add r4,r3,r9
|
|
|
e354a5 |
+ rldicl. r5,r4,60,62 /* Determine the number of 48B loops needed for
|
|
|
e354a5 |
+ alignment to 64B. And test for zero. */
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ lxv v0+32,0(r4)
|
|
|
e354a5 |
+ vcmpequb. v6,v0,v18
|
|
|
e354a5 |
+ bne cr6,L(tail1)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ lxv v0+32,16(r4)
|
|
|
e354a5 |
+ vcmpequb. v6,v0,v18
|
|
|
e354a5 |
+ bne cr6,L(tail2)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ lxv v0+32,32(r4)
|
|
|
e354a5 |
+ vcmpequb. v6,v0,v18
|
|
|
e354a5 |
+ bne cr6,L(tail3)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ lxv v0+32,48(r4)
|
|
|
e354a5 |
+ vcmpequb. v6,v0,v18
|
|
|
e354a5 |
+ bne cr6,L(tail4)
|
|
|
e354a5 |
+ addi r4,r4,64
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Speculatively generate a fake 16B aligned address to generate the
|
|
|
e354a5 |
+ vector byte constant 0,1,..,15 using lvsl during reduction. */
|
|
|
e354a5 |
+ li r0,0
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Skip the alignment if already 64B aligned. */
|
|
|
e354a5 |
+ beq L(loop_64b)
|
|
|
e354a5 |
+ mtctr r5
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Test 48B per iteration until 64B aligned. */
|
|
|
e354a5 |
+ .p2align 5
|
|
|
e354a5 |
+L(loop):
|
|
|
e354a5 |
+ lxv v0+32,0(r4)
|
|
|
e354a5 |
+ vcmpequb. v6,v0,v18
|
|
|
e354a5 |
+ bne cr6,L(tail1)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ lxv v0+32,16(r4)
|
|
|
e354a5 |
+ vcmpequb. v6,v0,v18
|
|
|
e354a5 |
+ bne cr6,L(tail2)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ lxv v0+32,32(r4)
|
|
|
e354a5 |
+ vcmpequb. v6,v0,v18
|
|
|
e354a5 |
+ bne cr6,L(tail3)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ addi r4,r4,48
|
|
|
e354a5 |
+ bdnz L(loop)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ .p2align 5
|
|
|
e354a5 |
+L(loop_64b):
|
|
|
e354a5 |
+ lxv v1+32,0(r4) /* Load 4 quadwords. */
|
|
|
e354a5 |
+ lxv v2+32,16(r4)
|
|
|
e354a5 |
+ lxv v3+32,32(r4)
|
|
|
e354a5 |
+ lxv v4+32,48(r4)
|
|
|
e354a5 |
+ vminub v5,v1,v2 /* Compare and merge into one VR for speed. */
|
|
|
e354a5 |
+ vminub v6,v3,v4
|
|
|
e354a5 |
+ vminub v7,v5,v6
|
|
|
e354a5 |
+ vcmpequb. v7,v7,v18 /* Check for NULLs. */
|
|
|
e354a5 |
+ addi r4,r4,64 /* Adjust address for the next iteration. */
|
|
|
e354a5 |
+ bne cr6,L(vmx_zero)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ lxv v1+32,0(r4) /* Load 4 quadwords. */
|
|
|
e354a5 |
+ lxv v2+32,16(r4)
|
|
|
e354a5 |
+ lxv v3+32,32(r4)
|
|
|
e354a5 |
+ lxv v4+32,48(r4)
|
|
|
e354a5 |
+ vminub v5,v1,v2 /* Compare and merge into one VR for speed. */
|
|
|
e354a5 |
+ vminub v6,v3,v4
|
|
|
e354a5 |
+ vminub v7,v5,v6
|
|
|
e354a5 |
+ vcmpequb. v7,v7,v18 /* Check for NULLs. */
|
|
|
e354a5 |
+ addi r4,r4,64 /* Adjust address for the next iteration. */
|
|
|
e354a5 |
+ bne cr6,L(vmx_zero)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ lxv v1+32,0(r4) /* Load 4 quadwords. */
|
|
|
e354a5 |
+ lxv v2+32,16(r4)
|
|
|
e354a5 |
+ lxv v3+32,32(r4)
|
|
|
e354a5 |
+ lxv v4+32,48(r4)
|
|
|
e354a5 |
+ vminub v5,v1,v2 /* Compare and merge into one VR for speed. */
|
|
|
e354a5 |
+ vminub v6,v3,v4
|
|
|
e354a5 |
+ vminub v7,v5,v6
|
|
|
e354a5 |
+ vcmpequb. v7,v7,v18 /* Check for NULLs. */
|
|
|
e354a5 |
+ addi r4,r4,64 /* Adjust address for the next iteration. */
|
|
|
e354a5 |
+ beq cr6,L(loop_64b)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+L(vmx_zero):
|
|
|
e354a5 |
+ /* OK, we found a null byte. Let's look for it in the current 64-byte
|
|
|
e354a5 |
+ block and mark it in its corresponding VR. */
|
|
|
e354a5 |
+ vcmpequb v1,v1,v18
|
|
|
e354a5 |
+ vcmpequb v2,v2,v18
|
|
|
e354a5 |
+ vcmpequb v3,v3,v18
|
|
|
e354a5 |
+ vcmpequb v4,v4,v18
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* We will now 'compress' the result into a single doubleword, so it
|
|
|
e354a5 |
+ can be moved to a GPR for the final calculation. First, we
|
|
|
e354a5 |
+ generate an appropriate mask for vbpermq, so we can permute bits into
|
|
|
e354a5 |
+ the first halfword. */
|
|
|
e354a5 |
+ vspltisb v10,3
|
|
|
e354a5 |
+ lvsl v11,0,r0
|
|
|
e354a5 |
+ vslb v10,v11,v10
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Permute the first bit of each byte into bits 48-63. */
|
|
|
e354a5 |
+ vbpermq v1,v1,v10
|
|
|
e354a5 |
+ vbpermq v2,v2,v10
|
|
|
e354a5 |
+ vbpermq v3,v3,v10
|
|
|
e354a5 |
+ vbpermq v4,v4,v10
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Shift each component into its correct position for merging. */
|
|
|
e354a5 |
+ vsldoi v2,v2,v2,2
|
|
|
e354a5 |
+ vsldoi v3,v3,v3,4
|
|
|
e354a5 |
+ vsldoi v4,v4,v4,6
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Merge the results and move to a GPR. */
|
|
|
e354a5 |
+ vor v1,v2,v1
|
|
|
e354a5 |
+ vor v2,v3,v4
|
|
|
e354a5 |
+ vor v4,v1,v2
|
|
|
e354a5 |
+ mfvrd r10,v4
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ /* Adjust address to the begninning of the current 64-byte block. */
|
|
|
e354a5 |
+ addi r4,r4,-64
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+ cnttzd r0,r10 /* Count trailing zeros before the match. */
|
|
|
e354a5 |
+ subf r5,r3,r4
|
|
|
e354a5 |
+ add r3,r5,r0 /* Compute final length. */
|
|
|
e354a5 |
+ blr
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+L(tail1):
|
|
|
e354a5 |
+ vctzlsbb r0,v6
|
|
|
e354a5 |
+ add r4,r4,r0
|
|
|
e354a5 |
+ subf r3,r3,r4
|
|
|
e354a5 |
+ blr
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+L(tail2):
|
|
|
e354a5 |
+ vctzlsbb r0,v6
|
|
|
e354a5 |
+ add r4,r4,r0
|
|
|
e354a5 |
+ addi r4,r4,16
|
|
|
e354a5 |
+ subf r3,r3,r4
|
|
|
e354a5 |
+ blr
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+L(tail3):
|
|
|
e354a5 |
+ vctzlsbb r0,v6
|
|
|
e354a5 |
+ add r4,r4,r0
|
|
|
e354a5 |
+ addi r4,r4,32
|
|
|
e354a5 |
+ subf r3,r3,r4
|
|
|
e354a5 |
+ blr
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+L(tail4):
|
|
|
e354a5 |
+ vctzlsbb r0,v6
|
|
|
e354a5 |
+ add r4,r4,r0
|
|
|
e354a5 |
+ addi r4,r4,48
|
|
|
e354a5 |
+ subf r3,r3,r4
|
|
|
e354a5 |
+ blr
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+END (STRLEN)
|
|
|
e354a5 |
+
|
|
|
e354a5 |
+#ifdef DEFINE_STRLEN_HIDDEN_DEF
|
|
|
e354a5 |
+weak_alias (__strlen, strlen)
|
|
|
e354a5 |
+libc_hidden_builtin_def (strlen)
|
|
|
e354a5 |
+#endif
|
|
|
e354a5 |
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
|
|
|
e354a5 |
index 1a8ef5fb73c3b0db..6d5661d08257b7a0 100644
|
|
|
e354a5 |
--- a/sysdeps/powerpc/powerpc64/multiarch/Makefile
|
|
|
e354a5 |
+++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile
|
|
|
e354a5 |
@@ -33,7 +33,7 @@ sysdep_routines += memcpy-power8-cached memcpy-power7 memcpy-a2 memcpy-power6 \
|
|
|
e354a5 |
|
|
|
e354a5 |
ifneq (,$(filter %le,$(config-machine)))
|
|
|
e354a5 |
sysdep_routines += strcmp-power9 strncmp-power9 strcpy-power9 stpcpy-power9 \
|
|
|
e354a5 |
- rawmemchr-power9
|
|
|
e354a5 |
+ rawmemchr-power9 strlen-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 297935863e44c0e1..daa30d3907395680 100644
|
|
|
e354a5 |
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
|
|
|
e354a5 |
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
|
|
|
e354a5 |
@@ -111,6 +111,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
|
|
|
e354a5 |
|
|
|
e354a5 |
/* Support sysdeps/powerpc/powerpc64/multiarch/strlen.c. */
|
|
|
e354a5 |
IFUNC_IMPL (i, name, strlen,
|
|
|
e354a5 |
+#ifdef __LITTLE_ENDIAN__
|
|
|
e354a5 |
+ IFUNC_IMPL_ADD (array, i, strcpy, hwcap2 & PPC_FEATURE2_ARCH_3_00,
|
|
|
e354a5 |
+ __strlen_power9)
|
|
|
e354a5 |
+#endif
|
|
|
e354a5 |
IFUNC_IMPL_ADD (array, i, strlen, hwcap2 & PPC_FEATURE2_ARCH_2_07,
|
|
|
e354a5 |
__strlen_power8)
|
|
|
e354a5 |
IFUNC_IMPL_ADD (array, i, strlen, hwcap & PPC_FEATURE_HAS_VSX,
|
|
|
e354a5 |
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strlen-power9.S b/sysdeps/powerpc/powerpc64/multiarch/strlen-power9.S
|
|
|
e354a5 |
new file mode 100644
|
|
|
e354a5 |
index 0000000000000000..68c8d54b5f5876a2
|
|
|
e354a5 |
--- /dev/null
|
|
|
e354a5 |
+++ b/sysdeps/powerpc/powerpc64/multiarch/strlen-power9.S
|
|
|
e354a5 |
@@ -0,0 +1,2 @@
|
|
|
e354a5 |
+#define STRLEN __strlen_power9
|
|
|
e354a5 |
+#include <sysdeps/powerpc/powerpc64/le/power9/strlen.S>
|
|
|
e354a5 |
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strlen.c b/sysdeps/powerpc/powerpc64/multiarch/strlen.c
|
|
|
e354a5 |
index 74810dab9929d505..b7f0fbb13fb97783 100644
|
|
|
e354a5 |
--- a/sysdeps/powerpc/powerpc64/multiarch/strlen.c
|
|
|
e354a5 |
+++ b/sysdeps/powerpc/powerpc64/multiarch/strlen.c
|
|
|
e354a5 |
@@ -30,8 +30,13 @@ extern __typeof (__redirect_strlen) __libc_strlen;
|
|
|
e354a5 |
extern __typeof (__redirect_strlen) __strlen_ppc attribute_hidden;
|
|
|
e354a5 |
extern __typeof (__redirect_strlen) __strlen_power7 attribute_hidden;
|
|
|
e354a5 |
extern __typeof (__redirect_strlen) __strlen_power8 attribute_hidden;
|
|
|
e354a5 |
+extern __typeof (__redirect_strlen) __strlen_power9 attribute_hidden;
|
|
|
e354a5 |
|
|
|
e354a5 |
libc_ifunc (__libc_strlen,
|
|
|
e354a5 |
+# ifdef __LITTLE_ENDIAN__
|
|
|
e354a5 |
+ (hwcap2 & PPC_FEATURE2_ARCH_3_00)
|
|
|
e354a5 |
+ ? __strlen_power9 :
|
|
|
e354a5 |
+# endif
|
|
|
e354a5 |
(hwcap2 & PPC_FEATURE2_ARCH_2_07)
|
|
|
e354a5 |
? __strlen_power8 :
|
|
|
e354a5 |
(hwcap & PPC_FEATURE_HAS_VSX)
|