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