bca718
From 24020ef9258267c5d65ab37dbf118bf52e4995d2 Mon Sep 17 00:00:00 2001
bca718
From: Stefan Liebler <stli@linux.vnet.ibm.com>
bca718
Date: Thu, 8 Oct 2015 12:40:02 +0200
bca718
Subject: [PATCH 21/30] S390: Optimize strchrnul and wcschrnul.
bca718
bca718
upstream-commit-id: d23d4ef19f1f5463745f2af205acb8c4975fd680
bca718
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00098.html
bca718
bca718
This patch provides optimized versions of strchrnul and wcschrnul with the z13
bca718
vector instructions.
bca718
bca718
ChangeLog:
bca718
bca718
	* sysdeps/s390/multiarch/strchrnul-c.c: New File.
bca718
	* sysdeps/s390/multiarch/strchrnul-vx.S: Likewise.
bca718
	* sysdeps/s390/multiarch/strchrnul.c: Likewise.
bca718
	* sysdeps/s390/multiarch/wcschrnul-c.c: Likewise.
bca718
	* sysdeps/s390/multiarch/wcschrnul-vx.S: Likewise.
bca718
	* sysdeps/s390/multiarch/wcschrnul.c: Likewise.
bca718
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add strchrnul and
bca718
	wcschrnul functions.
bca718
	* sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
	(__libc_ifunc_impl_list): Add ifunc test for strchrnul, wcschrnul.
bca718
	* wcsmbs/wcschrnul.c: Use WCSCHRNUL if defined.
bca718
	* string/test-strchr.c: Add wcschrnul support.
bca718
	* wcsmbs/test-wcschrnul.c: New File.
bca718
	* wcsmbs/Makefile (strop-tests): Add wcschrnul.
bca718
	* benchtests/bench-strchr.c: Add wcschrnul support.
bca718
	* benchtests/bench-wcschrnul.c: New File.
bca718
	* benchtests/Makefile (wcsmbs-bench): Add wcschrnul.
bca718
---
bca718
 benchtests/Makefile                      |  2 +-
bca718
 benchtests/bench-strchr.c                | 22 ++++++--
bca718
 benchtests/bench-wcschrnul.c             | 20 +++++++
bca718
 string/test-strchr.c                     | 24 ++++++--
bca718
 sysdeps/s390/multiarch/Makefile          |  6 +-
bca718
 sysdeps/s390/multiarch/ifunc-impl-list.c |  3 +
bca718
 sysdeps/s390/multiarch/strchrnul-c.c     | 26 +++++++++
bca718
 sysdeps/s390/multiarch/strchrnul-vx.S    | 93 ++++++++++++++++++++++++++++++
bca718
 sysdeps/s390/multiarch/strchrnul.c       | 28 +++++++++
bca718
 sysdeps/s390/multiarch/wcschrnul-c.c     | 25 ++++++++
bca718
 sysdeps/s390/multiarch/wcschrnul-vx.S    | 97 ++++++++++++++++++++++++++++++++
bca718
 sysdeps/s390/multiarch/wcschrnul.c       | 28 +++++++++
bca718
 wcsmbs/Makefile                          |  2 +-
bca718
 wcsmbs/test-wcschrnul-ifunc.c            | 20 +++++++
bca718
 wcsmbs/test-wcschrnul.c                  | 20 +++++++
bca718
 wcsmbs/wcschrnul.c                       |  5 ++
bca718
 16 files changed, 405 insertions(+), 16 deletions(-)
bca718
 create mode 100644 benchtests/bench-wcschrnul.c
bca718
 create mode 100644 sysdeps/s390/multiarch/strchrnul-c.c
bca718
 create mode 100644 sysdeps/s390/multiarch/strchrnul-vx.S
bca718
 create mode 100644 sysdeps/s390/multiarch/strchrnul.c
bca718
 create mode 100644 sysdeps/s390/multiarch/wcschrnul-c.c
bca718
 create mode 100644 sysdeps/s390/multiarch/wcschrnul-vx.S
bca718
 create mode 100644 sysdeps/s390/multiarch/wcschrnul.c
bca718
 create mode 100644 wcsmbs/test-wcschrnul-ifunc.c
bca718
 create mode 100644 wcsmbs/test-wcschrnul.c
bca718
bca718
diff --git a/benchtests/Makefile b/benchtests/Makefile
bca718
index bcb0288..d34bb3d 100644
bca718
--- a/benchtests/Makefile
bca718
+++ b/benchtests/Makefile
bca718
@@ -39,7 +39,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
bca718
 		strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
bca718
 		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
bca718
 wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
bca718
-		wcsncmp wcsncmp wcschr
bca718
+		wcsncmp wcsncmp wcschr wcschrnul
bca718
 string-bench-all := $(string-bench) ${wcsmbs-bench}
bca718
 
bca718
 stdlib-bench := strtod
bca718
diff --git a/benchtests/bench-strchr.c b/benchtests/bench-strchr.c
bca718
index d432ba5..9b1aaf9 100644
bca718
--- a/benchtests/bench-strchr.c
bca718
+++ b/benchtests/bench-strchr.c
bca718
@@ -22,10 +22,14 @@
bca718
 #  define TEST_NAME "strchrnul"
bca718
 # else
bca718
 #  define TEST_NAME "strchr"
bca718
-# endif
bca718
+# endif /* !USE_FOR_STRCHRNUL */
bca718
 #else
bca718
-# define TEST_NAME "wcschr"
bca718
-#endif
bca718
+# ifdef USE_FOR_STRCHRNUL
bca718
+#  define TEST_NAME "wcschrnul"
bca718
+# else
bca718
+#  define TEST_NAME "wcschr"
bca718
+# endif /* !USE_FOR_STRCHRNUL */
bca718
+#endif /* WIDE */
bca718
 #include "bench-string.h"
bca718
 
bca718
 #ifndef WIDE
bca718
@@ -44,20 +48,26 @@
bca718
 # define UCHAR unsigned char
bca718
 #else
bca718
 # include <wchar.h>
bca718
-# define STRCHR wcschr
bca718
+# ifdef USE_FOR_STRCHRNUL
bca718
+#  define STRCHR wcschrnul
bca718
+#  define stupid_STRCHR stupid_WCSCHRNUL
bca718
+#  define simple_STRCHR simple_WCSCHRNUL
bca718
+# else
bca718
+#  define STRCHR wcschr
bca718
+# endif /* !USE_FOR_STRCHRNUL */
bca718
 # define STRLEN wcslen
bca718
 # define CHAR wchar_t
bca718
 # define BIG_CHAR WCHAR_MAX
bca718
 # define MIDDLE_CHAR 1121
bca718
 # define SMALL_CHAR 851
bca718
 # define UCHAR wchar_t
bca718
-#endif
bca718
+#endif /* WIDE */
bca718
 
bca718
 #ifdef USE_FOR_STRCHRNUL
bca718
 # define NULLRET(endptr) endptr
bca718
 #else
bca718
 # define NULLRET(endptr) NULL
bca718
-#endif
bca718
+#endif /* !USE_FOR_STRCHRNUL */
bca718
 
bca718
 
bca718
 typedef CHAR *(*proto_t) (const CHAR *, int);
bca718
diff --git a/benchtests/bench-wcschrnul.c b/benchtests/bench-wcschrnul.c
bca718
new file mode 100644
bca718
index 0000000..124b602
bca718
--- /dev/null
bca718
+++ b/benchtests/bench-wcschrnul.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Measure wcschrnul functions.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#define WIDE 1
bca718
+#include "bench-strchrnul.c"
bca718
diff --git a/string/test-strchr.c b/string/test-strchr.c
bca718
index b84e138..1cd14d7 100644
bca718
--- a/string/test-strchr.c
bca718
+++ b/string/test-strchr.c
bca718
@@ -26,8 +26,12 @@
bca718
 #  define TEST_NAME "strchr"
bca718
 # endif
bca718
 #else
bca718
-# define TEST_NAME "wcschr"
bca718
-#endif
bca718
+# ifdef USE_FOR_STRCHRNUL
bca718
+#  define TEST_NAME "wcschrnul"
bca718
+# else
bca718
+#  define TEST_NAME "wcschr"
bca718
+# endif /* !USE_FOR_STRCHRNUL */
bca718
+#endif /* WIDE */
bca718
 #include "test-string.h"
bca718
 
bca718
 #ifndef WIDE
bca718
@@ -44,15 +48,23 @@
bca718
 # define MIDDLE_CHAR 127
bca718
 # define SMALL_CHAR 23
bca718
 # define UCHAR unsigned char
bca718
+# define L(s) s
bca718
 #else
bca718
 # include <wchar.h>
bca718
-# define STRCHR wcschr
bca718
+# ifdef USE_FOR_STRCHRNUL
bca718
+#  define STRCHR wcschrnul
bca718
+#  define stupid_STRCHR stupid_WCSCHRNUL
bca718
+#  define simple_STRCHR simple_WCSCHRNUL
bca718
+# else
bca718
+#  define STRCHR wcschr
bca718
+# endif /* !USE_FOR_STRCHRNUL */
bca718
 # define STRLEN wcslen
bca718
 # define CHAR wchar_t
bca718
 # define BIG_CHAR WCHAR_MAX
bca718
 # define MIDDLE_CHAR 1121
bca718
 # define SMALL_CHAR 851
bca718
 # define UCHAR wchar_t
bca718
+# define L(s) L ## s
bca718
 #endif
bca718
 
bca718
 #ifdef USE_FOR_STRCHRNUL
bca718
@@ -219,9 +231,9 @@ do_random_tests (void)
bca718
 static void
bca718
 check1 (void)
bca718
 {
bca718
-  char s[] __attribute__((aligned(16))) = "\xff";
bca718
-  char c = '\xfe';
bca718
-  char *exp_result = stupid_STRCHR (s, c);
bca718
+  CHAR s[] __attribute__((aligned(16))) = L ("\xff");
bca718
+  CHAR c = L ('\xfe');
bca718
+  CHAR *exp_result = stupid_STRCHR (s, c);
bca718
 
bca718
   FOR_EACH_IMPL (impl, 0)
bca718
     check_result (impl, s, c, exp_result);
bca718
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bca718
index 1a3673b..b6b64c9 100644
bca718
--- a/sysdeps/s390/multiarch/Makefile
bca718
+++ b/sysdeps/s390/multiarch/Makefile
bca718
@@ -9,7 +9,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
bca718
 		   strncat strncat-vx strncat-c \
bca718
 		   strcmp strcmp-vx \
bca718
 		   strncmp strncmp-vx strncmp-c \
bca718
-		   strchr strchr-vx strchr-c
bca718
+		   strchr strchr-vx strchr-c \
bca718
+		   strchrnul strchrnul-vx strchrnul-c
bca718
 endif
bca718
 
bca718
 ifeq ($(subdir),wcsmbs)
bca718
@@ -23,5 +24,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
bca718
 		   wcsncat wcsncat-vx wcsncat-c \
bca718
 		   wcscmp wcscmp-vx wcscmp-c \
bca718
 		   wcsncmp wcsncmp-vx wcsncmp-c \
bca718
-		   wcschr wcschr-vx wcschr-c
bca718
+		   wcschr wcschr-vx wcschr-c \
bca718
+		   wcschrnul wcschrnul-vx wcschrnul-c
bca718
 endif
bca718
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
index b0782ff..ea474a8 100644
bca718
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
@@ -112,6 +112,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bca718
   IFUNC_VX_IMPL (strchr);
bca718
   IFUNC_VX_IMPL (wcschr);
bca718
 
bca718
+  IFUNC_VX_IMPL (strchrnul);
bca718
+  IFUNC_VX_IMPL (wcschrnul);
bca718
+
bca718
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
bca718
 
bca718
   return i;
bca718
diff --git a/sysdeps/s390/multiarch/strchrnul-c.c b/sysdeps/s390/multiarch/strchrnul-c.c
bca718
new file mode 100644
bca718
index 0000000..7615217
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/strchrnul-c.c
bca718
@@ -0,0 +1,26 @@
bca718
+/* Default strchrnul implementation for S/390.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# define STRCHRNUL  __strchrnul_c
bca718
+# define __strchrnul STRCHRNUL
bca718
+# undef weak_alias
bca718
+# define weak_alias(name, alias)
bca718
+
bca718
+# include <string/strchrnul.c>
bca718
+#endif
bca718
diff --git a/sysdeps/s390/multiarch/strchrnul-vx.S b/sysdeps/s390/multiarch/strchrnul-vx.S
bca718
new file mode 100644
bca718
index 0000000..2c5f167
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/strchrnul-vx.S
bca718
@@ -0,0 +1,93 @@
bca718
+/* Vector optimized 32/64 bit S/390 version of strchrnul.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+
bca718
+# include "sysdep.h"
bca718
+# include "asm-syntax.h"
bca718
+
bca718
+	.text
bca718
+
bca718
+/* char *strchrnul (const char *s, int c)
bca718
+   Returns pointer to first c or to \0 if c not found.
bca718
+
bca718
+   Register usage:
bca718
+   -r1=tmp
bca718
+   -r2=s and return pointer
bca718
+   -r3=c
bca718
+   -r4=tmp
bca718
+   -r5=current_len
bca718
+   -v16=part of s
bca718
+   -v18=vector with c replicated in every byte
bca718
+*/
bca718
+ENTRY(__strchrnul_vx)
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+
bca718
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
bca718
+	lcbb	%r1,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
bca718
+
bca718
+	lghi	%r5,0		/* current_len = 0.  */
bca718
+
bca718
+	vlvgb	%v18,%r3,0	/* Generate vector which elements are all c.
bca718
+				   If c > 255, c will be truncated.  */
bca718
+	vrepb	%v18,%v18,0
bca718
+
bca718
+	vfeezbs	%v16,%v16,%v18	/* Find element equal with zero search.  */
bca718
+	vlgvb	%r4,%v16,7	/* Load byte index of character or zero.  */
bca718
+	clrjl	%r4,%r1,.Lfound /* Return if c/zero is in loaded bytes.  */
bca718
+
bca718
+	/* Align s to 16 byte.  */
bca718
+	risbgn	%r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
bca718
+	lghi	%r5,16		/* current_len = 16.  */
bca718
+	slr	%r5,%r4		/* Compute bytes to 16bytes boundary.  */
bca718
+
bca718
+	/* Find c/zero in 16byte aligned loop */
bca718
+.Lloop:
bca718
+	vl	%v16,0(%r5,%r2) /* Load s */
bca718
+	vfeezbs	%v16,%v16,%v18	/* Find element equal with zero search.  */
bca718
+	jno	.Lfound		/* Found c/zero (cc=0|1|2).  */
bca718
+	vl	%v16,16(%r5,%r2)
bca718
+	vfeezbs	%v16,%v16,%v18
bca718
+	jno	.Lfound16
bca718
+	vl	%v16,32(%r5,%r2)
bca718
+	vfeezbs	%v16,%v16,%v18
bca718
+	jno	.Lfound32
bca718
+	vl	%v16,48(%r5,%r2)
bca718
+	vfeezbs	%v16,%v16,%v18
bca718
+	jno	.Lfound48
bca718
+
bca718
+	aghi	%r5,64
bca718
+	j	.Lloop		/* No character and no zero -> loop.  */
bca718
+
bca718
+	/* Found character or zero */
bca718
+.Lfound48:
bca718
+	aghi	%r5,16
bca718
+.Lfound32:
bca718
+	aghi	%r5,16
bca718
+.Lfound16:
bca718
+	aghi	%r5,16
bca718
+.Lfound:
bca718
+	vlgvb	%r1,%v16,7	/* Load byte index of character.  */
bca718
+	algr	%r5,%r1
bca718
+	la	%r2,0(%r5,%r2)	/* Return pointer to character.  */
bca718
+
bca718
+.Lend:
bca718
+	br	%r14
bca718
+END(__strchrnul_vx)
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/strchrnul.c b/sysdeps/s390/multiarch/strchrnul.c
bca718
new file mode 100644
bca718
index 0000000..73fcf19
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/strchrnul.c
bca718
@@ -0,0 +1,28 @@
bca718
+/* Multiple versions of strchrnul.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# include <string.h>
bca718
+# include <ifunc-resolve.h>
bca718
+
bca718
+s390_vx_libc_ifunc (__strchrnul)
bca718
+weak_alias (__strchrnul, strchrnul)
bca718
+
bca718
+#else
bca718
+# include <string/strchrnul.c>
bca718
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
bca718
diff --git a/sysdeps/s390/multiarch/wcschrnul-c.c b/sysdeps/s390/multiarch/wcschrnul-c.c
bca718
new file mode 100644
bca718
index 0000000..31fa416
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcschrnul-c.c
bca718
@@ -0,0 +1,25 @@
bca718
+/* Default wcschrnul implementation for S/390.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# define WCSCHRNUL  __wcschrnul_c
bca718
+
bca718
+# include <wchar.h>
bca718
+extern __typeof (__wcschrnul) __wcschrnul_c;
bca718
+# include <wcsmbs/wcschrnul.c>
bca718
+#endif
bca718
diff --git a/sysdeps/s390/multiarch/wcschrnul-vx.S b/sysdeps/s390/multiarch/wcschrnul-vx.S
bca718
new file mode 100644
bca718
index 0000000..a89aee0
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcschrnul-vx.S
bca718
@@ -0,0 +1,97 @@
bca718
+/* Vector optimized 32/64 bit S/390 version of wcschrnul.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+
bca718
+# include "sysdep.h"
bca718
+# include "asm-syntax.h"
bca718
+
bca718
+	.text
bca718
+
bca718
+/* wchar_t* wcschrnul (const wchar_t *s, wchar_t c)
bca718
+   Returns pointer to first c or to \0 if c not found.
bca718
+
bca718
+   Register usage:
bca718
+   -r1=tmp
bca718
+   -r2=s and return pointer
bca718
+   -r3=c
bca718
+   -r4=tmp
bca718
+   -r5=current_len
bca718
+   -v16=part of s
bca718
+   -v18=vector with c replicated in every byte
bca718
+*/
bca718
+ENTRY(__wcschrnul_vx)
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+
bca718
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
bca718
+	lcbb	%r1,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
bca718
+
bca718
+	tmll	%r2,3		/* Test if s is 4-byte aligned?   */
bca718
+	jne	.Lfallback	/* And use common-code variant if not.  */
bca718
+
bca718
+	lghi	%r5,0		/* current_len = 0.  */
bca718
+
bca718
+	vlvgf	%v18,%r3,0	/* Generate vector which elements are all c.  */
bca718
+	vrepf	%v18,%v18,0
bca718
+
bca718
+	vfeezfs	%v16,%v16,%v18	/* Find element equal with zero search.  */
bca718
+	vlgvb	%r4,%v16,7	/* Load byte index of character or zero.  */
bca718
+	clrjl	%r4,%r1,.Lfound /* Return if c/zero is in loaded bytes.  */
bca718
+
bca718
+	/* Align s to 16 byte.  */
bca718
+	risbgn	%r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
bca718
+	lghi	%r5,16		/* current_len = 16.  */
bca718
+	slr	%r5,%r4		/* Compute bytes to 16bytes boundary.  */
bca718
+
bca718
+	/* Find c/zero in 16byte aligned loop */
bca718
+.Lloop:
bca718
+	vl	%v16,0(%r5,%r2) /* Load s.  */
bca718
+	vfeezfs	%v16,%v16,%v18	/* Find element equal with zero search.  */
bca718
+	jno	.Lfound		/* Found c/zero (cc=0|1|2).  */
bca718
+	vl	%v16,16(%r5,%r2)
bca718
+	vfeezfs	%v16,%v16,%v18
bca718
+	jno	.Lfound16
bca718
+	vl	%v16,32(%r5,%r2)
bca718
+	vfeezfs	%v16,%v16,%v18
bca718
+	jno	.Lfound32
bca718
+	vl	%v16,48(%r5,%r2)
bca718
+	vfeezfs	%v16,%v16,%v18
bca718
+	jno	.Lfound48
bca718
+
bca718
+	aghi	%r5,64
bca718
+	j	.Lloop		/* No character and no zero -> loop.  */
bca718
+
bca718
+	/* Found character or zero */
bca718
+.Lfound48:
bca718
+	aghi	%r5,16
bca718
+.Lfound32:
bca718
+	aghi	%r5,16
bca718
+.Lfound16:
bca718
+	aghi	%r5,16
bca718
+.Lfound:
bca718
+	vlgvb	%r1,%v16,7	/* Load byte index of character.  */
bca718
+	algr	%r5,%r1
bca718
+	la	%r2,0(%r5,%r2)	/* Return pointer to character.  */
bca718
+
bca718
+.Lend:
bca718
+	br	%r14
bca718
+.Lfallback:
bca718
+	jg	__wcschrnul_c
bca718
+END(__wcschrnul_vx)
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/wcschrnul.c b/sysdeps/s390/multiarch/wcschrnul.c
bca718
new file mode 100644
bca718
index 0000000..644258b
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcschrnul.c
bca718
@@ -0,0 +1,28 @@
bca718
+/* Multiple versions of wcschrnul.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# include <wchar.h>
bca718
+# include <ifunc-resolve.h>
bca718
+
bca718
+s390_vx_libc_ifunc (__wcschrnul)
bca718
+weak_alias (__wcschrnul, wcschrnul)
bca718
+
bca718
+#else
bca718
+# include <wcsmbs/wcschrnul.c>
bca718
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
bca718
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
bca718
index 611b2c9..de3635d 100644
bca718
--- a/wcsmbs/Makefile
bca718
+++ b/wcsmbs/Makefile
bca718
@@ -42,7 +42,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
bca718
 	    mbrtoc16 c16rtomb
bca718
 
bca718
 strop-tests :=  wcscmp wcsncmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
bca718
-		wcpcpy wcsncpy wcpncpy wcscat wcsncat
bca718
+		wcpcpy wcsncpy wcpncpy wcscat wcsncat wcschrnul
bca718
 tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
bca718
 	 tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \
bca718
 	 tst-c16c32-1 wcsatcliff $(addprefix test-,$(strop-tests))
bca718
diff --git a/wcsmbs/test-wcschrnul-ifunc.c b/wcsmbs/test-wcschrnul-ifunc.c
bca718
new file mode 100644
bca718
index 0000000..e64a1e4
bca718
--- /dev/null
bca718
+++ b/wcsmbs/test-wcschrnul-ifunc.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Test and measure IFUNC implementations of wcschrnul function.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#define TEST_IFUNC 1
bca718
+#include "test-wcschrnul.c"
bca718
diff --git a/wcsmbs/test-wcschrnul.c b/wcsmbs/test-wcschrnul.c
bca718
new file mode 100644
bca718
index 0000000..baea763
bca718
--- /dev/null
bca718
+++ b/wcsmbs/test-wcschrnul.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Test wcschrnul functions.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#define WIDE 1
bca718
+#include "../string/test-strchrnul.c"
bca718
diff --git a/wcsmbs/wcschrnul.c b/wcsmbs/wcschrnul.c
bca718
index 04db8f1..1e4c44f 100644
bca718
--- a/wcsmbs/wcschrnul.c
bca718
+++ b/wcsmbs/wcschrnul.c
bca718
@@ -17,6 +17,9 @@
bca718
 
bca718
 #include <wchar.h>
bca718
 
bca718
+#ifdef WCSCHRNUL
bca718
+# define __wcschrnul WCSCHRNUL
bca718
+#endif
bca718
 
bca718
 /* Find the first occurrence of WC in WCS.  */
bca718
 wchar_t *
bca718
@@ -32,4 +35,6 @@ __wcschrnul (wcs, wc)
bca718
 
bca718
   return (wchar_t *) wcs;
bca718
 }
bca718
+#ifndef WCSCHRNUL
bca718
 weak_alias (__wcschrnul, wcschrnul)
bca718
+#endif
bca718
-- 
bca718
2.3.0
bca718