ce426f
From 24020ef9258267c5d65ab37dbf118bf52e4995d2 Mon Sep 17 00:00:00 2001
ce426f
From: Stefan Liebler <stli@linux.vnet.ibm.com>
ce426f
Date: Thu, 8 Oct 2015 12:40:02 +0200
ce426f
Subject: [PATCH 21/30] S390: Optimize strchrnul and wcschrnul.
ce426f
ce426f
upstream-commit-id: d23d4ef19f1f5463745f2af205acb8c4975fd680
ce426f
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00098.html
ce426f
ce426f
This patch provides optimized versions of strchrnul and wcschrnul with the z13
ce426f
vector instructions.
ce426f
ce426f
ChangeLog:
ce426f
ce426f
	* sysdeps/s390/multiarch/strchrnul-c.c: New File.
ce426f
	* sysdeps/s390/multiarch/strchrnul-vx.S: Likewise.
ce426f
	* sysdeps/s390/multiarch/strchrnul.c: Likewise.
ce426f
	* sysdeps/s390/multiarch/wcschrnul-c.c: Likewise.
ce426f
	* sysdeps/s390/multiarch/wcschrnul-vx.S: Likewise.
ce426f
	* sysdeps/s390/multiarch/wcschrnul.c: Likewise.
ce426f
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add strchrnul and
ce426f
	wcschrnul functions.
ce426f
	* sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
	(__libc_ifunc_impl_list): Add ifunc test for strchrnul, wcschrnul.
ce426f
	* wcsmbs/wcschrnul.c: Use WCSCHRNUL if defined.
ce426f
	* string/test-strchr.c: Add wcschrnul support.
ce426f
	* wcsmbs/test-wcschrnul.c: New File.
ce426f
	* wcsmbs/Makefile (strop-tests): Add wcschrnul.
ce426f
	* benchtests/bench-strchr.c: Add wcschrnul support.
ce426f
	* benchtests/bench-wcschrnul.c: New File.
ce426f
	* benchtests/Makefile (wcsmbs-bench): Add wcschrnul.
ce426f
---
ce426f
 benchtests/Makefile                      |  2 +-
ce426f
 benchtests/bench-strchr.c                | 22 ++++++--
ce426f
 benchtests/bench-wcschrnul.c             | 20 +++++++
ce426f
 string/test-strchr.c                     | 24 ++++++--
ce426f
 sysdeps/s390/multiarch/Makefile          |  6 +-
ce426f
 sysdeps/s390/multiarch/ifunc-impl-list.c |  3 +
ce426f
 sysdeps/s390/multiarch/strchrnul-c.c     | 26 +++++++++
ce426f
 sysdeps/s390/multiarch/strchrnul-vx.S    | 93 ++++++++++++++++++++++++++++++
ce426f
 sysdeps/s390/multiarch/strchrnul.c       | 28 +++++++++
ce426f
 sysdeps/s390/multiarch/wcschrnul-c.c     | 25 ++++++++
ce426f
 sysdeps/s390/multiarch/wcschrnul-vx.S    | 97 ++++++++++++++++++++++++++++++++
ce426f
 sysdeps/s390/multiarch/wcschrnul.c       | 28 +++++++++
ce426f
 wcsmbs/Makefile                          |  2 +-
ce426f
 wcsmbs/test-wcschrnul-ifunc.c            | 20 +++++++
ce426f
 wcsmbs/test-wcschrnul.c                  | 20 +++++++
ce426f
 wcsmbs/wcschrnul.c                       |  5 ++
ce426f
 16 files changed, 405 insertions(+), 16 deletions(-)
ce426f
 create mode 100644 benchtests/bench-wcschrnul.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/strchrnul-c.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/strchrnul-vx.S
ce426f
 create mode 100644 sysdeps/s390/multiarch/strchrnul.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/wcschrnul-c.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/wcschrnul-vx.S
ce426f
 create mode 100644 sysdeps/s390/multiarch/wcschrnul.c
ce426f
 create mode 100644 wcsmbs/test-wcschrnul-ifunc.c
ce426f
 create mode 100644 wcsmbs/test-wcschrnul.c
ce426f
ce426f
diff --git a/benchtests/Makefile b/benchtests/Makefile
ce426f
index bcb0288..d34bb3d 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
ce426f
+		wcsncmp wcsncmp wcschr wcschrnul
ce426f
 string-bench-all := $(string-bench) ${wcsmbs-bench}
ce426f
 
ce426f
 stdlib-bench := strtod
ce426f
diff --git a/benchtests/bench-strchr.c b/benchtests/bench-strchr.c
ce426f
index d432ba5..9b1aaf9 100644
ce426f
--- a/benchtests/bench-strchr.c
ce426f
+++ b/benchtests/bench-strchr.c
ce426f
@@ -22,10 +22,14 @@
ce426f
 #  define TEST_NAME "strchrnul"
ce426f
 # else
ce426f
 #  define TEST_NAME "strchr"
ce426f
-# endif
ce426f
+# endif /* !USE_FOR_STRCHRNUL */
ce426f
 #else
ce426f
-# define TEST_NAME "wcschr"
ce426f
-#endif
ce426f
+# ifdef USE_FOR_STRCHRNUL
ce426f
+#  define TEST_NAME "wcschrnul"
ce426f
+# else
ce426f
+#  define TEST_NAME "wcschr"
ce426f
+# endif /* !USE_FOR_STRCHRNUL */
ce426f
+#endif /* WIDE */
ce426f
 #include "bench-string.h"
ce426f
 
ce426f
 #ifndef WIDE
ce426f
@@ -44,20 +48,26 @@
ce426f
 # define UCHAR unsigned char
ce426f
 #else
ce426f
 # include <wchar.h>
ce426f
-# define STRCHR wcschr
ce426f
+# ifdef USE_FOR_STRCHRNUL
ce426f
+#  define STRCHR wcschrnul
ce426f
+#  define stupid_STRCHR stupid_WCSCHRNUL
ce426f
+#  define simple_STRCHR simple_WCSCHRNUL
ce426f
+# else
ce426f
+#  define STRCHR wcschr
ce426f
+# endif /* !USE_FOR_STRCHRNUL */
ce426f
 # define STRLEN wcslen
ce426f
 # define CHAR wchar_t
ce426f
 # define BIG_CHAR WCHAR_MAX
ce426f
 # define MIDDLE_CHAR 1121
ce426f
 # define SMALL_CHAR 851
ce426f
 # define UCHAR wchar_t
ce426f
-#endif
ce426f
+#endif /* WIDE */
ce426f
 
ce426f
 #ifdef USE_FOR_STRCHRNUL
ce426f
 # define NULLRET(endptr) endptr
ce426f
 #else
ce426f
 # define NULLRET(endptr) NULL
ce426f
-#endif
ce426f
+#endif /* !USE_FOR_STRCHRNUL */
ce426f
 
ce426f
 
ce426f
 typedef CHAR *(*proto_t) (const CHAR *, int);
ce426f
diff --git a/benchtests/bench-wcschrnul.c b/benchtests/bench-wcschrnul.c
ce426f
new file mode 100644
ce426f
index 0000000..124b602
ce426f
--- /dev/null
ce426f
+++ b/benchtests/bench-wcschrnul.c
ce426f
@@ -0,0 +1,20 @@
ce426f
+/* Measure wcschrnul 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-strchrnul.c"
ce426f
diff --git a/string/test-strchr.c b/string/test-strchr.c
ce426f
index b84e138..1cd14d7 100644
ce426f
--- a/string/test-strchr.c
ce426f
+++ b/string/test-strchr.c
ce426f
@@ -26,8 +26,12 @@
ce426f
 #  define TEST_NAME "strchr"
ce426f
 # endif
ce426f
 #else
ce426f
-# define TEST_NAME "wcschr"
ce426f
-#endif
ce426f
+# ifdef USE_FOR_STRCHRNUL
ce426f
+#  define TEST_NAME "wcschrnul"
ce426f
+# else
ce426f
+#  define TEST_NAME "wcschr"
ce426f
+# endif /* !USE_FOR_STRCHRNUL */
ce426f
+#endif /* WIDE */
ce426f
 #include "test-string.h"
ce426f
 
ce426f
 #ifndef WIDE
ce426f
@@ -44,15 +48,23 @@
ce426f
 # define MIDDLE_CHAR 127
ce426f
 # define SMALL_CHAR 23
ce426f
 # define UCHAR unsigned char
ce426f
+# define L(s) s
ce426f
 #else
ce426f
 # include <wchar.h>
ce426f
-# define STRCHR wcschr
ce426f
+# ifdef USE_FOR_STRCHRNUL
ce426f
+#  define STRCHR wcschrnul
ce426f
+#  define stupid_STRCHR stupid_WCSCHRNUL
ce426f
+#  define simple_STRCHR simple_WCSCHRNUL
ce426f
+# else
ce426f
+#  define STRCHR wcschr
ce426f
+# endif /* !USE_FOR_STRCHRNUL */
ce426f
 # define STRLEN wcslen
ce426f
 # define CHAR wchar_t
ce426f
 # define BIG_CHAR WCHAR_MAX
ce426f
 # define MIDDLE_CHAR 1121
ce426f
 # define SMALL_CHAR 851
ce426f
 # define UCHAR wchar_t
ce426f
+# define L(s) L ## s
ce426f
 #endif
ce426f
 
ce426f
 #ifdef USE_FOR_STRCHRNUL
ce426f
@@ -219,9 +231,9 @@ do_random_tests (void)
ce426f
 static void
ce426f
 check1 (void)
ce426f
 {
ce426f
-  char s[] __attribute__((aligned(16))) = "\xff";
ce426f
-  char c = '\xfe';
ce426f
-  char *exp_result = stupid_STRCHR (s, c);
ce426f
+  CHAR s[] __attribute__((aligned(16))) = L ("\xff");
ce426f
+  CHAR c = L ('\xfe');
ce426f
+  CHAR *exp_result = stupid_STRCHR (s, c);
ce426f
 
ce426f
   FOR_EACH_IMPL (impl, 0)
ce426f
     check_result (impl, s, c, exp_result);
ce426f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
ce426f
index 1a3673b..b6b64c9 100644
ce426f
--- a/sysdeps/s390/multiarch/Makefile
ce426f
+++ b/sysdeps/s390/multiarch/Makefile
ce426f
@@ -9,7 +9,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
ce426f
 		   strncat strncat-vx strncat-c \
ce426f
 		   strcmp strcmp-vx \
ce426f
 		   strncmp strncmp-vx strncmp-c \
ce426f
-		   strchr strchr-vx strchr-c
ce426f
+		   strchr strchr-vx strchr-c \
ce426f
+		   strchrnul strchrnul-vx strchrnul-c
ce426f
 endif
ce426f
 
ce426f
 ifeq ($(subdir),wcsmbs)
ce426f
@@ -23,5 +24,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
ce426f
 		   wcsncat wcsncat-vx wcsncat-c \
ce426f
 		   wcscmp wcscmp-vx wcscmp-c \
ce426f
 		   wcsncmp wcsncmp-vx wcsncmp-c \
ce426f
-		   wcschr wcschr-vx wcschr-c
ce426f
+		   wcschr wcschr-vx wcschr-c \
ce426f
+		   wcschrnul wcschrnul-vx wcschrnul-c
ce426f
 endif
ce426f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
index b0782ff..ea474a8 100644
ce426f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
@@ -112,6 +112,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
ce426f
   IFUNC_VX_IMPL (strchr);
ce426f
   IFUNC_VX_IMPL (wcschr);
ce426f
 
ce426f
+  IFUNC_VX_IMPL (strchrnul);
ce426f
+  IFUNC_VX_IMPL (wcschrnul);
ce426f
+
ce426f
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
ce426f
 
ce426f
   return i;
ce426f
diff --git a/sysdeps/s390/multiarch/strchrnul-c.c b/sysdeps/s390/multiarch/strchrnul-c.c
ce426f
new file mode 100644
ce426f
index 0000000..7615217
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/strchrnul-c.c
ce426f
@@ -0,0 +1,26 @@
ce426f
+/* Default strchrnul 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 STRCHRNUL  __strchrnul_c
ce426f
+# define __strchrnul STRCHRNUL
ce426f
+# undef weak_alias
ce426f
+# define weak_alias(name, alias)
ce426f
+
ce426f
+# include <string/strchrnul.c>
ce426f
+#endif
ce426f
diff --git a/sysdeps/s390/multiarch/strchrnul-vx.S b/sysdeps/s390/multiarch/strchrnul-vx.S
ce426f
new file mode 100644
ce426f
index 0000000..2c5f167
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/strchrnul-vx.S
ce426f
@@ -0,0 +1,93 @@
ce426f
+/* Vector optimized 32/64 bit S/390 version of strchrnul.
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 *strchrnul (const char *s, int c)
ce426f
+   Returns pointer to first c or to \0 if c not found.
ce426f
+
ce426f
+   Register usage:
ce426f
+   -r1=tmp
ce426f
+   -r2=s and return pointer
ce426f
+   -r3=c
ce426f
+   -r4=tmp
ce426f
+   -r5=current_len
ce426f
+   -v16=part of s
ce426f
+   -v18=vector with c replicated in every byte
ce426f
+*/
ce426f
+ENTRY(__strchrnul_vx)
ce426f
+	.machine "z13"
ce426f
+	.machinemode "zarch_nohighgprs"
ce426f
+
ce426f
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
ce426f
+	lcbb	%r1,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
ce426f
+
ce426f
+	lghi	%r5,0		/* current_len = 0.  */
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
+	vfeezbs	%v16,%v16,%v18	/* Find element equal with zero search.  */
ce426f
+	vlgvb	%r4,%v16,7	/* Load byte index of character or zero.  */
ce426f
+	clrjl	%r4,%r1,.Lfound /* Return if c/zero is in loaded bytes.  */
ce426f
+
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
+	/* Find c/zero in 16byte aligned loop */
ce426f
+.Lloop:
ce426f
+	vl	%v16,0(%r5,%r2) /* Load s */
ce426f
+	vfeezbs	%v16,%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	%v16,%v16,%v18
ce426f
+	jno	.Lfound16
ce426f
+	vl	%v16,32(%r5,%r2)
ce426f
+	vfeezbs	%v16,%v16,%v18
ce426f
+	jno	.Lfound32
ce426f
+	vl	%v16,48(%r5,%r2)
ce426f
+	vfeezbs	%v16,%v16,%v18
ce426f
+	jno	.Lfound48
ce426f
+
ce426f
+	aghi	%r5,64
ce426f
+	j	.Lloop		/* No character and no zero -> loop.  */
ce426f
+
ce426f
+	/* Found character or zero */
ce426f
+.Lfound48:
ce426f
+	aghi	%r5,16
ce426f
+.Lfound32:
ce426f
+	aghi	%r5,16
ce426f
+.Lfound16:
ce426f
+	aghi	%r5,16
ce426f
+.Lfound:
ce426f
+	vlgvb	%r1,%v16,7	/* Load byte index of character.  */
ce426f
+	algr	%r5,%r1
ce426f
+	la	%r2,0(%r5,%r2)	/* Return pointer to character.  */
ce426f
+
ce426f
+.Lend:
ce426f
+	br	%r14
ce426f
+END(__strchrnul_vx)
ce426f
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
ce426f
diff --git a/sysdeps/s390/multiarch/strchrnul.c b/sysdeps/s390/multiarch/strchrnul.c
ce426f
new file mode 100644
ce426f
index 0000000..73fcf19
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/strchrnul.c
ce426f
@@ -0,0 +1,28 @@
ce426f
+/* Multiple versions of strchrnul.
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_ifunc (__strchrnul)
ce426f
+weak_alias (__strchrnul, strchrnul)
ce426f
+
ce426f
+#else
ce426f
+# include <string/strchrnul.c>
ce426f
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
ce426f
diff --git a/sysdeps/s390/multiarch/wcschrnul-c.c b/sysdeps/s390/multiarch/wcschrnul-c.c
ce426f
new file mode 100644
ce426f
index 0000000..31fa416
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/wcschrnul-c.c
ce426f
@@ -0,0 +1,25 @@
ce426f
+/* Default wcschrnul 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 WCSCHRNUL  __wcschrnul_c
ce426f
+
ce426f
+# include <wchar.h>
ce426f
+extern __typeof (__wcschrnul) __wcschrnul_c;
ce426f
+# include <wcsmbs/wcschrnul.c>
ce426f
+#endif
ce426f
diff --git a/sysdeps/s390/multiarch/wcschrnul-vx.S b/sysdeps/s390/multiarch/wcschrnul-vx.S
ce426f
new file mode 100644
ce426f
index 0000000..a89aee0
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/wcschrnul-vx.S
ce426f
@@ -0,0 +1,97 @@
ce426f
+/* Vector optimized 32/64 bit S/390 version of wcschrnul.
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* wcschrnul (const wchar_t *s, wchar_t c)
ce426f
+   Returns pointer to first c or to \0 if c not found.
ce426f
+
ce426f
+   Register usage:
ce426f
+   -r1=tmp
ce426f
+   -r2=s and return pointer
ce426f
+   -r3=c
ce426f
+   -r4=tmp
ce426f
+   -r5=current_len
ce426f
+   -v16=part of s
ce426f
+   -v18=vector with c replicated in every byte
ce426f
+*/
ce426f
+ENTRY(__wcschrnul_vx)
ce426f
+	.machine "z13"
ce426f
+	.machinemode "zarch_nohighgprs"
ce426f
+
ce426f
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
ce426f
+	lcbb	%r1,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
+	lghi	%r5,0		/* current_len = 0.  */
ce426f
+
ce426f
+	vlvgf	%v18,%r3,0	/* Generate vector which elements are all c.  */
ce426f
+	vrepf	%v18,%v18,0
ce426f
+
ce426f
+	vfeezfs	%v16,%v16,%v18	/* Find element equal with zero search.  */
ce426f
+	vlgvb	%r4,%v16,7	/* Load byte index of character or zero.  */
ce426f
+	clrjl	%r4,%r1,.Lfound /* Return if c/zero is in loaded bytes.  */
ce426f
+
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
+	/* Find c/zero in 16byte aligned loop */
ce426f
+.Lloop:
ce426f
+	vl	%v16,0(%r5,%r2) /* Load s.  */
ce426f
+	vfeezfs	%v16,%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	%v16,%v16,%v18
ce426f
+	jno	.Lfound16
ce426f
+	vl	%v16,32(%r5,%r2)
ce426f
+	vfeezfs	%v16,%v16,%v18
ce426f
+	jno	.Lfound32
ce426f
+	vl	%v16,48(%r5,%r2)
ce426f
+	vfeezfs	%v16,%v16,%v18
ce426f
+	jno	.Lfound48
ce426f
+
ce426f
+	aghi	%r5,64
ce426f
+	j	.Lloop		/* No character and no zero -> loop.  */
ce426f
+
ce426f
+	/* Found character or zero */
ce426f
+.Lfound48:
ce426f
+	aghi	%r5,16
ce426f
+.Lfound32:
ce426f
+	aghi	%r5,16
ce426f
+.Lfound16:
ce426f
+	aghi	%r5,16
ce426f
+.Lfound:
ce426f
+	vlgvb	%r1,%v16,7	/* Load byte index of character.  */
ce426f
+	algr	%r5,%r1
ce426f
+	la	%r2,0(%r5,%r2)	/* Return pointer to character.  */
ce426f
+
ce426f
+.Lend:
ce426f
+	br	%r14
ce426f
+.Lfallback:
ce426f
+	jg	__wcschrnul_c
ce426f
+END(__wcschrnul_vx)
ce426f
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
ce426f
diff --git a/sysdeps/s390/multiarch/wcschrnul.c b/sysdeps/s390/multiarch/wcschrnul.c
ce426f
new file mode 100644
ce426f
index 0000000..644258b
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/wcschrnul.c
ce426f
@@ -0,0 +1,28 @@
ce426f
+/* Multiple versions of wcschrnul.
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_ifunc (__wcschrnul)
ce426f
+weak_alias (__wcschrnul, wcschrnul)
ce426f
+
ce426f
+#else
ce426f
+# include <wcsmbs/wcschrnul.c>
ce426f
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
ce426f
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
ce426f
index 611b2c9..de3635d 100644
ce426f
--- a/wcsmbs/Makefile
ce426f
+++ b/wcsmbs/Makefile
ce426f
@@ -42,7 +42,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
ce426f
 	    mbrtoc16 c16rtomb
ce426f
 
ce426f
 strop-tests :=  wcscmp wcsncmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
ce426f
-		wcpcpy wcsncpy wcpncpy wcscat wcsncat
ce426f
+		wcpcpy wcsncpy wcpncpy wcscat wcsncat wcschrnul
ce426f
 tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
ce426f
 	 tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \
ce426f
 	 tst-c16c32-1 wcsatcliff $(addprefix test-,$(strop-tests))
ce426f
diff --git a/wcsmbs/test-wcschrnul-ifunc.c b/wcsmbs/test-wcschrnul-ifunc.c
ce426f
new file mode 100644
ce426f
index 0000000..e64a1e4
ce426f
--- /dev/null
ce426f
+++ b/wcsmbs/test-wcschrnul-ifunc.c
ce426f
@@ -0,0 +1,20 @@
ce426f
+/* Test and measure IFUNC implementations of wcschrnul function.
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 TEST_IFUNC 1
ce426f
+#include "test-wcschrnul.c"
ce426f
diff --git a/wcsmbs/test-wcschrnul.c b/wcsmbs/test-wcschrnul.c
ce426f
new file mode 100644
ce426f
index 0000000..baea763
ce426f
--- /dev/null
ce426f
+++ b/wcsmbs/test-wcschrnul.c
ce426f
@@ -0,0 +1,20 @@
ce426f
+/* Test wcschrnul 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 "../string/test-strchrnul.c"
ce426f
diff --git a/wcsmbs/wcschrnul.c b/wcsmbs/wcschrnul.c
ce426f
index 04db8f1..1e4c44f 100644
ce426f
--- a/wcsmbs/wcschrnul.c
ce426f
+++ b/wcsmbs/wcschrnul.c
ce426f
@@ -17,6 +17,9 @@
ce426f
 
ce426f
 #include <wchar.h>
ce426f
 
ce426f
+#ifdef WCSCHRNUL
ce426f
+# define __wcschrnul WCSCHRNUL
ce426f
+#endif
ce426f
 
ce426f
 /* Find the first occurrence of WC in WCS.  */
ce426f
 wchar_t *
ce426f
@@ -32,4 +35,6 @@ __wcschrnul (wcs, wc)
ce426f
 
ce426f
   return (wchar_t *) wcs;
ce426f
 }
ce426f
+#ifndef WCSCHRNUL
ce426f
 weak_alias (__wcschrnul, wcschrnul)
ce426f
+#endif
ce426f
-- 
ce426f
2.3.0
ce426f