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