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