|
|
147e83 |
From cb5e8d0ec1a4c4eb09da45015755e3d18b3a086b Mon Sep 17 00:00:00 2001
|
|
|
147e83 |
From: Stefan Liebler <stli@linux.vnet.ibm.com>
|
|
|
147e83 |
Date: Thu, 8 Oct 2015 12:43:56 +0200
|
|
|
147e83 |
Subject: [PATCH 22/30] S390: Optimize strrchr and wcsrchr.
|
|
|
147e83 |
|
|
|
147e83 |
upstream-commit-id: f40132d4bda984479bac89dfcd6968e9ff56e088
|
|
|
147e83 |
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00101.html
|
|
|
147e83 |
|
|
|
147e83 |
This patch provides optimized versions of strrchr and wcsrchr with the z13
|
|
|
147e83 |
vector instructions.
|
|
|
147e83 |
|
|
|
147e83 |
ChangeLog:
|
|
|
147e83 |
|
|
|
147e83 |
* sysdeps/s390/multiarch/strrchr-c.c: New File.
|
|
|
147e83 |
* sysdeps/s390/multiarch/strrchr-vx.S: Likewise.
|
|
|
147e83 |
* sysdeps/s390/multiarch/strrchr.c: Likewise.
|
|
|
147e83 |
* sysdeps/s390/multiarch/wcsrchr-c.c: Likewise.
|
|
|
147e83 |
* sysdeps/s390/multiarch/wcsrchr-vx.S: Likewise.
|
|
|
147e83 |
* sysdeps/s390/multiarch/wcsrchr.c: Likewise.
|
|
|
147e83 |
* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add strrchr and
|
|
|
147e83 |
wcsrchr functions.
|
|
|
147e83 |
* sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
147e83 |
(__libc_ifunc_impl_list): Add ifunc test for strrchr, wcsrchr.
|
|
|
147e83 |
* benchtests/bench-wcsrchr.c: New File.
|
|
|
147e83 |
* benchtests/Makefile (wcsmbs-bench): Add wcsrchr.
|
|
|
147e83 |
---
|
|
|
147e83 |
benchtests/Makefile | 2 +-
|
|
|
147e83 |
benchtests/bench-wcsrchr.c | 20 ++++
|
|
|
147e83 |
string/strrchr.c | 6 +-
|
|
|
147e83 |
sysdeps/s390/multiarch/Makefile | 6 +-
|
|
|
147e83 |
sysdeps/s390/multiarch/ifunc-impl-list.c | 3 +
|
|
|
147e83 |
sysdeps/s390/multiarch/strrchr-c.c | 29 +++++
|
|
|
147e83 |
sysdeps/s390/multiarch/strrchr-vx.S | 180 +++++++++++++++++++++++++++++
|
|
|
147e83 |
sysdeps/s390/multiarch/strrchr.c | 28 +++++
|
|
|
147e83 |
sysdeps/s390/multiarch/wcsrchr-c.c | 25 ++++
|
|
|
147e83 |
sysdeps/s390/multiarch/wcsrchr-vx.S | 190 +++++++++++++++++++++++++++++++
|
|
|
147e83 |
sysdeps/s390/multiarch/wcsrchr.c | 27 +++++
|
|
|
147e83 |
11 files changed, 512 insertions(+), 4 deletions(-)
|
|
|
147e83 |
create mode 100644 benchtests/bench-wcsrchr.c
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/strrchr-c.c
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/strrchr-vx.S
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/strrchr.c
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/wcsrchr-c.c
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/wcsrchr-vx.S
|
|
|
147e83 |
create mode 100644 sysdeps/s390/multiarch/wcsrchr.c
|
|
|
147e83 |
|
|
|
147e83 |
diff --git a/benchtests/Makefile b/benchtests/Makefile
|
|
|
147e83 |
index d34bb3d..6444394 100644
|
|
|
147e83 |
--- a/benchtests/Makefile
|
|
|
147e83 |
+++ b/benchtests/Makefile
|
|
|
147e83 |
@@ -39,7 +39,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
|
|
|
147e83 |
strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
|
|
|
147e83 |
strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
|
|
|
147e83 |
wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
|
|
|
147e83 |
- wcsncmp wcsncmp wcschr wcschrnul
|
|
|
147e83 |
+ wcsncmp wcsncmp wcschr wcschrnul wcsrchr
|
|
|
147e83 |
string-bench-all := $(string-bench) ${wcsmbs-bench}
|
|
|
147e83 |
|
|
|
147e83 |
stdlib-bench := strtod
|
|
|
147e83 |
diff --git a/benchtests/bench-wcsrchr.c b/benchtests/bench-wcsrchr.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..0d3923f
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/benchtests/bench-wcsrchr.c
|
|
|
147e83 |
@@ -0,0 +1,20 @@
|
|
|
147e83 |
+/* Measure wcsrchr functions.
|
|
|
147e83 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
147e83 |
+ This file is part of the GNU C Library.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
147e83 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
147e83 |
+ License as published by the Free Software Foundation; either
|
|
|
147e83 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
147e83 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
147e83 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
147e83 |
+ Lesser General Public License for more details.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
147e83 |
+ License along with the GNU C Library; if not, see
|
|
|
147e83 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+#define WIDE 1
|
|
|
147e83 |
+#include "bench-strrchr.c"
|
|
|
147e83 |
diff --git a/string/strrchr.c b/string/strrchr.c
|
|
|
147e83 |
index a986ff9..03f3957 100644
|
|
|
147e83 |
--- a/string/strrchr.c
|
|
|
147e83 |
+++ b/string/strrchr.c
|
|
|
147e83 |
@@ -19,9 +19,13 @@
|
|
|
147e83 |
|
|
|
147e83 |
#undef strrchr
|
|
|
147e83 |
|
|
|
147e83 |
+#ifndef STRRCHR
|
|
|
147e83 |
+# define STRRCHR strrchr
|
|
|
147e83 |
+#endif
|
|
|
147e83 |
+
|
|
|
147e83 |
/* Find the last occurrence of C in S. */
|
|
|
147e83 |
char *
|
|
|
147e83 |
-strrchr (const char *s, int c)
|
|
|
147e83 |
+STRRCHR (const char *s, int c)
|
|
|
147e83 |
{
|
|
|
147e83 |
register const char *found, *p;
|
|
|
147e83 |
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
|
|
|
147e83 |
index b6b64c9..b8b141e 100644
|
|
|
147e83 |
--- a/sysdeps/s390/multiarch/Makefile
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/Makefile
|
|
|
147e83 |
@@ -10,7 +10,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
|
|
|
147e83 |
strcmp strcmp-vx \
|
|
|
147e83 |
strncmp strncmp-vx strncmp-c \
|
|
|
147e83 |
strchr strchr-vx strchr-c \
|
|
|
147e83 |
- strchrnul strchrnul-vx strchrnul-c
|
|
|
147e83 |
+ strchrnul strchrnul-vx strchrnul-c \
|
|
|
147e83 |
+ strrchr strrchr-vx strrchr-c
|
|
|
147e83 |
endif
|
|
|
147e83 |
|
|
|
147e83 |
ifeq ($(subdir),wcsmbs)
|
|
|
147e83 |
@@ -25,5 +26,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
|
|
|
147e83 |
wcscmp wcscmp-vx wcscmp-c \
|
|
|
147e83 |
wcsncmp wcsncmp-vx wcsncmp-c \
|
|
|
147e83 |
wcschr wcschr-vx wcschr-c \
|
|
|
147e83 |
- wcschrnul wcschrnul-vx wcschrnul-c
|
|
|
147e83 |
+ wcschrnul wcschrnul-vx wcschrnul-c \
|
|
|
147e83 |
+ wcsrchr wcsrchr-vx wcsrchr-c
|
|
|
147e83 |
endif
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
147e83 |
index ea474a8..ee84d80 100644
|
|
|
147e83 |
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
|
|
|
147e83 |
@@ -115,6 +115,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
|
|
|
147e83 |
IFUNC_VX_IMPL (strchrnul);
|
|
|
147e83 |
IFUNC_VX_IMPL (wcschrnul);
|
|
|
147e83 |
|
|
|
147e83 |
+ IFUNC_VX_IMPL (strrchr);
|
|
|
147e83 |
+ IFUNC_VX_IMPL (wcsrchr);
|
|
|
147e83 |
+
|
|
|
147e83 |
#endif /* HAVE_S390_VX_ASM_SUPPORT */
|
|
|
147e83 |
|
|
|
147e83 |
return i;
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/strrchr-c.c b/sysdeps/s390/multiarch/strrchr-c.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..b035cdc
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/strrchr-c.c
|
|
|
147e83 |
@@ -0,0 +1,29 @@
|
|
|
147e83 |
+/* Default strrchr implementation for S/390.
|
|
|
147e83 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
147e83 |
+ This file is part of the GNU C Library.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
147e83 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
147e83 |
+ License as published by the Free Software Foundation; either
|
|
|
147e83 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
147e83 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
147e83 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
147e83 |
+ Lesser General Public License for more details.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
147e83 |
+ License along with the GNU C Library; if not, see
|
|
|
147e83 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
|
|
|
147e83 |
+# define STRRCHR __strrchr_c
|
|
|
147e83 |
+# undef weak_alias
|
|
|
147e83 |
+# ifdef SHARED
|
|
|
147e83 |
+# undef libc_hidden_builtin_def
|
|
|
147e83 |
+# define libc_hidden_builtin_def(name) \
|
|
|
147e83 |
+ __hidden_ver1 (__strrchr_c, __GI_strrchr, __strrchr_c);
|
|
|
147e83 |
+# endif /* SHARED */
|
|
|
147e83 |
+
|
|
|
147e83 |
+# include <string/strrchr.c>
|
|
|
147e83 |
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/strrchr-vx.S b/sysdeps/s390/multiarch/strrchr-vx.S
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..dbc183b
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/strrchr-vx.S
|
|
|
147e83 |
@@ -0,0 +1,180 @@
|
|
|
147e83 |
+/* Vector optimized 32/64 bit S/390 version of strrchr.
|
|
|
147e83 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
147e83 |
+ This file is part of the GNU C Library.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
147e83 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
147e83 |
+ License as published by the Free Software Foundation; either
|
|
|
147e83 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
147e83 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
147e83 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
147e83 |
+ Lesser General Public License for more details.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
147e83 |
+ License along with the GNU C Library; if not, see
|
|
|
147e83 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
|
|
|
147e83 |
+
|
|
|
147e83 |
+# include "sysdep.h"
|
|
|
147e83 |
+# include "asm-syntax.h"
|
|
|
147e83 |
+
|
|
|
147e83 |
+ .text
|
|
|
147e83 |
+
|
|
|
147e83 |
+/* char *strrchr (const char *s, int c)
|
|
|
147e83 |
+ Locate the last character c in string.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ Register usage:
|
|
|
147e83 |
+ -r0=loaded bytes in first part of s.
|
|
|
147e83 |
+ -r1=pointer to last occurence of c or NULL if not found.
|
|
|
147e83 |
+ -r2=s
|
|
|
147e83 |
+ -r3=c
|
|
|
147e83 |
+ -r4=tmp
|
|
|
147e83 |
+ -r5=current_len
|
|
|
147e83 |
+ -v16=part of s
|
|
|
147e83 |
+ -v17=index of found element
|
|
|
147e83 |
+ -v18=replicated c
|
|
|
147e83 |
+ -v19=part of s with last occurence of c.
|
|
|
147e83 |
+ -v20=permute pattern
|
|
|
147e83 |
+*/
|
|
|
147e83 |
+ENTRY(__strrchr_vx)
|
|
|
147e83 |
+ .machine "z13"
|
|
|
147e83 |
+ .machinemode "zarch_nohighgprs"
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
|
|
|
147e83 |
+ lcbb %r0,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vlvgb %v18,%r3,0 /* Generate vector which elements are all c.
|
|
|
147e83 |
+ if c > 255, c will be truncated. */
|
|
|
147e83 |
+ vrepb %v18,%v18,0
|
|
|
147e83 |
+
|
|
|
147e83 |
+ lghi %r1,-1 /* Currently no c found. */
|
|
|
147e83 |
+ lghi %r5,0 /* current_len = 0. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vfeezbs %v17,%v16,%v18 /* Find element equal or zero. */
|
|
|
147e83 |
+ vlgvb %r4,%v17,7 /* Load byte index of c/zero or 16. */
|
|
|
147e83 |
+ clrjl %r4,%r0,.Lfound_first_part /* Found c/zero in loaded bytes. */
|
|
|
147e83 |
+.Lalign:
|
|
|
147e83 |
+ /* Align s to 16 byte. */
|
|
|
147e83 |
+ risbgn %r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
|
|
|
147e83 |
+ lghi %r5,16 /* current_len = 16. */
|
|
|
147e83 |
+ slr %r5,%r4 /* Compute bytes to 16bytes boundary. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lloop:
|
|
|
147e83 |
+ vl %v16,0(%r5,%r2) /* Load s. */
|
|
|
147e83 |
+ vfeezbs %v17,%v16,%v18 /* Find element equal with zero search. */
|
|
|
147e83 |
+ jno .Lfound /* Found c/zero (cc=0|1|2). */
|
|
|
147e83 |
+ vl %v16,16(%r5,%r2)
|
|
|
147e83 |
+ vfeezbs %v17,%v16,%v18
|
|
|
147e83 |
+ jno .Lfound16
|
|
|
147e83 |
+ vl %v16,32(%r5,%r2)
|
|
|
147e83 |
+ vfeezbs %v17,%v16,%v18
|
|
|
147e83 |
+ jno .Lfound32
|
|
|
147e83 |
+ vl %v16,48(%r5,%r2)
|
|
|
147e83 |
+ vfeezbs %v17,%v16,%v18
|
|
|
147e83 |
+ jno .Lfound48
|
|
|
147e83 |
+
|
|
|
147e83 |
+ aghi %r5,64
|
|
|
147e83 |
+ j .Lloop /* No character and no zero -> loop. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lfound48:
|
|
|
147e83 |
+ la %r5,16(%r5) /* Use la since aghi would clobber cc. */
|
|
|
147e83 |
+.Lfound32:
|
|
|
147e83 |
+ la %r5,16(%r5)
|
|
|
147e83 |
+.Lfound16:
|
|
|
147e83 |
+ la %r5,16(%r5)
|
|
|
147e83 |
+.Lfound:
|
|
|
147e83 |
+ je .Lzero /* Found zero, but no c before that zero. */
|
|
|
147e83 |
+ /* Save this part of s to check for further matches after reaching
|
|
|
147e83 |
+ the end of the complete string. */
|
|
|
147e83 |
+ vlr %v19,%v16
|
|
|
147e83 |
+ lgr %r1,%r5
|
|
|
147e83 |
+
|
|
|
147e83 |
+ jh .Lzero /* Found a zero after the found c. */
|
|
|
147e83 |
+ aghi %r5,16 /* Start search of next part of s. */
|
|
|
147e83 |
+ j .Lloop
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lfound_first_part:
|
|
|
147e83 |
+ /* This code is only executed if the found c/zero is whithin loaded
|
|
|
147e83 |
+ bytes. If no c/zero was found (cc==3) the found index = 16, thus
|
|
|
147e83 |
+ this code is not called.
|
|
|
147e83 |
+ Resulting condition code of vector find element equal:
|
|
|
147e83 |
+ cc==0: no c, found zero
|
|
|
147e83 |
+ cc==1: c found, no zero
|
|
|
147e83 |
+ cc==2: c found, found zero after c
|
|
|
147e83 |
+ cc==3: no c, no zero (this case can be ignored). */
|
|
|
147e83 |
+ je .Lzero /* Found zero, but no c before that zero. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ locgrne %r1,%r5 /* Mark c as found in first part of s. */
|
|
|
147e83 |
+ vlr %v19,%v16
|
|
|
147e83 |
+
|
|
|
147e83 |
+ jl .Lalign /* No zero (e.g. if vr was fully loaded)
|
|
|
147e83 |
+ -> Align and loop afterwards. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Found a zero in vr. If vr was not fully loaded due to block
|
|
|
147e83 |
+ boundary, the remaining bytes are filled with zero and we can't
|
|
|
147e83 |
+ rely on zero indication of condition code here! */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vfenezb %v17,%v16,%v16 /* Find zero. */
|
|
|
147e83 |
+ vlgvb %r4,%v17,7 /* Load byte index of zero or 16. */
|
|
|
147e83 |
+ clrjl %r4,%r0,.Lzero /* Zero within loaded bytes -> end. */
|
|
|
147e83 |
+ j .Lalign /* Align and loop afterwards. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lend_searched_zero:
|
|
|
147e83 |
+ vlgvb %r4,%v17,7 /* Load byte index of zero. */
|
|
|
147e83 |
+ algr %r5,%r4
|
|
|
147e83 |
+ la %r2,0(%r5,%r2) /* Return pointer to zero. */
|
|
|
147e83 |
+ br %r14
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lzero:
|
|
|
147e83 |
+ /* Reached end of string. Check if one c was found before. */
|
|
|
147e83 |
+ clije %r3,0,.Lend_searched_zero /* Found zero and c is zero. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ cgfi %r1,-1 /* No c found -> return NULL. */
|
|
|
147e83 |
+ locghie %r2,0
|
|
|
147e83 |
+ ber %r14
|
|
|
147e83 |
+
|
|
|
147e83 |
+ larl %r3,.Lpermute_mask /* Load permute mask. */
|
|
|
147e83 |
+ vl %v20,0(%r3)
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* c was found and is part of v19. */
|
|
|
147e83 |
+ vfenezb %v17,%v19,%v19 /* Find zero. */
|
|
|
147e83 |
+ vlgvb %r4,%v17,7 /* Load byte index of zero or 16. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgfi %r5,0 /* Loaded byte count in v19 is 16, ... */
|
|
|
147e83 |
+ lochine %r0,16 /* ... if v19 is not the first part of s. */
|
|
|
147e83 |
+ ahi %r0,-1 /* Convert byte count to highest index. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clr %r0,%r4
|
|
|
147e83 |
+ locrl %r4,%r0 /* r4 = min (zero-index, highest-index). */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Right-shift of v19 to mask bytes after zero. */
|
|
|
147e83 |
+ clije %r4,15,.Lzero_permute /* No shift is needed if highest index
|
|
|
147e83 |
+ in vr is 15. */
|
|
|
147e83 |
+ lhi %r0,15
|
|
|
147e83 |
+ slr %r0,%r4 /* Compute byte count for vector shift right. */
|
|
|
147e83 |
+ sll %r0,3 /* Convert to bit count. */
|
|
|
147e83 |
+ vlvgb %v17,%r0,7
|
|
|
147e83 |
+ vsrlb %v19,%v19,%v17 /* Vector shift right by byte by number of bytes
|
|
|
147e83 |
+ specified in bits 1-4 of byte 7 in v17. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Reverse bytes in v19. */
|
|
|
147e83 |
+.Lzero_permute:
|
|
|
147e83 |
+ vperm %v19,%v19,%v19,%v20 /* Permute v19 to reversed order. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Find c in reversed v19. */
|
|
|
147e83 |
+ vfeeb %v19,%v19,%v18 /* Find c. */
|
|
|
147e83 |
+ la %r2,0(%r1,%r2)
|
|
|
147e83 |
+ vlgvb %r3,%v19,7 /* Load byte index of c. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Compute index in real s and return. */
|
|
|
147e83 |
+ slgr %r4,%r3
|
|
|
147e83 |
+ la %r2,0(%r4,%r2) /* Return pointer to zero. */
|
|
|
147e83 |
+ br %r14
|
|
|
147e83 |
+.Lpermute_mask:
|
|
|
147e83 |
+ .byte 0x0F,0x0E,0x0D,0x0C,0x0B,0x0A,0x09,0x08
|
|
|
147e83 |
+ .byte 0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00
|
|
|
147e83 |
+END(__strrchr_vx)
|
|
|
147e83 |
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/strrchr.c b/sysdeps/s390/multiarch/strrchr.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..dc4efd3
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/strrchr.c
|
|
|
147e83 |
@@ -0,0 +1,28 @@
|
|
|
147e83 |
+/* Multiple versions of strrchr.
|
|
|
147e83 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
147e83 |
+ This file is part of the GNU C Library.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
147e83 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
147e83 |
+ License as published by the Free Software Foundation; either
|
|
|
147e83 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
147e83 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
147e83 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
147e83 |
+ Lesser General Public License for more details.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
147e83 |
+ License along with the GNU C Library; if not, see
|
|
|
147e83 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
|
|
|
147e83 |
+# include <string.h>
|
|
|
147e83 |
+# include <ifunc-resolve.h>
|
|
|
147e83 |
+
|
|
|
147e83 |
+s390_vx_libc_ifunc2 (__strrchr, strrchr)
|
|
|
147e83 |
+weak_alias (strrchr, rindex)
|
|
|
147e83 |
+
|
|
|
147e83 |
+#else
|
|
|
147e83 |
+# include <string/strrchr.c>
|
|
|
147e83 |
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/wcsrchr-c.c b/sysdeps/s390/multiarch/wcsrchr-c.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..8f66600
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/wcsrchr-c.c
|
|
|
147e83 |
@@ -0,0 +1,25 @@
|
|
|
147e83 |
+/* Default wcsrchr implementation for S/390.
|
|
|
147e83 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
147e83 |
+ This file is part of the GNU C Library.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
147e83 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
147e83 |
+ License as published by the Free Software Foundation; either
|
|
|
147e83 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
147e83 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
147e83 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
147e83 |
+ Lesser General Public License for more details.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
147e83 |
+ License along with the GNU C Library; if not, see
|
|
|
147e83 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
|
|
|
147e83 |
+# define WCSRCHR __wcsrchr_c
|
|
|
147e83 |
+
|
|
|
147e83 |
+# include <wchar.h>
|
|
|
147e83 |
+extern __typeof (wcsrchr) __wcsrchr_c;
|
|
|
147e83 |
+# include <wcsmbs/wcsrchr.c>
|
|
|
147e83 |
+#endif
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/wcsrchr-vx.S b/sysdeps/s390/multiarch/wcsrchr-vx.S
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..efb7701
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/wcsrchr-vx.S
|
|
|
147e83 |
@@ -0,0 +1,190 @@
|
|
|
147e83 |
+/* Vector optimized 32/64 bit S/390 version of wcsrchr.
|
|
|
147e83 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
147e83 |
+ This file is part of the GNU C Library.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
147e83 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
147e83 |
+ License as published by the Free Software Foundation; either
|
|
|
147e83 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
147e83 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
147e83 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
147e83 |
+ Lesser General Public License for more details.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
147e83 |
+ License along with the GNU C Library; if not, see
|
|
|
147e83 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
|
|
|
147e83 |
+
|
|
|
147e83 |
+# include "sysdep.h"
|
|
|
147e83 |
+# include "asm-syntax.h"
|
|
|
147e83 |
+
|
|
|
147e83 |
+ .text
|
|
|
147e83 |
+
|
|
|
147e83 |
+/* wchar_t *wcsrchr (const wchar_t *s, wchar_t c)
|
|
|
147e83 |
+ Locate the last character c in string.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ Register usage:
|
|
|
147e83 |
+ -r0=loaded bytes in first part of s.
|
|
|
147e83 |
+ -r1=pointer to last occurence of c or NULL if not found.
|
|
|
147e83 |
+ -r2=s
|
|
|
147e83 |
+ -r3=c
|
|
|
147e83 |
+ -r4=tmp
|
|
|
147e83 |
+ -r5=current_len
|
|
|
147e83 |
+ -v16=part of s
|
|
|
147e83 |
+ -v17=index of found element
|
|
|
147e83 |
+ -v18=replicated c
|
|
|
147e83 |
+ -v19=part of s with last occurence of c.
|
|
|
147e83 |
+ -v20=permute pattern
|
|
|
147e83 |
+*/
|
|
|
147e83 |
+ENTRY(__wcsrchr_vx)
|
|
|
147e83 |
+ .machine "z13"
|
|
|
147e83 |
+ .machinemode "zarch_nohighgprs"
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
|
|
|
147e83 |
+ lcbb %r0,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ tmll %r2,3 /* Test if s is 4-byte aligned? */
|
|
|
147e83 |
+ jne .Lfallback /* And use common-code variant if not. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vlvgf %v18,%r3,0 /* Generate vector which elements are all c. */
|
|
|
147e83 |
+ vrepf %v18,%v18,0
|
|
|
147e83 |
+
|
|
|
147e83 |
+ lghi %r1,-1 /* Currently no c found. */
|
|
|
147e83 |
+ lghi %r5,0 /* current_len = 0. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vfeezfs %v17,%v16,%v18 /* Find element equal or zero. */
|
|
|
147e83 |
+ vlgvb %r4,%v17,7 /* Load byte index of c/zero or 16. */
|
|
|
147e83 |
+ clrjl %r4,%r0,.Lfound_first_part /* Found c/zero in loaded bytes. */
|
|
|
147e83 |
+.Lalign:
|
|
|
147e83 |
+ /* Align s to 16 byte. */
|
|
|
147e83 |
+ risbgn %r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
|
|
|
147e83 |
+ lghi %r5,16 /* current_len = 16. */
|
|
|
147e83 |
+ slr %r5,%r4 /* Compute bytes to 16bytes boundary. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lloop:
|
|
|
147e83 |
+ vl %v16,0(%r5,%r2) /* Load s. */
|
|
|
147e83 |
+ vfeezfs %v17,%v16,%v18 /* Find element equal with zero search. */
|
|
|
147e83 |
+ jno .Lfound /* Found c/zero (cc=0|1|2). */
|
|
|
147e83 |
+ vl %v16,16(%r5,%r2)
|
|
|
147e83 |
+ vfeezfs %v17,%v16,%v18
|
|
|
147e83 |
+ jno .Lfound16
|
|
|
147e83 |
+ vl %v16,32(%r5,%r2)
|
|
|
147e83 |
+ vfeezfs %v17,%v16,%v18
|
|
|
147e83 |
+ jno .Lfound32
|
|
|
147e83 |
+ vl %v16,48(%r5,%r2)
|
|
|
147e83 |
+ vfeezfs %v17,%v16,%v18
|
|
|
147e83 |
+ jno .Lfound48
|
|
|
147e83 |
+
|
|
|
147e83 |
+ aghi %r5,64
|
|
|
147e83 |
+ j .Lloop /* No character and no zero -> loop. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lfound48:
|
|
|
147e83 |
+ la %r5,16(%r5) /* Use la since aghi would clobber cc. */
|
|
|
147e83 |
+.Lfound32:
|
|
|
147e83 |
+ la %r5,16(%r5)
|
|
|
147e83 |
+.Lfound16:
|
|
|
147e83 |
+ la %r5,16(%r5)
|
|
|
147e83 |
+.Lfound:
|
|
|
147e83 |
+ je .Lzero /* Found zero, but no c before that zero. */
|
|
|
147e83 |
+ /* Save this part of s to check for further matches after reaching
|
|
|
147e83 |
+ the end of the complete string. */
|
|
|
147e83 |
+ vlr %v19,%v16
|
|
|
147e83 |
+ lgr %r1,%r5
|
|
|
147e83 |
+
|
|
|
147e83 |
+ jh .Lzero /* Found a zero after the found c. */
|
|
|
147e83 |
+ aghi %r5,16 /* Start search of next part of s. */
|
|
|
147e83 |
+ j .Lloop
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lfound_first_part:
|
|
|
147e83 |
+ /* This code is only executed if the found c/zero is whithin loaded
|
|
|
147e83 |
+ bytes. If no c/zero was found (cc==3) the found index = 16, thus
|
|
|
147e83 |
+ this code is not called.
|
|
|
147e83 |
+ Resulting condition code of vector find element equal:
|
|
|
147e83 |
+ cc==0: no c, found zero
|
|
|
147e83 |
+ cc==1: c found, no zero
|
|
|
147e83 |
+ cc==2: c found, found zero after c
|
|
|
147e83 |
+ cc==3: no c, no zero (this case can be ignored). */
|
|
|
147e83 |
+ je .Lzero /* Found zero, but no c before that zero. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ locgrne %r1,%r5 /* Mark c as found in first part of s. */
|
|
|
147e83 |
+ vlr %v19,%v16
|
|
|
147e83 |
+
|
|
|
147e83 |
+ jl .Lalign /* No zero (e.g. if vr was fully loaded)
|
|
|
147e83 |
+ -> Align and loop afterwards. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Found a zero in vr. If vr was not fully loaded due to block
|
|
|
147e83 |
+ boundary, the remaining bytes are filled with zero and we can't
|
|
|
147e83 |
+ rely on zero indication of condition code here! */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ vfenezf %v17,%v16,%v16
|
|
|
147e83 |
+ vlgvb %r4,%v17,7 /* Load byte index of zero or 16. */
|
|
|
147e83 |
+ clrjl %r4,%r0,.Lzero /* Zero within loaded bytes -> end. */
|
|
|
147e83 |
+ j .Lalign /* Align and loop afterwards. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lend_searched_zero:
|
|
|
147e83 |
+ vlgvb %r4,%v17,7 /* Load byte index of zero. */
|
|
|
147e83 |
+ algr %r5,%r4
|
|
|
147e83 |
+ la %r2,0(%r5,%r2) /* Return pointer to zero. */
|
|
|
147e83 |
+ br %r14
|
|
|
147e83 |
+
|
|
|
147e83 |
+.Lzero:
|
|
|
147e83 |
+ /* Reached end of string. Check if one c was found before. */
|
|
|
147e83 |
+ clije %r3,0,.Lend_searched_zero /* Found zero and c is zero. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ cgfi %r1,-1 /* No c found -> return NULL. */
|
|
|
147e83 |
+ locghie %r2,0
|
|
|
147e83 |
+ ber %r14
|
|
|
147e83 |
+
|
|
|
147e83 |
+ larl %r3,.Lpermute_mask /* Load permute mask. */
|
|
|
147e83 |
+ vl %v20,0(%r3)
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* c was found and is part of v19. */
|
|
|
147e83 |
+ vfenezf %v17,%v19,%v19 /* Find zero. */
|
|
|
147e83 |
+ vlgvb %r4,%v17,7 /* Load byte index of zero or 16. */
|
|
|
147e83 |
+ ahi %r4,3 /* Found zero index is first byte,
|
|
|
147e83 |
+ thus highest byte index is last byte of
|
|
|
147e83 |
+ wchar_t zero. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clgfi %r5,0 /* Loaded byte count in v19 is 16, ... */
|
|
|
147e83 |
+ lochine %r0,16 /* ... if v19 is not the first part of s. */
|
|
|
147e83 |
+ ahi %r0,-1 /* Convert byte count to highest index. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ clr %r0,%r4
|
|
|
147e83 |
+ locrl %r4,%r0 /* r4 = min (zero-index, highest-index). */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Right-shift of v19 to mask bytes after zero. */
|
|
|
147e83 |
+ clije %r4,15,.Lzero_permute /* No shift is needed if highest index
|
|
|
147e83 |
+ in vr is 15. */
|
|
|
147e83 |
+ lhi %r0,15
|
|
|
147e83 |
+ slr %r0,%r4 /* Compute byte count for vector shift left. */
|
|
|
147e83 |
+ sll %r0,3 /* Convert to bit count. */
|
|
|
147e83 |
+ vlvgb %v17,%r0,7
|
|
|
147e83 |
+ vsrlb %v19,%v19,%v17 /* Vector shift right by byte by number of bytes
|
|
|
147e83 |
+ specified in bits 1-4 of byte 7 in v17. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Reverse bytes in v19. */
|
|
|
147e83 |
+.Lzero_permute:
|
|
|
147e83 |
+ vperm %v19,%v19,%v19,%v20 /* Permute v19 to reversed order. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Find c in reversed v19. */
|
|
|
147e83 |
+ vfeef %v19,%v19,%v18 /* Find c. */
|
|
|
147e83 |
+ la %r2,0(%r1,%r2)
|
|
|
147e83 |
+ vlgvb %r3,%v19,7 /* Load byte index of c. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+ /* Compute index in real s and return. */
|
|
|
147e83 |
+ slgr %r4,%r3
|
|
|
147e83 |
+ lay %r2,-3(%r4,%r2) /* Return pointer to zero. -3 is needed,
|
|
|
147e83 |
+ because the found byte index is reversed in
|
|
|
147e83 |
+ vector-register. Thus point to first byte of
|
|
|
147e83 |
+ wchar_t. */
|
|
|
147e83 |
+ br %r14
|
|
|
147e83 |
+.Lpermute_mask:
|
|
|
147e83 |
+ .byte 0x0C,0x0D,0x0E,0x0F,0x08,0x09,0x0A,0x0B
|
|
|
147e83 |
+ .byte 0x04,0x05,0x06,0x07,0x00,0x01,0x02,0x03
|
|
|
147e83 |
+.Lfallback:
|
|
|
147e83 |
+ jg __wcsrchr_c
|
|
|
147e83 |
+END(__wcsrchr_vx)
|
|
|
147e83 |
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
|
|
|
147e83 |
diff --git a/sysdeps/s390/multiarch/wcsrchr.c b/sysdeps/s390/multiarch/wcsrchr.c
|
|
|
147e83 |
new file mode 100644
|
|
|
147e83 |
index 0000000..db3f467
|
|
|
147e83 |
--- /dev/null
|
|
|
147e83 |
+++ b/sysdeps/s390/multiarch/wcsrchr.c
|
|
|
147e83 |
@@ -0,0 +1,27 @@
|
|
|
147e83 |
+/* Multiple versions of wcsrchr.
|
|
|
147e83 |
+ Copyright (C) 2015 Free Software Foundation, Inc.
|
|
|
147e83 |
+ This file is part of the GNU C Library.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
147e83 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
147e83 |
+ License as published by the Free Software Foundation; either
|
|
|
147e83 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
147e83 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
147e83 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
147e83 |
+ Lesser General Public License for more details.
|
|
|
147e83 |
+
|
|
|
147e83 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
147e83 |
+ License along with the GNU C Library; if not, see
|
|
|
147e83 |
+ <http://www.gnu.org/licenses/>. */
|
|
|
147e83 |
+
|
|
|
147e83 |
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
|
|
|
147e83 |
+# include <wchar.h>
|
|
|
147e83 |
+# include <ifunc-resolve.h>
|
|
|
147e83 |
+
|
|
|
147e83 |
+s390_vx_libc_ifunc2 (__wcsrchr, wcsrchr)
|
|
|
147e83 |
+
|
|
|
147e83 |
+#else
|
|
|
147e83 |
+# include <wcsmbs/wcsrchr.c>
|
|
|
147e83 |
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
|
|
|
147e83 |
--
|
|
|
147e83 |
2.3.0
|
|
|
147e83 |
|