00db10
From 6bad9c03df10e4bca1840eff95ef9036e5261436 Mon Sep 17 00:00:00 2001
00db10
From: Stefan Liebler <stli@linux.vnet.ibm.com>
00db10
Date: Thu, 8 Oct 2015 13:20:09 +0200
00db10
Subject: [PATCH 26/30] S390: Optimize memchr, rawmemchr and wmemchr.
00db10
00db10
upstream-commit-id: 88eefd344b3cf4a41284a1dfdaca61667e3a1b4b
00db10
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00093.html
00db10
00db10
This patch provides optimized versions of memchr, rawmemchr and wmemchr with the
00db10
z13 vector instructions.
00db10
00db10
ChangeLog:
00db10
00db10
	* sysdeps/s390/multiarch/memchr-vx.S: New File.
00db10
	* sysdeps/s390/multiarch/memchr.c: Likewise.
00db10
	* sysdeps/s390/multiarch/rawmemchr-c.c: Likewise.
00db10
	* sysdeps/s390/multiarch/rawmemchr-vx.S: Likewise.
00db10
	* sysdeps/s390/multiarch/rawmemchr.c: Likewise.
00db10
	* sysdeps/s390/multiarch/wmemchr-c.c: Likewise.
00db10
	* sysdeps/s390/multiarch/wmemchr-vx.S: Likewise.
00db10
	* sysdeps/s390/multiarch/wmemchr.c: Likewise.
00db10
	* sysdeps/s390/s390-32/multiarch/memchr.c: Likewise.
00db10
	* sysdeps/s390/s390-64/multiarch/memchr.c: Likewise.
00db10
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add memchr, wmemchr
00db10
	and rawmemchr functions.
00db10
	* sysdeps/s390/multiarch/ifunc-impl-list-common.c
00db10
	(__libc_ifunc_impl_list_common): Add ifunc test for memchr, rawmemchr
00db10
	and wmemchr.
00db10
	* wcsmbs/wmemchr.c: Use WMEMCHR if defined.
00db10
	* string/test-memchr.c: Add wmemchr support.
00db10
	* wcsmbs/test-wmemchr.c: New File.
00db10
	* wcsmbs/Makefile (strop-tests): Add wmemchr.
00db10
	* benchtests/bench-memchr.c: Add wmemchr support.
00db10
	* benchtests/bench-wmemchr.c: New File.
00db10
	* benchtests/Makefile (wcsmbs-bench): wmemchr.
00db10
---
00db10
 benchtests/Makefile                      |   3 +-
00db10
 benchtests/bench-memchr.c                |  68 ++++++++-----
00db10
 benchtests/bench-wmemchr.c               |  20 ++++
00db10
 string/test-memchr.c                     |  89 +++++++++++------
00db10
 sysdeps/s390/multiarch/Makefile          |   7 +-
00db10
 sysdeps/s390/multiarch/ifunc-impl-list.c |   4 +
00db10
 sysdeps/s390/multiarch/memchr-vx.S       | 159 +++++++++++++++++++++++++++++
00db10
 sysdeps/s390/multiarch/memchr.c          |  24 +++++
00db10
 sysdeps/s390/multiarch/rawmemchr-c.c     |  34 +++++++
00db10
 sysdeps/s390/multiarch/rawmemchr-vx.S    |  92 +++++++++++++++++
00db10
 sysdeps/s390/multiarch/rawmemchr.c       |  28 ++++++
00db10
 sysdeps/s390/multiarch/wmemchr-c.c       |  31 ++++++
00db10
 sysdeps/s390/multiarch/wmemchr-vx.S      | 166 +++++++++++++++++++++++++++++++
00db10
 sysdeps/s390/multiarch/wmemchr.c         |  27 +++++
00db10
 sysdeps/s390/s390-32/multiarch/memchr.c  |  21 ++++
00db10
 sysdeps/s390/s390-64/multiarch/memchr.c  |  21 ++++
00db10
 wcsmbs/Makefile                          |   2 +-
00db10
 wcsmbs/test-wmemchr-ifunc.c              |  20 ++++
00db10
 wcsmbs/test-wmemchr.c                    |  20 ++++
00db10
 wcsmbs/wmemchr.c                         |   4 +
00db10
 20 files changed, 780 insertions(+), 60 deletions(-)
00db10
 create mode 100644 benchtests/bench-wmemchr.c
00db10
 create mode 100644 sysdeps/s390/multiarch/memchr-vx.S
00db10
 create mode 100644 sysdeps/s390/multiarch/memchr.c
00db10
 create mode 100644 sysdeps/s390/multiarch/rawmemchr-c.c
00db10
 create mode 100644 sysdeps/s390/multiarch/rawmemchr-vx.S
00db10
 create mode 100644 sysdeps/s390/multiarch/rawmemchr.c
00db10
 create mode 100644 sysdeps/s390/multiarch/wmemchr-c.c
00db10
 create mode 100644 sysdeps/s390/multiarch/wmemchr-vx.S
00db10
 create mode 100644 sysdeps/s390/multiarch/wmemchr.c
00db10
 create mode 100644 sysdeps/s390/s390-32/multiarch/memchr.c
00db10
 create mode 100644 sysdeps/s390/s390-64/multiarch/memchr.c
00db10
 create mode 100644 wcsmbs/test-wmemchr-ifunc.c
00db10
 create mode 100644 wcsmbs/test-wmemchr.c
00db10
00db10
diff --git a/benchtests/Makefile b/benchtests/Makefile
00db10
index 4e811a9..b4b3127 100644
00db10
--- a/benchtests/Makefile
00db10
+++ b/benchtests/Makefile
00db10
@@ -39,7 +39,8 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
00db10
 		strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
00db10
 		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
00db10
 wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
00db10
-		wcsncmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn
00db10
+		wcsncmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \
00db10
+		wmemchr
00db10
 string-bench-all := $(string-bench) ${wcsmbs-bench}
00db10
 
00db10
 stdlib-bench := strtod
00db10
diff --git a/benchtests/bench-memchr.c b/benchtests/bench-memchr.c
00db10
index 30c472c..84a90b4 100644
00db10
--- a/benchtests/bench-memchr.c
00db10
+++ b/benchtests/bench-memchr.c
00db10
@@ -16,31 +16,51 @@
00db10
    License along with the GNU C Library; if not, see
00db10
    <http://www.gnu.org/licenses/>.  */
00db10
 
00db10
+#ifndef WIDE
00db10
+# define CHAR char
00db10
+# define SMALL_CHAR 127
00db10
+#else
00db10
+# include <wchar.h>
00db10
+# define CHAR wchar_t
00db10
+# define SMALL_CHAR 1273
00db10
+#endif /* WIDE */
00db10
 #ifndef USE_AS_MEMRCHR
00db10
 # define TEST_MAIN
00db10
-# define TEST_NAME "memchr"
00db10
+# ifndef WIDE
00db10
+#  define TEST_NAME "memchr"
00db10
+# else
00db10
+#  define TEST_NAME "wmemchr"
00db10
+# endif /* WIDE */
00db10
 # include "bench-string.h"
00db10
 
00db10
-typedef char *(*proto_t) (const char *, int, size_t);
00db10
-char *simple_memchr (const char *, int, size_t);
00db10
+# ifndef WIDE
00db10
+#  define MEMCHR memchr
00db10
+#  define SIMPLE_MEMCHR simple_memchr
00db10
+# else
00db10
+#  define MEMCHR wmemchr
00db10
+#  define SIMPLE_MEMCHR simple_wmemchr
00db10
+# endif /* WIDE */
00db10
 
00db10
-IMPL (simple_memchr, 0)
00db10
-IMPL (memchr, 1)
00db10
+typedef CHAR *(*proto_t) (const CHAR *, int, size_t);
00db10
+CHAR *SIMPLE_MEMCHR (const CHAR *, int, size_t);
00db10
 
00db10
-char *
00db10
-simple_memchr (const char *s, int c, size_t n)
00db10
+IMPL (SIMPLE_MEMCHR, 0)
00db10
+IMPL (MEMCHR, 1)
00db10
+
00db10
+CHAR *
00db10
+SIMPLE_MEMCHR (const CHAR *s, int c, size_t n)
00db10
 {
00db10
   while (n--)
00db10
-    if (*s++ == (char) c)
00db10
-      return (char *) s - 1;
00db10
+    if (*s++ == (CHAR) c)
00db10
+      return (CHAR *) s - 1;
00db10
   return NULL;
00db10
 }
00db10
-#endif
00db10
+#endif /* !USE_AS_MEMRCHR */
00db10
 
00db10
 static void
00db10
-do_one_test (impl_t *impl, const char *s, int c, size_t n, char *exp_res)
00db10
+do_one_test (impl_t *impl, const CHAR *s, int c, size_t n, CHAR *exp_res)
00db10
 {
00db10
-  char *res = CALL (impl, s, c, n);
00db10
+  CHAR *res = CALL (impl, s, c, n);
00db10
   size_t i, iters = INNER_LOOP_ITERS;
00db10
   timing_t start, stop, cur;
00db10
 
00db10
@@ -68,36 +88,38 @@ static void
00db10
 do_test (size_t align, size_t pos, size_t len, int seek_char)
00db10
 {
00db10
   size_t i;
00db10
-  char *result;
00db10
+  CHAR *result;
00db10
 
00db10
   align &= 7;
00db10
-  if (align + len >= page_size)
00db10
+  if ((align + len) * sizeof (CHAR) >= page_size)
00db10
     return;
00db10
 
00db10
+  CHAR *buf = (CHAR *) (buf1);
00db10
+
00db10
   for (i = 0; i < len; ++i)
00db10
     {
00db10
-      buf1[align + i] = 1 + 23 * i % 127;
00db10
-      if (buf1[align + i] == seek_char)
00db10
-        buf1[align + i] = seek_char + 1;
00db10
+      buf[align + i] = 1 + 23 * i % SMALL_CHAR;
00db10
+      if (buf[align + i] == seek_char)
00db10
+        buf[align + i] = seek_char + 1;
00db10
     }
00db10
-  buf1[align + len] = 0;
00db10
+  buf[align + len] = 0;
00db10
 
00db10
   if (pos < len)
00db10
     {
00db10
-      buf1[align + pos] = seek_char;
00db10
-      buf1[align + len] = -seek_char;
00db10
-      result = (char *) (buf1 + align + pos);
00db10
+      buf[align + pos] = seek_char;
00db10
+      buf[align + len] = -seek_char;
00db10
+      result = (CHAR *) (buf1 + align + pos);
00db10
     }
00db10
   else
00db10
     {
00db10
       result = NULL;
00db10
-      buf1[align + len] = seek_char;
00db10
+      buf[align + len] = seek_char;
00db10
     }
00db10
 
00db10
   printf ("Length %4zd, alignment %2zd:", pos, align);
00db10
 
00db10
   FOR_EACH_IMPL (impl, 0)
00db10
-    do_one_test (impl, (char *) (buf1 + align), seek_char, len, result);
00db10
+    do_one_test (impl, (CHAR *) (buf + align), seek_char, len, result);
00db10
 
00db10
   putchar ('\n');
00db10
 }
00db10
diff --git a/benchtests/bench-wmemchr.c b/benchtests/bench-wmemchr.c
00db10
new file mode 100644
00db10
index 0000000..d796a69
00db10
--- /dev/null
00db10
+++ b/benchtests/bench-wmemchr.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Measure wmemchr 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-memchr.c"
00db10
diff --git a/string/test-memchr.c b/string/test-memchr.c
00db10
index cdcceeb..058a837 100644
00db10
--- a/string/test-memchr.c
00db10
+++ b/string/test-memchr.c
00db10
@@ -18,28 +18,49 @@
00db10
    <http://www.gnu.org/licenses/>.  */
00db10
 
00db10
 #define TEST_MAIN
00db10
-#define TEST_NAME "memchr"
00db10
+#ifndef WIDE
00db10
+# define TEST_NAME "memchr"
00db10
+#else
00db10
+# define TEST_NAME "wmemchr"
00db10
+#endif /* WIDE */
00db10
 #include "test-string.h"
00db10
 
00db10
-typedef char *(*proto_t) (const char *, int, size_t);
00db10
-char *simple_memchr (const char *, int, size_t);
00db10
-
00db10
-IMPL (simple_memchr, 0)
00db10
-IMPL (memchr, 1)
00db10
-
00db10
-char *
00db10
-simple_memchr (const char *s, int c, size_t n)
00db10
+#ifndef WIDE
00db10
+# define MEMCHR memchr
00db10
+# define CHAR char
00db10
+# define UCHAR unsigned char
00db10
+# define SIMPLE_MEMCHR simple_memchr
00db10
+# define BIG_CHAR CHAR_MAX
00db10
+# define SMALL_CHAR 127
00db10
+#else
00db10
+# include <wchar.h>
00db10
+# define MEMCHR wmemchr
00db10
+# define CHAR wchar_t
00db10
+# define UCHAR wchar_t
00db10
+# define SIMPLE_MEMCHR simple_wmemchr
00db10
+# define BIG_CHAR WCHAR_MAX
00db10
+# define SMALL_CHAR 1273
00db10
+#endif /* WIDE */
00db10
+
00db10
+typedef CHAR *(*proto_t) (const CHAR *, int, size_t);
00db10
+CHAR *SIMPLE_MEMCHR (const CHAR *, int, size_t);
00db10
+
00db10
+IMPL (SIMPLE_MEMCHR, 0)
00db10
+IMPL (MEMCHR, 1)
00db10
+
00db10
+CHAR *
00db10
+SIMPLE_MEMCHR (const CHAR *s, int c, size_t n)
00db10
 {
00db10
   while (n--)
00db10
-    if (*s++ == (char) c)
00db10
-      return (char *) s - 1;
00db10
+    if (*s++ == (CHAR) c)
00db10
+      return (CHAR *) s - 1;
00db10
   return NULL;
00db10
 }
00db10
 
00db10
 static void
00db10
-do_one_test (impl_t *impl, const char *s, int c, size_t n, char *exp_res)
00db10
+do_one_test (impl_t *impl, const CHAR *s, int c, size_t n, CHAR *exp_res)
00db10
 {
00db10
-  char *res = CALL (impl, s, c, n);
00db10
+  CHAR *res = CALL (impl, s, c, n);
00db10
   if (res != exp_res)
00db10
     {
00db10
       error (0, 0, "Wrong result in function %s %p %p", impl->name,
00db10
@@ -53,34 +74,36 @@ static void
00db10
 do_test (size_t align, size_t pos, size_t len, int seek_char)
00db10
 {
00db10
   size_t i;
00db10
-  char *result;
00db10
+  CHAR *result;
00db10
 
00db10
   align &= 7;
00db10
-  if (align + len >= page_size)
00db10
+  if ((align + len) * sizeof (CHAR) >= page_size)
00db10
     return;
00db10
 
00db10
+  CHAR *buf = (CHAR *) (buf1);
00db10
+
00db10
   for (i = 0; i < len; ++i)
00db10
     {
00db10
-      buf1[align + i] = 1 + 23 * i % 127;
00db10
-      if (buf1[align + i] == seek_char)
00db10
-        buf1[align + i] = seek_char + 1;
00db10
+      buf[align + i] = 1 + 23 * i % SMALL_CHAR;
00db10
+      if (buf[align + i] == seek_char)
00db10
+	buf[align + i] = seek_char + 1;
00db10
     }
00db10
-  buf1[align + len] = 0;
00db10
+  buf[align + len] = 0;
00db10
 
00db10
   if (pos < len)
00db10
     {
00db10
-      buf1[align + pos] = seek_char;
00db10
-      buf1[align + len] = -seek_char;
00db10
-      result = (char *) (buf1 + align + pos);
00db10
+      buf[align + pos] = seek_char;
00db10
+      buf[align + len] = -seek_char;
00db10
+      result = (CHAR *) (buf + align + pos);
00db10
     }
00db10
   else
00db10
     {
00db10
       result = NULL;
00db10
-      buf1[align + len] = seek_char;
00db10
+      buf[align + len] = seek_char;
00db10
     }
00db10
 
00db10
   FOR_EACH_IMPL (impl, 0)
00db10
-    do_one_test (impl, (char *) (buf1 + align), seek_char, len, result);
00db10
+    do_one_test (impl, (CHAR *) (buf + align), seek_char, len, result);
00db10
 }
00db10
 
00db10
 static void
00db10
@@ -88,8 +111,8 @@ do_random_tests (void)
00db10
 {
00db10
   size_t i, j, n, align, pos, len;
00db10
   int seek_char;
00db10
-  char *result;
00db10
-  unsigned char *p = buf1 + page_size - 512;
00db10
+  CHAR *result;
00db10
+  UCHAR *p = (UCHAR *) (buf1 + page_size) - 512;
00db10
 
00db10
   for (n = 0; n < ITERATIONS; n++)
00db10
     {
00db10
@@ -101,11 +124,11 @@ do_random_tests (void)
00db10
       if (pos >= len)
00db10
 	len = pos + (random () & 7);
00db10
       if (len + align >= 512)
00db10
-        len = 512 - align - (random () & 7);
00db10
-      seek_char = random () & 255;
00db10
+	len = 512 - align - (random () & 7);
00db10
+      seek_char = random () & BIG_CHAR;
00db10
       j = len + align + 64;
00db10
       if (j > 512)
00db10
-        j = 512;
00db10
+	j = 512;
00db10
 
00db10
       for (i = 0; i < j; i++)
00db10
 	{
00db10
@@ -113,7 +136,7 @@ do_random_tests (void)
00db10
 	    p[i] = seek_char;
00db10
 	  else
00db10
 	    {
00db10
-	      p[i] = random () & 255;
00db10
+	      p[i] = random () & BIG_CHAR;
00db10
 	      if (i < pos + align && p[i] == seek_char)
00db10
 		p[i] = seek_char + 13;
00db10
 	    }
00db10
@@ -124,17 +147,17 @@ do_random_tests (void)
00db10
 	  size_t r = random ();
00db10
 	  if ((r & 31) == 0)
00db10
 	    len = ~(uintptr_t) (p + align) - ((r >> 5) & 31);
00db10
-	  result = (char *) (p + pos + align);
00db10
+	  result = (CHAR *) (p + pos + align);
00db10
 	}
00db10
       else
00db10
 	result = NULL;
00db10
 
00db10
       FOR_EACH_IMPL (impl, 1)
00db10
-	if (CALL (impl, (char *) (p + align), seek_char, len) != result)
00db10
+	if (CALL (impl, (CHAR *) (p + align), seek_char, len) != result)
00db10
 	  {
00db10
 	    error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %d, %zd, %zd) %p != %p, p %p",
00db10
 		   n, impl->name, align, seek_char, len, pos,
00db10
-		   CALL (impl, (char *) (p + align), seek_char, len),
00db10
+		   CALL (impl, (CHAR *) (p + align), seek_char, len),
00db10
 		   result, p);
00db10
 	    ret = 1;
00db10
 	  }
00db10
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
00db10
index 2c1fce0..4a04c34 100644
00db10
--- a/sysdeps/s390/multiarch/Makefile
00db10
+++ b/sysdeps/s390/multiarch/Makefile
00db10
@@ -14,7 +14,9 @@ sysdep_routines += strlen strlen-vx strlen-c \
00db10
 		   strrchr strrchr-vx strrchr-c \
00db10
 		   strspn strspn-vx strspn-c \
00db10
 		   strpbrk strpbrk-vx strpbrk-c \
00db10
-		   strcspn strcspn-vx strcspn-c
00db10
+		   strcspn strcspn-vx strcspn-c \
00db10
+		   memchr memchr-vx \
00db10
+		   rawmemchr rawmemchr-vx rawmemchr-c
00db10
 endif
00db10
 
00db10
 ifeq ($(subdir),wcsmbs)
00db10
@@ -33,5 +35,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
00db10
 		   wcsrchr wcsrchr-vx wcsrchr-c \
00db10
 		   wcsspn wcsspn-vx wcsspn-c \
00db10
 		   wcspbrk wcspbrk-vx wcspbrk-c \
00db10
-		   wcscspn wcscspn-vx wcscspn-c
00db10
+		   wcscspn wcscspn-vx wcscspn-c \
00db10
+		   wmemchr wmemchr-vx wmemchr-c
00db10
 endif
00db10
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
index 7f62e49..d4c7c0d 100644
00db10
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
@@ -127,6 +127,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
00db10
   IFUNC_VX_IMPL (strcspn);
00db10
   IFUNC_VX_IMPL (wcscspn);
00db10
 
00db10
+  IFUNC_VX_IMPL (memchr);
00db10
+  IFUNC_VX_IMPL (wmemchr);
00db10
+  IFUNC_VX_IMPL (rawmemchr);
00db10
+
00db10
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
00db10
 
00db10
   return i;
00db10
diff --git a/sysdeps/s390/multiarch/memchr-vx.S b/sysdeps/s390/multiarch/memchr-vx.S
00db10
new file mode 100644
00db10
index 0000000..5c98fd9
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/memchr-vx.S
00db10
@@ -0,0 +1,159 @@
00db10
+/* Vector optimized 32/64 bit S/390 version of memchr.
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
+/* void *memchr (const void *s, int c, size_t n)
00db10
+   Scans memory for character c
00db10
+   and returns pointer to first c.
00db10
+
00db10
+   Register usage:
00db10
+   -r0=tmp
00db10
+   -r1=tmp
00db10
+   -r2=s
00db10
+   -r3=c
00db10
+   -r4=n
00db10
+   -r5=current_len
00db10
+   -v16=part of s
00db10
+   -v17=index of found c
00db10
+   -v18=c replicated
00db10
+*/
00db10
+ENTRY(__memchr_vx)
00db10
+
00db10
+	.machine "z13"
00db10
+	.machinemode "zarch_nohighgprs"
00db10
+
00db10
+# if !defined __s390x__
00db10
+	llgfr	%r4,%r4
00db10
+# endif /* !defined __s390x__ */
00db10
+
00db10
+	clgije	%r4,0,.Lnf_end	/* If len == 0 then exit.  */
00db10
+
00db10
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
00db10
+	lcbb	%r0,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
00db10
+	llgfr	%r0,%r0		/* Convert 32bit to 64bit.  */
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
+	lghi	%r5,16		/* current_len = 16.  */
00db10
+
00db10
+	clgrjhe	%r0,%r4,.Llastcmp /* If (bytes to boundary) >= n,
00db10
+				     jump to lastcmp.  */
00db10
+
00db10
+	vfeebs	%v17,%v16,%v18	/* Find c.  */
00db10
+	vlgvb	%r1,%v17,7	/* Load byte index of c.  */
00db10
+	clgrjl	%r1,%r0,.Lfound2 /* Found c is within loaded bytes.  */
00db10
+
00db10
+	/* Align s to 16 byte.  */
00db10
+	risbgn	%r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
00db10
+	slr	%r5,%r1		/* Compute bytes to 16bytes boundary.  */
00db10
+
00db10
+	lgr	%r0,%r5		/* If %r5 + 64 < n? -> loop64.  */
00db10
+	aghi	%r0,64
00db10
+	clgrjl	%r0,%r4,.Lloop64
00db10
+.Llt64:
00db10
+	vl	%v16,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+	clgrjhe	%r5,%r4,.Llastcmp /* Do last compare if curr-len >= n.  */
00db10
+	vfeebs	%v17,%v16,%v18	/* Find c.  */
00db10
+	jl	.Lfound	/* Jump away if c was found.  */
00db10
+
00db10
+	vl	%v16,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+	clgrjhe	%r5,%r4,.Llastcmp
00db10
+	vfeebs	%v17,%v16,%v18
00db10
+	jl	.Lfound
00db10
+
00db10
+	vl	%v16,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+	clgrjhe	%r5,%r4,.Llastcmp
00db10
+	vfeebs	%v17,%v16,%v18
00db10
+	jl	.Lfound
00db10
+
00db10
+	vl	%v16,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+
00db10
+.Llastcmp:
00db10
+	/* Use comparision result only if located within first n characters.
00db10
+	   %r5: current_len;
00db10
+	   %r4: n;
00db10
+	   (current_len - n): [0...16[
00db10
+	   first ignored match index: vr-width - (current_len - n) ]0...16]
00db10
+	*/
00db10
+	vfeebs	%v17,%v16,%v18	/* Find c.  */
00db10
+	slgrk	%r4,%r5,%r4	/* %r5 = current_len - n.  */
00db10
+	lghi	%r0,16		/* Register width = 16.  */
00db10
+	vlgvb	%r1,%v17,7	/* Extract found index or 16 if all equal.  */
00db10
+	slr	%r0,%r4		/* %r0 = first ignored match index.  */
00db10
+	clrjl	%r1,%r0,.Lfound2 /* Go away if miscompare is below n bytes.  */
00db10
+	/* c not found within n-bytes.  */
00db10
+.Lnf_end:
00db10
+	lghi	%r2,0		/* Return null.  */
00db10
+	br	%r14
00db10
+
00db10
+.Lfound48:
00db10
+	aghi	%r5,16
00db10
+.Lfound32:
00db10
+	aghi	%r5,16
00db10
+.Lfound16:
00db10
+	aghi	%r5,16
00db10
+.Lfound0:
00db10
+	aghi	%r5,16
00db10
+.Lfound:
00db10
+	vlgvb	%r1,%v17,7	/* Load byte index of c.  */
00db10
+.Lfound2:
00db10
+	slgfi	%r5,16		/* current_len -=16 */
00db10
+	algr	%r5,%r1		/* Zero byte index is added to current len.  */
00db10
+	la	%r2,0(%r5,%r2)	/* Return pointer to c.  */
00db10
+	br	%r14
00db10
+
00db10
+
00db10
+.Lloop64:
00db10
+	vl	%v16,0(%r5,%r2)
00db10
+	vfeebs	%v17,%v16,%v18	/* Find c.  */
00db10
+	jl	.Lfound0	/* Jump away if c was found.  */
00db10
+	vl	%v16,16(%r5,%r2)
00db10
+	vfeebs	%v17,%v16,%v18
00db10
+	jl	.Lfound16
00db10
+	vl	%v16,32(%r5,%r2)
00db10
+	vfeebs	%v17,%v16,%v18
00db10
+	jl	.Lfound32
00db10
+	vl	%v16,48(%r5,%r2)
00db10
+	vfeebs	%v17,%v16,%v18
00db10
+	jl	.Lfound48
00db10
+
00db10
+	aghi	%r5,64
00db10
+	lgr	%r0,%r5		/* If %r5 + 64 < n? -> loop64.  */
00db10
+	aghi	%r0,64
00db10
+	clgrjl	%r0,%r4,.Lloop64
00db10
+
00db10
+	j	.Llt64
00db10
+END(__memchr_vx)
00db10
+
00db10
+# define memchr __memchr_c
00db10
+# undef libc_hidden_builtin_def
00db10
+# define libc_hidden_builtin_def(name) strong_alias(__memchr_c, __GI_memchr)
00db10
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
00db10
+
00db10
+#include <memchr.S>
00db10
diff --git a/sysdeps/s390/multiarch/memchr.c b/sysdeps/s390/multiarch/memchr.c
00db10
new file mode 100644
00db10
index 0000000..6624765
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/memchr.c
00db10
@@ -0,0 +1,24 @@
00db10
+/* Multiple versions of memchr.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
00db10
+# include <string.h>
00db10
+# include <ifunc-resolve.h>
00db10
+
00db10
+s390_vx_libc_ifunc2 (__memchr, memchr)
00db10
+#endif
00db10
diff --git a/sysdeps/s390/multiarch/rawmemchr-c.c b/sysdeps/s390/multiarch/rawmemchr-c.c
00db10
new file mode 100644
00db10
index 0000000..f652133
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/rawmemchr-c.c
00db10
@@ -0,0 +1,34 @@
00db10
+/* Default rawmemchr 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
+# include <string.h>
00db10
+
00db10
+# define RAWMEMCHR  __rawmemchr_c
00db10
+# undef weak_alias
00db10
+# define weak_alias(a, b)
00db10
+# ifdef SHARED
00db10
+#  undef libc_hidden_def
00db10
+#  define libc_hidden_def(name)				\
00db10
+     __hidden_ver1 (__rawmemchr_c, __GI___rawmemchr, __rawmemchr_c);
00db10
+# endif /* SHARED */
00db10
+
00db10
+extern __typeof (rawmemchr) __rawmemchr_c attribute_hidden;
00db10
+
00db10
+# include <string/rawmemchr.c>
00db10
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
00db10
diff --git a/sysdeps/s390/multiarch/rawmemchr-vx.S b/sysdeps/s390/multiarch/rawmemchr-vx.S
00db10
new file mode 100644
00db10
index 0000000..2af4570
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/rawmemchr-vx.S
00db10
@@ -0,0 +1,92 @@
00db10
+/* Vector optimized 32/64 bit S/390 version of rawmemchr.
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
+/* void *rawmemchr (const void *s, int c)
00db10
+   Scans memory for character c
00db10
+   and returns pointer to first c.
00db10
+
00db10
+   Register usage:
00db10
+   -r1=tmp
00db10
+   -r2=s
00db10
+   -r3=c
00db10
+   -r4=tmp
00db10
+   -r5=current_len
00db10
+   -v16=part of s
00db10
+   -v17=index of unequal
00db10
+   -v18=c replicated
00db10
+*/
00db10
+ENTRY(__rawmemchr_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
+	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
+	vfeeb	%v17,%v16,%v18	/* Vector find element equal.  */
00db10
+	vlgvb	%r5,%v17,7	/* Load byte index of character or zero.  */
00db10
+	clrjl	%r5,%r1,.Lend_found /* If found c is in loaded bytes, end.  */
00db10
+
00db10
+	/* Align s to 16 byte.  */
00db10
+	risbgn	%r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
00db10
+	lghi	%r5,16
00db10
+	slr	%r5,%r1		/* Compute bytes to 16bytes boundary.  */
00db10
+
00db10
+	/* Find c in a 16byte aligned loop.  */
00db10
+.Lloop:
00db10
+	vl	%v16,0(%r5,%r2)	/* Load s.  */
00db10
+	vfeebs	%v17,%v16,%v18	/* Vector find element equal.  */
00db10
+	jno	.Lcharacter	/* Jump away if element found.  */
00db10
+	vl	%v16,16(%r5,%r2)
00db10
+	vfeebs	%v17,%v16,%v18
00db10
+	jno	.Lcharacter16
00db10
+	vl	%v16,32(%r5,%r2)
00db10
+	vfeebs	%v17,%v16,%v18
00db10
+	jno	.Lcharacter32
00db10
+	vl	%v16,48(%r5,%r2)
00db10
+	vfeebs	%v17,%v16,%v18
00db10
+	jno	.Lcharacter48
00db10
+
00db10
+	aghi	%r5,64
00db10
+	j	.Lloop		/* No character found -> loop.  */
00db10
+
00db10
+	/* Found character.  */
00db10
+.Lcharacter48:
00db10
+	aghi %r5,16
00db10
+.Lcharacter32:
00db10
+	aghi %r5,16
00db10
+.Lcharacter16:
00db10
+	aghi %r5,16
00db10
+.Lcharacter:
00db10
+	vlgvb	%r1,%v17,7	/* Load byte index of character.  */
00db10
+	algr	%r5,%r1
00db10
+.Lend_found:
00db10
+	la	%r2,0(%r5,%r2)	/* Return pointer to character.  */
00db10
+	br	%r14
00db10
+END(__rawmemchr_vx)
00db10
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
00db10
diff --git a/sysdeps/s390/multiarch/rawmemchr.c b/sysdeps/s390/multiarch/rawmemchr.c
00db10
new file mode 100644
00db10
index 0000000..2335289
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/rawmemchr.c
00db10
@@ -0,0 +1,28 @@
00db10
+/* Multiple versions of rawmemchr.
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 (__rawmemchr)
00db10
+weak_alias (__rawmemchr, rawmemchr)
00db10
+
00db10
+#else
00db10
+# include <string/rawmemchr.c>
00db10
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT &&!defined NOT_IN_libc ) */
00db10
diff --git a/sysdeps/s390/multiarch/wmemchr-c.c b/sysdeps/s390/multiarch/wmemchr-c.c
00db10
new file mode 100644
00db10
index 0000000..d4abeb4
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wmemchr-c.c
00db10
@@ -0,0 +1,31 @@
00db10
+/* Default wmemchr 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 WMEMCHR  __wmemchr_c
00db10
+
00db10
+# include <wchar.h>
00db10
+extern __typeof (wmemchr) __wmemchr_c;
00db10
+# ifdef SHARED
00db10
+#  undef libc_hidden_def
00db10
+#  define libc_hidden_def(name)			\
00db10
+  __hidden_ver1 (__wmemchr_c, __GI_wmemchr, __wmemchr_c);
00db10
+# endif /* SHARED */
00db10
+
00db10
+# include <wcsmbs/wmemchr.c>
00db10
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
00db10
diff --git a/sysdeps/s390/multiarch/wmemchr-vx.S b/sysdeps/s390/multiarch/wmemchr-vx.S
00db10
new file mode 100644
00db10
index 0000000..4df08d2
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wmemchr-vx.S
00db10
@@ -0,0 +1,166 @@
00db10
+/* Vector optimized 32/64 bit S/390 version of wmemchr.
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 *wmemchr (const wchar_t *s, wchar_t c, size_t n)
00db10
+   Scans memory for character c
00db10
+   and returns pointer to first c.
00db10
+
00db10
+   Register usage:
00db10
+   -r0=tmp
00db10
+   -r1=tmp
00db10
+   -r2=s
00db10
+   -r3=c
00db10
+   -r4=n
00db10
+   -r5=current_len
00db10
+   -v16=part of s
00db10
+   -v17=index of found c
00db10
+   -v18=c replicated
00db10
+*/
00db10
+ENTRY(__wmemchr_vx)
00db10
+	.machine "z13"
00db10
+	.machinemode "zarch_nohighgprs"
00db10
+
00db10
+# if !defined __s390x__
00db10
+	llgfr	%r4,%r4
00db10
+# endif /* !defined __s390x__ */
00db10
+
00db10
+	clgije	%r4,0,.Lnf_end	/* If len == 0 then exit.  */
00db10
+
00db10
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
00db10
+	lcbb	%r0,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
00db10
+	llgfr	%r0,%r0		/* Convert 32bit to 64bit.  */
00db10
+
00db10
+	tmll	%r2,3		/* Test if s is 4-byte aligned?  */
00db10
+	jne	.Lfallback	/* And use common-code variant if not.  */
00db10
+
00db10
+	vlvgf	%v18,%r3,0	/* Generate vector which elements are all c.  */
00db10
+	vrepf	%v18,%v18,0
00db10
+	lghi	%r5,16		/* current_len = 16.  */
00db10
+
00db10
+	/* Check range of maxlen and convert to byte-count.  */
00db10
+# ifdef __s390x__
00db10
+	tmhh	%r4,49152	/* Test bit 0 or 1 of maxlen.  */
00db10
+	lghi	%r1,-4		/* Max byte-count is 18446744073709551612.  */
00db10
+# else
00db10
+	tmlh	%r4,49152	/* Test bit 0 or 1 of maxlen.  */
00db10
+	llilf	%r1,4294967292	/* Max byte-count is 4294967292.  */
00db10
+# endif /* !__s390x__ */
00db10
+	sllg	%r4,%r4,2	/* Convert character-count to byte-count.  */
00db10
+	locgrne	%r4,%r1		/* Use max byte-count, if bit 0/1 was one.  */
00db10
+
00db10
+	clgrjhe	%r0,%r4,.Llastcmp /* If (bytes to boundary) >= n,
00db10
+				     jump to lastcmp.  */
00db10
+
00db10
+	vfeefs	%v17,%v16,%v18	/* Find c.  */
00db10
+	vlgvb	%r1,%v17,7	/* Load byte index of c.  */
00db10
+	clgrjl	%r1,%r0,.Lfound2 /* Found c is within loaded bytes.  */
00db10
+
00db10
+	/* Align s to 16 byte.  */
00db10
+	risbgn	%r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
00db10
+	slr	%r5,%r1		/* Compute bytes to 16bytes boundary.  */
00db10
+
00db10
+	lgr	%r0,%r5		/* If %r5 + 64 < n? -> loop64.  */
00db10
+	aghi	%r0,64
00db10
+	clgrjl	%r0,%r4,.Lloop64
00db10
+.Llt64:
00db10
+	vl	%v16,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+	clgrjhe	%r5,%r4,.Llastcmp /* Do last compare if curr-len >= n.  */
00db10
+	vfeefs	%v17,%v16,%v18	/* Find c.  */
00db10
+	jl	.Lfound		/* Jump away if c was found.  */
00db10
+
00db10
+	vl	%v16,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+	clgrjhe	%r5,%r4,.Llastcmp
00db10
+	vfeefs	%v17,%v16,%v18
00db10
+	jl	.Lfound
00db10
+
00db10
+	vl	%v16,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+	clgrjhe	%r5,%r4,.Llastcmp
00db10
+	vfeefs	%v17,%v16,%v18
00db10
+	jl	.Lfound
00db10
+
00db10
+	vl	%v16,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+
00db10
+.Llastcmp:
00db10
+	/* Use comparision result only if located within first n characters.
00db10
+	   %r5: current_len;
00db10
+	   %r4: n;
00db10
+	   (current_len - n): [0...16[
00db10
+	   first ignored match index = vr-width - (current_len - n) ]0...16]
00db10
+	*/
00db10
+	vfeefs	%v17,%v16,%v18	/* Find c.  */
00db10
+	slgrk	%r4,%r5,%r4	/* %r5 = current_len - n.  */
00db10
+	lghi	%r0,16		/* Register width = 16.  */
00db10
+	vlgvb	%r1,%v17,7	/* Extract found index or 16 if all equal.  */
00db10
+	slr	%r0,%r4		/* %r0 = first ignored match index.  */
00db10
+	clrjl	%r1,%r0,.Lfound2 /* Go away if miscompare is below n bytes.  */
00db10
+	/* c not found within n-bytes.  */
00db10
+.Lnf_end:
00db10
+	lghi	%r2,0		/* Return null.  */
00db10
+	br	%r14
00db10
+
00db10
+.Lfound48:
00db10
+	aghi	%r5,16
00db10
+.Lfound32:
00db10
+	aghi	%r5,16
00db10
+.Lfound16:
00db10
+	aghi	%r5,16
00db10
+.Lfound0:
00db10
+	aghi	%r5,16
00db10
+.Lfound:
00db10
+	vlgvb	%r1,%v17,7	/* Load byte index of c.  */
00db10
+.Lfound2:
00db10
+	slgfi	%r5,16		/* current_len -=16 */
00db10
+	algr	%r5,%r1		/* Zero byte index is added to current len.  */
00db10
+	la	%r2,0(%r5,%r2)	/* Return pointer to c.  */
00db10
+	br	%r14
00db10
+
00db10
+.Lloop64:
00db10
+	vl	%v16,0(%r5,%r2)
00db10
+	vfeefs	%v17,%v16,%v18	/* Find c.  */
00db10
+	jl	.Lfound0	/* Jump away if c was found.  */
00db10
+	vl	%v16,16(%r5,%r2)
00db10
+	vfeefs	%v17,%v16,%v18
00db10
+	jl	.Lfound16
00db10
+	vl	%v16,32(%r5,%r2)
00db10
+	vfeefs	%v17,%v16,%v18
00db10
+	jl	.Lfound32
00db10
+	vl	%v16,48(%r5,%r2)
00db10
+	vfeefs	%v17,%v16,%v18
00db10
+	jl	.Lfound48
00db10
+
00db10
+	aghi	%r5,64
00db10
+	lgr	%r0,%r5		/* If %r5 + 64 < n? -> loop64.  */
00db10
+	aghi	%r0,64
00db10
+	clgrjl	%r0,%r4,.Lloop64
00db10
+
00db10
+	j	.Llt64
00db10
+.Lfallback:
00db10
+	jg	__wmemchr_c
00db10
+END(__wmemchr_vx)
00db10
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
00db10
diff --git a/sysdeps/s390/multiarch/wmemchr.c b/sysdeps/s390/multiarch/wmemchr.c
00db10
new file mode 100644
00db10
index 0000000..b8b0e83
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wmemchr.c
00db10
@@ -0,0 +1,27 @@
00db10
+/* Multiple versions of wmemchr.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
00db10
+# include <wchar.h>
00db10
+# include <ifunc-resolve.h>
00db10
+
00db10
+s390_vx_libc_ifunc2 (__wmemchr, wmemchr)
00db10
+
00db10
+#else
00db10
+# include <wcsmbs/wmemchr.c>
00db10
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
00db10
diff --git a/sysdeps/s390/s390-32/multiarch/memchr.c b/sysdeps/s390/s390-32/multiarch/memchr.c
00db10
new file mode 100644
00db10
index 0000000..00958cd
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/s390-32/multiarch/memchr.c
00db10
@@ -0,0 +1,21 @@
00db10
+/* Multiple versions of memchr.
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
+/* This wrapper-file is needed, because otherwise file
00db10
+   sysdeps/s390/s390-[32|64]/memchr.S will be used.  */
00db10
+#include <sysdeps/s390/multiarch/memchr.c>
00db10
diff --git a/sysdeps/s390/s390-64/multiarch/memchr.c b/sysdeps/s390/s390-64/multiarch/memchr.c
00db10
new file mode 100644
00db10
index 0000000..00958cd
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/s390-64/multiarch/memchr.c
00db10
@@ -0,0 +1,21 @@
00db10
+/* Multiple versions of memchr.
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
+/* This wrapper-file is needed, because otherwise file
00db10
+   sysdeps/s390/s390-[32|64]/memchr.S will be used.  */
00db10
+#include <sysdeps/s390/multiarch/memchr.c>
00db10
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
00db10
index 9730b00..f8bc401 100644
00db10
--- a/wcsmbs/Makefile
00db10
+++ b/wcsmbs/Makefile
00db10
@@ -43,7 +43,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
00db10
 
00db10
 strop-tests :=  wcscmp wcsncmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
00db10
 		wcpcpy wcsncpy wcpncpy wcscat wcsncat wcschrnul wcsspn wcspbrk \
00db10
-		wcscspn
00db10
+		wcscspn wmemchr
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-wmemchr-ifunc.c b/wcsmbs/test-wmemchr-ifunc.c
00db10
new file mode 100644
00db10
index 0000000..4b40871
00db10
--- /dev/null
00db10
+++ b/wcsmbs/test-wmemchr-ifunc.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Test and measure IFUNC implementations of wmemchr 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-wmemchr.c"
00db10
diff --git a/wcsmbs/test-wmemchr.c b/wcsmbs/test-wmemchr.c
00db10
new file mode 100644
00db10
index 0000000..90c7f68
00db10
--- /dev/null
00db10
+++ b/wcsmbs/test-wmemchr.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Test wmemchr 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-memchr.c"
00db10
diff --git a/wcsmbs/wmemchr.c b/wcsmbs/wmemchr.c
00db10
index 99ebed4..905a321 100644
00db10
--- a/wcsmbs/wmemchr.c
00db10
+++ b/wcsmbs/wmemchr.c
00db10
@@ -18,6 +18,10 @@
00db10
 
00db10
 #include <wchar.h>
00db10
 
00db10
+#ifdef WMEMCHR
00db10
+# define wmemchr WMEMCHR
00db10
+#endif
00db10
+
00db10
 wchar_t *
00db10
 wmemchr (s, c, n)
00db10
      register const wchar_t *s;
00db10
-- 
00db10
2.3.0
00db10