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