bca718
From 67611d45bb5e464f2e80782ec37ce3548459cf57 Mon Sep 17 00:00:00 2001
bca718
From: Stefan Liebler <stli@linux.vnet.ibm.com>
bca718
Date: Thu, 8 Oct 2015 12:56:03 +0200
bca718
Subject: [PATCH 23/30] S390: Optimize strspn and wcsspn.
bca718
bca718
upstream-commit-id: f1ffad98be7ec4111fbd1cd1f58f3e3343257519
bca718
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00095.html
bca718
bca718
This patch provides optimized versions of strspn and wcsspn with the z13
bca718
vector instructions.
bca718
bca718
ChangeLog:
bca718
bca718
	* sysdeps/s390/multiarch/strspn-c.c: New File.
bca718
	* sysdeps/s390/multiarch/strspn-vx.S: Likewise.
bca718
	* sysdeps/s390/multiarch/strspn.c: Likewise.
bca718
	* sysdeps/s390/multiarch/wcsspn-c.c: Likewise.
bca718
	* sysdeps/s390/multiarch/wcsspn-vx.S: Likewise.
bca718
	* sysdeps/s390/multiarch/wcsspn.c: Likewise.
bca718
	* wcsmbs/wcsspn.c: Use WCSSPN if defined.
bca718
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add strspn and
bca718
	wcsspn functions.
bca718
	* sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
	(__libc_ifunc_impl_list): Add ifunc test for strspn, wcsspn.
bca718
	* string/test-strspn.c: Add wcsspn support.
bca718
	* wcsmbs/test-wcsspn.c: New File.
bca718
	* wcsmbs/Makefile (strop-tests): Add wcsspn.
bca718
	* benchtests/bench-strspn.c: Add wcsspn support.
bca718
	* benchtests/bench-wcsspn.c: New File.
bca718
	* benchtests/Makefile (wcsmbs-bench): Add wcsspn.
bca718
---
bca718
 benchtests/Makefile                      |   2 +-
bca718
 benchtests/bench-strspn.c                |  71 +++++---
bca718
 benchtests/bench-wcsspn.c                |  20 +++
bca718
 string/strspn.c                          |   7 +-
bca718
 string/test-strspn.c                     | 100 +++++++-----
bca718
 sysdeps/s390/multiarch/Makefile          |   6 +-
bca718
 sysdeps/s390/multiarch/ifunc-impl-list.c |   3 +
bca718
 sysdeps/s390/multiarch/strspn-c.c        |  28 ++++
bca718
 sysdeps/s390/multiarch/strspn-vx.S       | 256 +++++++++++++++++++++++++++++
bca718
 sysdeps/s390/multiarch/strspn.c          |  27 ++++
bca718
 sysdeps/s390/multiarch/wcsspn-c.c        |  31 ++++
bca718
 sysdeps/s390/multiarch/wcsspn-vx.S       | 270 +++++++++++++++++++++++++++++++
bca718
 sysdeps/s390/multiarch/wcsspn.c          |  27 ++++
bca718
 wcsmbs/Makefile                          |   2 +-
bca718
 wcsmbs/test-wcsspn-ifunc.c               |  20 +++
bca718
 wcsmbs/test-wcsspn.c                     |  20 +++
bca718
 wcsmbs/wcsspn.c                          |   3 +
bca718
 17 files changed, 827 insertions(+), 66 deletions(-)
bca718
 create mode 100644 benchtests/bench-wcsspn.c
bca718
 create mode 100644 sysdeps/s390/multiarch/strspn-c.c
bca718
 create mode 100644 sysdeps/s390/multiarch/strspn-vx.S
bca718
 create mode 100644 sysdeps/s390/multiarch/strspn.c
bca718
 create mode 100644 sysdeps/s390/multiarch/wcsspn-c.c
bca718
 create mode 100644 sysdeps/s390/multiarch/wcsspn-vx.S
bca718
 create mode 100644 sysdeps/s390/multiarch/wcsspn.c
bca718
 create mode 100644 wcsmbs/test-wcsspn-ifunc.c
bca718
 create mode 100644 wcsmbs/test-wcsspn.c
bca718
bca718
diff --git a/benchtests/Makefile b/benchtests/Makefile
bca718
index 6444394..337b2a1 100644
bca718
--- a/benchtests/Makefile
bca718
+++ b/benchtests/Makefile
bca718
@@ -39,7 +39,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
bca718
 		strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
bca718
 		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
bca718
 wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
bca718
-		wcsncmp wcsncmp wcschr wcschrnul wcsrchr
bca718
+		wcsncmp wcsncmp wcschr wcschrnul wcsrchr wcsspn
bca718
 string-bench-all := $(string-bench) ${wcsmbs-bench}
bca718
 
bca718
 stdlib-bench := strtod
bca718
diff --git a/benchtests/bench-strspn.c b/benchtests/bench-strspn.c
bca718
index 634bca1..e1f2272 100644
bca718
--- a/benchtests/bench-strspn.c
bca718
+++ b/benchtests/bench-strspn.c
bca718
@@ -17,22 +17,47 @@
bca718
    <http://www.gnu.org/licenses/>.  */
bca718
 
bca718
 #define TEST_MAIN
bca718
-#define TEST_NAME "strspn"
bca718
+#ifndef WIDE
bca718
+# define TEST_NAME "strspn"
bca718
+#else
bca718
+# define TEST_NAME "wcsspn"
bca718
+#endif /* WIDE */
bca718
 #include "bench-string.h"
bca718
 
bca718
-typedef size_t (*proto_t) (const char *, const char *);
bca718
-size_t simple_strspn (const char *, const char *);
bca718
-size_t stupid_strspn (const char *, const char *);
bca718
-
bca718
-IMPL (stupid_strspn, 0)
bca718
-IMPL (simple_strspn, 0)
bca718
-IMPL (strspn, 1)
bca718
+#ifndef WIDE
bca718
+# define STRSPN strspn
bca718
+# define CHAR char
bca718
+# define SIMPLE_STRSPN simple_strspn
bca718
+# define STUPID_STRSPN stupid_strspn
bca718
+# define STRLEN strlen
bca718
+# define STRCHR strchr
bca718
+# define BIG_CHAR CHAR_MAX
bca718
+# define SMALL_CHAR 127
bca718
+#else
bca718
+# include <wchar.h>
bca718
+# define STRSPN wcsspn
bca718
+# define CHAR wchar_t
bca718
+# define SIMPLE_STRSPN simple_wcsspn
bca718
+# define STUPID_STRSPN stupid_wcsspn
bca718
+# define STRLEN wcslen
bca718
+# define STRCHR wcschr
bca718
+# define BIG_CHAR WCHAR_MAX
bca718
+# define SMALL_CHAR 1273
bca718
+#endif /* WIDE */
bca718
+
bca718
+typedef size_t (*proto_t) (const CHAR *, const CHAR *);
bca718
+size_t SIMPLE_STRSPN (const CHAR *, const CHAR *);
bca718
+size_t STUPID_STRSPN (const CHAR *, const CHAR *);
bca718
+
bca718
+IMPL (STUPID_STRSPN, 0)
bca718
+IMPL (SIMPLE_STRSPN, 0)
bca718
+IMPL (STRSPN, 1)
bca718
 
bca718
 size_t
bca718
-simple_strspn (const char *s, const char *acc)
bca718
+SIMPLE_STRSPN (const CHAR *s, const CHAR *acc)
bca718
 {
bca718
-  const char *r, *str = s;
bca718
-  char c;
bca718
+  const CHAR *r, *str = s;
bca718
+  CHAR c;
bca718
 
bca718
   while ((c = *s++) != '\0')
bca718
     {
bca718
@@ -46,9 +71,9 @@ simple_strspn (const char *s, const char *acc)
bca718
 }
bca718
 
bca718
 size_t
bca718
-stupid_strspn (const char *s, const char *acc)
bca718
+STUPID_STRSPN (const CHAR *s, const CHAR *acc)
bca718
 {
bca718
-  size_t ns = strlen (s), nacc = strlen (acc);
bca718
+  size_t ns = STRLEN (s), nacc = STRLEN (acc);
bca718
   size_t i, j;
bca718
 
bca718
   for (i = 0; i < ns; ++i)
bca718
@@ -63,7 +88,7 @@ stupid_strspn (const char *s, const char *acc)
bca718
 }
bca718
 
bca718
 static void
bca718
-do_one_test (impl_t *impl, const char *s, const char *acc, size_t exp_res)
bca718
+do_one_test (impl_t *impl, const CHAR *s, const CHAR *acc, size_t exp_res)
bca718
 {
bca718
   size_t res = CALL (impl, s, acc), i, iters = INNER_LOOP_ITERS;
bca718
   timing_t start, stop, cur;
bca718
@@ -92,34 +117,34 @@ static void
bca718
 do_test (size_t align, size_t pos, size_t len)
bca718
 {
bca718
   size_t i;
bca718
-  char *acc, *s;
bca718
+  CHAR *acc, *s;
bca718
 
bca718
   align &= 7;
bca718
-  if (align + pos + 10 >= page_size || len > 240 || ! len)
bca718
+  if ((align + pos + 10) * sizeof (CHAR) >= page_size || len > 240 || ! len)
bca718
     return;
bca718
 
bca718
-  acc = (char *) (buf2 + (random () & 255));
bca718
-  s = (char *) (buf1 + align);
bca718
+  acc = (CHAR *) (buf2) + (random () & BIG_CHAR);
bca718
+  s = (CHAR *) (buf1) + align;
bca718
 
bca718
   for (i = 0; i < len; ++i)
bca718
     {
bca718
-      acc[i] = random () & 255;
bca718
+      acc[i] = random () & BIG_CHAR;
bca718
       if (!acc[i])
bca718
-	acc[i] = random () & 255;
bca718
+	acc[i] = random () & BIG_CHAR;
bca718
       if (!acc[i])
bca718
-	acc[i] = 1 + (random () & 127);
bca718
+	acc[i] = 1 + (random () & SMALL_CHAR);
bca718
     }
bca718
   acc[len] = '\0';
bca718
 
bca718
   for (i = 0; i < pos; ++i)
bca718
     s[i] = acc[random () % len];
bca718
-  s[pos] = random () & 255;
bca718
+  s[pos] = random () & BIG_CHAR;
bca718
   if (strchr (acc, s[pos]))
bca718
     s[pos] = '\0';
bca718
   else
bca718
     {
bca718
       for (i = pos + 1; i < pos + 10; ++i)
bca718
-	s[i] = random () & 255;
bca718
+	s[i] = random () & BIG_CHAR;
bca718
       s[i] = '\0';
bca718
     }
bca718
 
bca718
diff --git a/benchtests/bench-wcsspn.c b/benchtests/bench-wcsspn.c
bca718
new file mode 100644
bca718
index 0000000..7bdef50
bca718
--- /dev/null
bca718
+++ b/benchtests/bench-wcsspn.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Measure wcsspn functions.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#define WIDE 1
bca718
+#include "bench-strspn.c"
bca718
diff --git a/string/strspn.c b/string/strspn.c
bca718
index 48624aa..f0ac9db 100644
bca718
--- a/string/strspn.c
bca718
+++ b/string/strspn.c
bca718
@@ -18,13 +18,14 @@
bca718
 #include <string.h>
bca718
 
bca718
 #undef strspn
bca718
+#ifndef STRSPN
bca718
+#define STRSPN strspn
bca718
+#endif
bca718
 
bca718
 /* Return the length of the maximum initial segment
bca718
    of S which contains only characters in ACCEPT.  */
bca718
 size_t
bca718
-strspn (s, accept)
bca718
-     const char *s;
bca718
-     const char *accept;
bca718
+STRSPN (const char *s, const char *accept)
bca718
 {
bca718
   const char *p;
bca718
   const char *a;
bca718
diff --git a/string/test-strspn.c b/string/test-strspn.c
bca718
index 0d6cd19..306958e 100644
bca718
--- a/string/test-strspn.c
bca718
+++ b/string/test-strspn.c
bca718
@@ -18,22 +18,49 @@
bca718
    <http://www.gnu.org/licenses/>.  */
bca718
 
bca718
 #define TEST_MAIN
bca718
-#define TEST_NAME "strspn"
bca718
+#ifndef WIDE
bca718
+# define TEST_NAME "strspn"
bca718
+#else
bca718
+# define TEST_NAME "wcsspn"
bca718
+#endif /* WIDE */
bca718
 #include "test-string.h"
bca718
 
bca718
-typedef size_t (*proto_t) (const char *, const char *);
bca718
-size_t simple_strspn (const char *, const char *);
bca718
-size_t stupid_strspn (const char *, const char *);
bca718
-
bca718
-IMPL (stupid_strspn, 0)
bca718
-IMPL (simple_strspn, 0)
bca718
-IMPL (strspn, 1)
bca718
+#ifndef WIDE
bca718
+# define STRSPN strspn
bca718
+# define CHAR char
bca718
+# define UCHAR unsigned char
bca718
+# define SIMPLE_STRSPN simple_strspn
bca718
+# define STUPID_STRSPN stupid_strspn
bca718
+# define STRLEN strlen
bca718
+# define STRCHR strchr
bca718
+# define BIG_CHAR CHAR_MAX
bca718
+# define SMALL_CHAR 127
bca718
+#else
bca718
+# include <wchar.h>
bca718
+# define STRSPN wcsspn
bca718
+# define CHAR wchar_t
bca718
+# define UCHAR wchar_t
bca718
+# define SIMPLE_STRSPN simple_wcsspn
bca718
+# define STUPID_STRSPN stupid_wcsspn
bca718
+# define STRLEN wcslen
bca718
+# define STRCHR wcschr
bca718
+# define BIG_CHAR WCHAR_MAX
bca718
+# define SMALL_CHAR 1273
bca718
+#endif /* WIDE */
bca718
+
bca718
+typedef size_t (*proto_t) (const CHAR *, const CHAR *);
bca718
+size_t SIMPLE_STRSPN (const CHAR *, const CHAR *);
bca718
+size_t STUPID_STRSPN (const CHAR *, const CHAR *);
bca718
+
bca718
+IMPL (STUPID_STRSPN, 0)
bca718
+IMPL (SIMPLE_STRSPN, 0)
bca718
+IMPL (STRSPN, 1)
bca718
 
bca718
 size_t
bca718
-simple_strspn (const char *s, const char *acc)
bca718
+SIMPLE_STRSPN (const CHAR *s, const CHAR *acc)
bca718
 {
bca718
-  const char *r, *str = s;
bca718
-  char c;
bca718
+  const CHAR *r, *str = s;
bca718
+  CHAR c;
bca718
 
bca718
   while ((c = *s++) != '\0')
bca718
     {
bca718
@@ -47,9 +74,9 @@ simple_strspn (const char *s, const char *acc)
bca718
 }
bca718
 
bca718
 size_t
bca718
-stupid_strspn (const char *s, const char *acc)
bca718
+STUPID_STRSPN (const CHAR *s, const CHAR *acc)
bca718
 {
bca718
-  size_t ns = strlen (s), nacc = strlen (acc);
bca718
+  size_t ns = STRLEN (s), nacc = STRLEN (acc);
bca718
   size_t i, j;
bca718
 
bca718
   for (i = 0; i < ns; ++i)
bca718
@@ -64,7 +91,7 @@ stupid_strspn (const char *s, const char *acc)
bca718
 }
bca718
 
bca718
 static void
bca718
-do_one_test (impl_t *impl, const char *s, const char *acc, size_t exp_res)
bca718
+do_one_test (impl_t *impl, const CHAR *s, const CHAR *acc, size_t exp_res)
bca718
 {
bca718
   size_t res = CALL (impl, s, acc);
bca718
   if (res != exp_res)
bca718
@@ -80,34 +107,34 @@ static void
bca718
 do_test (size_t align, size_t pos, size_t len)
bca718
 {
bca718
   size_t i;
bca718
-  char *acc, *s;
bca718
+  CHAR *acc, *s;
bca718
 
bca718
   align &= 7;
bca718
-  if (align + pos + 10 >= page_size || len > 240 || ! len)
bca718
+  if ((align + pos + 10) * sizeof (CHAR) >= page_size || len > 240 || ! len)
bca718
     return;
bca718
 
bca718
-  acc = (char *) (buf2 + (random () & 255));
bca718
-  s = (char *) (buf1 + align);
bca718
+  acc = (CHAR *) (buf2) + (random () & 255);
bca718
+  s = (CHAR *) (buf1) + align;
bca718
 
bca718
   for (i = 0; i < len; ++i)
bca718
     {
bca718
-      acc[i] = random () & 255;
bca718
+      acc[i] = random () & BIG_CHAR;
bca718
       if (!acc[i])
bca718
-	acc[i] = random () & 255;
bca718
+	acc[i] = random () & BIG_CHAR;
bca718
       if (!acc[i])
bca718
-	acc[i] = 1 + (random () & 127);
bca718
+	acc[i] = 1 + (random () & SMALL_CHAR);
bca718
     }
bca718
   acc[len] = '\0';
bca718
 
bca718
   for (i = 0; i < pos; ++i)
bca718
     s[i] = acc[random () % len];
bca718
-  s[pos] = random () & 255;
bca718
-  if (strchr (acc, s[pos]))
bca718
+  s[pos] = random () & BIG_CHAR;
bca718
+  if (STRCHR (acc, s[pos]))
bca718
     s[pos] = '\0';
bca718
   else
bca718
     {
bca718
       for (i = pos + 1; i < pos + 10; ++i)
bca718
-	s[i] = random () & 255;
bca718
+	s[i] = random () & BIG_CHAR;
bca718
       s[i] = '\0';
bca718
     }
bca718
 
bca718
@@ -119,8 +146,8 @@ static void
bca718
 do_random_tests (void)
bca718
 {
bca718
   size_t i, j, n, align, pos, alen, len;
bca718
-  unsigned char *p = buf1 + page_size - 512;
bca718
-  unsigned char *acc;
bca718
+  UCHAR *p = (UCHAR *) (buf1 + page_size) - 512;
bca718
+  UCHAR *acc;
bca718
 
bca718
   for (n = 0; n < ITERATIONS; n++)
bca718
     {
bca718
@@ -138,14 +165,14 @@ do_random_tests (void)
bca718
       len = random () & 511;
bca718
       if (len + align >= 512)
bca718
 	len = 511 - align - (random () & 7);
bca718
-      acc = buf2 + page_size - alen - 1 - (random () & 7);
bca718
+      acc = (UCHAR *) (buf2 + page_size) - alen - 1 - (random () & 7);
bca718
       for (i = 0; i < alen; ++i)
bca718
 	{
bca718
-	  acc[i] = random () & 255;
bca718
+	  acc[i] = random () & BIG_CHAR;
bca718
 	  if (!acc[i])
bca718
-	    acc[i] = random () & 255;
bca718
+	    acc[i] = random () & BIG_CHAR;
bca718
 	  if (!acc[i])
bca718
-	    acc[i] = 1 + (random () & 127);
bca718
+	    acc[i] = 1 + (random () & SMALL_CHAR);
bca718
 	}
bca718
       acc[i] = '\0';
bca718
       j = (pos > len ? pos : len) + align + 64;
bca718
@@ -158,26 +185,27 @@ do_random_tests (void)
bca718
 	    p[i] = '\0';
bca718
 	  else if (i == pos + align)
bca718
 	    {
bca718
-	      p[i] = random () & 255;
bca718
-	      if (strchr ((char *) acc, p[i]))
bca718
+	      p[i] = random () & BIG_CHAR;
bca718
+	      if (STRCHR ((CHAR *) acc, p[i]))
bca718
 		p[i] = '\0';
bca718
 	    }
bca718
 	  else if (i < align || i > pos + align)
bca718
-	    p[i] = random () & 255;
bca718
+	    p[i] = random () & BIG_CHAR;
bca718
 	  else
bca718
 	    p[i] = acc [random () % alen];
bca718
 	}
bca718
 
bca718
       FOR_EACH_IMPL (impl, 1)
bca718
-	if (CALL (impl, (char *) (p + align),
bca718
-		  (char *) acc) != (pos < len ? pos : len))
bca718
+	if (CALL (impl, (CHAR *) (p + align),
bca718
+		  (CHAR *) acc) != (pos < len ? pos : len))
bca718
 	  {
bca718
 	    error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %p, %zd, %zd, %zd) %zd != %zd",
bca718
 		   n, impl->name, align, acc, alen, pos, len,
bca718
-		   CALL (impl, (char *) (p + align), (char *) acc),
bca718
+		   CALL (impl, (CHAR *) (p + align), (CHAR *) acc),
bca718
 		   (pos < len ? pos : len));
bca718
 	    ret = 1;
bca718
 	  }
bca718
+
bca718
     }
bca718
 }
bca718
 
bca718
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bca718
index b8b141e..9403169 100644
bca718
--- a/sysdeps/s390/multiarch/Makefile
bca718
+++ b/sysdeps/s390/multiarch/Makefile
bca718
@@ -11,7 +11,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
bca718
 		   strncmp strncmp-vx strncmp-c \
bca718
 		   strchr strchr-vx strchr-c \
bca718
 		   strchrnul strchrnul-vx strchrnul-c \
bca718
-		   strrchr strrchr-vx strrchr-c
bca718
+		   strrchr strrchr-vx strrchr-c \
bca718
+		   strspn strspn-vx strspn-c
bca718
 endif
bca718
 
bca718
 ifeq ($(subdir),wcsmbs)
bca718
@@ -27,5 +28,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
bca718
 		   wcsncmp wcsncmp-vx wcsncmp-c \
bca718
 		   wcschr wcschr-vx wcschr-c \
bca718
 		   wcschrnul wcschrnul-vx wcschrnul-c \
bca718
-		   wcsrchr wcsrchr-vx wcsrchr-c
bca718
+		   wcsrchr wcsrchr-vx wcsrchr-c \
bca718
+		   wcsspn wcsspn-vx wcsspn-c
bca718
 endif
bca718
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
index ee84d80..cbedf64 100644
bca718
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
@@ -118,6 +118,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bca718
   IFUNC_VX_IMPL (strrchr);
bca718
   IFUNC_VX_IMPL (wcsrchr);
bca718
 
bca718
+  IFUNC_VX_IMPL (strspn);
bca718
+  IFUNC_VX_IMPL (wcsspn);
bca718
+
bca718
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
bca718
 
bca718
   return i;
bca718
diff --git a/sysdeps/s390/multiarch/strspn-c.c b/sysdeps/s390/multiarch/strspn-c.c
bca718
new file mode 100644
bca718
index 0000000..8a7d342
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/strspn-c.c
bca718
@@ -0,0 +1,28 @@
bca718
+/* Default strspn implementation for S/390.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# define STRSPN  __strspn_c
bca718
+# ifdef SHARED
bca718
+#  undef libc_hidden_builtin_def
bca718
+#  define libc_hidden_builtin_def(name)				\
bca718
+     __hidden_ver1 (__strspn_c, __GI_strspn, __strspn_c);
bca718
+# endif /* SHARED */
bca718
+
bca718
+# include <string/strspn.c>
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/strspn-vx.S b/sysdeps/s390/multiarch/strspn-vx.S
bca718
new file mode 100644
bca718
index 0000000..df22347
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/strspn-vx.S
bca718
@@ -0,0 +1,256 @@
bca718
+/* Vector optimized 32/64 bit S/390 version of strspn.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+
bca718
+# include "sysdep.h"
bca718
+# include "asm-syntax.h"
bca718
+
bca718
+	.text
bca718
+
bca718
+/* size_t strspn (const char *s, const char * accept)
bca718
+   The strspn() function calculates the length of the initial segment
bca718
+   of s which consists entirely of characters in accept.
bca718
+
bca718
+   This method checks the length of accept string. If it fits entirely
bca718
+   in one vector register, a fast algorithm is used, which does not need
bca718
+   to check multiple parts of accept-string. Otherwise a slower full
bca718
+   check of accept-string is used.
bca718
+
bca718
+   register overview:
bca718
+   r3:  pointer to start of accept-string
bca718
+   r2:  pointer to start of search-string
bca718
+   r4:  loaded byte count of vl search-string
bca718
+   r0:  found byte index
bca718
+   r1:  current return len of s
bca718
+   v16: search-string
bca718
+   v17: accept-string
bca718
+   v18: temp-vreg
bca718
+
bca718
+   ONLY FOR SLOW:
bca718
+   v19: first accept-string
bca718
+   v20: zero for preparing acc-vector
bca718
+   v21: global mask; 1 indicates a match between
bca718
+	search-string-vreg and any accept-character
bca718
+   v22: current mask; 1 indicates a match between
bca718
+	search-string-vreg and any accept-character in current acc-vreg
bca718
+   v30, v31: for re-/storing registers r6, r8, r9
bca718
+   r5:  current len of accept-string
bca718
+   r6:	zero-index in search-string or 16 if no zero
bca718
+	or min(zero-index, loaded byte count)
bca718
+   r8:	>0, if former accept-string-part contains a zero,
bca718
+	otherwise =0;
bca718
+   r9: loaded byte count of vlbb accept-string
bca718
+*/
bca718
+ENTRY(__strspn_vx)
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+
bca718
+	/*
bca718
+	  Check if accept-string fits in one vreg:
bca718
+	  ----------------------------------------
bca718
+	*/
bca718
+	vlbb	%v17,0(%r3),6	/* Load accept.  */
bca718
+	lcbb	%r4,0(%r3),6
bca718
+	jo	.Lcheck_onbb	/* Special case if accept lays
bca718
+				   on block-boundary.  */
bca718
+.Lcheck_notonbb:
bca718
+	vistrbs	%v17,%v17	/* Fill with zeros after first zero.  */
bca718
+	je	.Lfast		/* Zero found -> accept fits in one vreg.  */
bca718
+	j	.Lslow		/* No zero -> accept exceeds one vreg.  */
bca718
+
bca718
+.Lcheck_onbb:
bca718
+	/* Accept lays on block-boundary.  */
bca718
+	vfenezb	%v18,%v17,%v17	/* Search zero in loaded accept bytes.  */
bca718
+	vlgvb	%r0,%v18,7	/* Get index of zero or 16 if not found.  */
bca718
+	clrjl	%r0,%r4,.Lcheck_notonbb /* Zero index < loaded bytes count ->
bca718
+					   Accept fits in one vreg;
bca718
+					   Fill with zeros and proceed
bca718
+					   with FAST.  */
bca718
+	vl	%v17,0(%r3)	/* Load accept, which exceeds loaded bytes.  */
bca718
+	j	.Lcheck_notonbb /* Check if accept fits in one vreg.  */
bca718
+
bca718
+
bca718
+	/*
bca718
+	  Search s for accept in one vreg
bca718
+	  -------------------------------
bca718
+	*/
bca718
+.Lfast:
bca718
+	/* Complete accept-string is in v17 and remaining bytes are zero.  */
bca718
+
bca718
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
bca718
+	lcbb	%r1,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
bca718
+
bca718
+	vfaezbs	%v16,%v16,%v17,8 /* Find first element in v16
bca718
+				    unequal to any in v17
bca718
+				    or first zero element.  */
bca718
+	vlgvb	%r0,%v16,7	/* Load byte index of found element.  */
bca718
+	/* If found index is within loaded bytes (%r0 < %r1),
bca718
+	   return with found element index (=equal count).  */
bca718
+	clr	%r0,%r1
bca718
+	locgrl	%r2,%r0
bca718
+	blr	%r14
bca718
+
bca718
+	/* Align s to 16 byte.  */
bca718
+	risbgn	%r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
bca718
+	lghi	%r1,16		/* current_len = 16.  */
bca718
+	slr	%r1,%r4		/* Compute bytes to 16bytes boundary.  */
bca718
+
bca718
+.Lfast_loop:
bca718
+	vl	%v16,0(%r1,%r2)	/* Load search-string.  */
bca718
+	vfaezbs	%v16,%v16,%v17,8 /* Find first element in v16
bca718
+				    unequal to any in v17
bca718
+				    or first zero element.  */
bca718
+	jno	.Lfast_loop_found
bca718
+	vl	%v16,16(%r1,%r2)
bca718
+	vfaezbs	%v16,%v16,%v17,8
bca718
+	jno	.Lfast_loop_found16
bca718
+	vl	%v16,32(%r1,%r2)
bca718
+	vfaezbs	%v16,%v16,%v17,8
bca718
+	jno	.Lfast_loop_found32
bca718
+	vl	%v16,48(%r1,%r2)
bca718
+	vfaezbs	%v16,%v16,%v17,8
bca718
+	jno	.Lfast_loop_found48
bca718
+
bca718
+	aghi	%r1,64
bca718
+	j	.Lfast_loop	/* Loop if no element was unequal to accept
bca718
+				   and not zero.  */
bca718
+
bca718
+	/* Found unequal or zero element.  */
bca718
+.Lfast_loop_found48:
bca718
+	aghi	%r1,16
bca718
+.Lfast_loop_found32:
bca718
+	aghi	%r1,16
bca718
+.Lfast_loop_found16:
bca718
+	aghi	%r1,16
bca718
+.Lfast_loop_found:
bca718
+	vlgvb	%r0,%v16,7	/* Load byte index of found element.  */
bca718
+	algrk	%r2,%r1,%r0	/* And add it to current len.  */
bca718
+	br	%r14
bca718
+
bca718
+
bca718
+	/*
bca718
+	  Search s for accept in multiple vregs
bca718
+	  -------------------------------------
bca718
+	*/
bca718
+.Lslow:
bca718
+	/* Save registers.  */
bca718
+	vlvgg	%v30,%r6,0
bca718
+	vlvgp	%v31,%r8,%r9
bca718
+	lghi	%r1,0		/* current_len = 0.  */
bca718
+
bca718
+	/* Accept in v17 without zero.  */
bca718
+	vlr	%v19,%v17	/* Save first acc-part for a fast reload.  */
bca718
+	vzero	%v20		/* Zero for preparing acc-vector.  */
bca718
+
bca718
+	/* Align s to 16 byte.  */
bca718
+	risbg	%r0,%r2,60,128+63,0 /* Test if s is aligned and
bca718
+				     %r0 = bits 60-63 'and' 15  */
bca718
+	je	.Lslow_loop_str /* If s is aligned, loop aligned */
bca718
+	lghi	%r4,15
bca718
+	slr	%r4,%r0		/* Compute highest index to load (15-x).  */
bca718
+	vll	%v16,%r4,0(%r2) /* Load up to 16byte boundary (vll needs
bca718
+				   highest index, left bytes are 0).  */
bca718
+	ahi	%r4,1		/* Work with loaded byte count.  */
bca718
+	vzero	%v21		/* Zero out global mask.  */
bca718
+	lghi	%r5,0		/* Set current len of accept-string to zero.  */
bca718
+	vfenezb	%v18,%v16,%v16	/* Find zero in current string-part.  */
bca718
+	lghi	%r8,0		/* There is no zero in first accept-part.  */
bca718
+	vlgvb	%r6,%v18,7	/* Load byte index of zero or 16
bca718
+				   if there is no zero.  */
bca718
+	clr	%r4,%r6		/* cc==1 if loaded byte count < zero-index.  */
bca718
+	locrl	%r6,%r4		/* Load on cc==1.  */
bca718
+	j	.Lslow_loop_acc
bca718
+
bca718
+	/* Process s in 16byte aligned loop.  */
bca718
+.Lslow_next_str:
bca718
+	vlr	%v17,%v19	/* Load first part of accept (no zero).  */
bca718
+	algfr	%r1,%r4		/* Add loaded byte count to current len.  */
bca718
+.Lslow_loop_str:
bca718
+	vl	%v16,0(%r1,%r2)	/* Load search-string.  */
bca718
+	lghi	%r4,16		/* Loaded byte count is 16.  */
bca718
+	vzero	%v21		/* Zero out global mask.  */
bca718
+	lghi	%r5,0		/* Set current len of accept-string to zero.  */
bca718
+	vfenezb	%v18,%v16,%v16	/* Find zero in current string-part.  */
bca718
+	lghi	%r8,0		/* There is no zero in first accept-part.  */
bca718
+	vlgvb	%r6,%v18,7	/* Load byte index of zero or 16 if no zero.  */
bca718
+
bca718
+.Lslow_loop_acc:
bca718
+	vfaeb	%v22,%v16,%v17,4 /* Create matching-mask (1 in mask ->
bca718
+				    character matches any accepted character in
bca718
+				    this accept-string-part) IN=0, RT=1.  */
bca718
+	vo	%v21,%v21,%v22	/* global-mask = global- | matching-mask.  */
bca718
+	vfenezb	%v18,%v21,%v21	/* Find first zero in global-mask.  */
bca718
+	vlgvb	%r0,%v18,7	/* Get first found zero-index
bca718
+				   (= first mismatch).  */
bca718
+	clrjl	%r0,%r6,.Lslow_next_acc /* Mismatch-index < min(lbc,zero-index)
bca718
+					    -> Process this string-part
bca718
+					       with next acc-part.  */
bca718
+	clrjhe	%r0,%r4,.Lslow_next_str /* Found-index >= loaded byte count
bca718
+					   -> All loaded bytes are matching
bca718
+					      any accept-character
bca718
+					      and are not zero.  */
bca718
+	/* All bytes are matching any characters in accept-string
bca718
+	   and search-string is fully processed (found-index == zero-index)  */
bca718
+.Lslow_add_lbc_end:
bca718
+	algrk	%r2,%r1,%r0	/* Add matching characters to current_len.  */
bca718
+	/* Restore registers.  */
bca718
+	vlgvg	%r6,%v30,0
bca718
+	vlgvg	%r8,%v31,0
bca718
+	vlgvg	%r9,%v31,1
bca718
+	br	%r14
bca718
+
bca718
+
bca718
+
bca718
+.Lslow_next_acc:
bca718
+	clijh	%r8,0,.Lslow_add_lbc_end /* There was a zero in last acc-part
bca718
+					     -> Add found index to current len
bca718
+						and end.  */
bca718
+	vlbb	%v17,16(%r5,%r3),6 /* Load next accept part.  */
bca718
+	aghi	%r5,16		/* Add current_len of accept-string.  */
bca718
+	lcbb	%r9,0(%r5,%r3),6 /* Get loaded byte count of accept-string.  */
bca718
+	jo	.Lslow_next_acc_onbb /* Jump away if accept-string is
bca718
+					 on block-boundary.  */
bca718
+.Lslow_next_acc_notonbb:
bca718
+	vistrbs	%v17,%v17	/* Fill with zeros after first zero.  */
bca718
+	jo	.Lslow_loop_acc /* No zero found -> no preparation needed.  */
bca718
+
bca718
+.Lslow_next_acc_prepare_zero:
bca718
+	/* Zero in accept-part: fill zeros with first-accept-character.  */
bca718
+	vlgvb	%r8,%v17,0	/* Load first element of acc-part.  */
bca718
+	clije	%r8,0,.Lslow_add_lbc_end /* End if zero is first character
bca718
+					     in this part of accept-string.  */
bca718
+	/* r8>0 -> zero found in this acc-part.  */
bca718
+	vrepb	%v18,%v17,0	/* Replicate first char accross all chars.  */
bca718
+	vceqb	%v22,%v20,%v17	/* Create a mask (v22) of null chars
bca718
+				   by comparing with 0 (v20).  */
bca718
+	vsel	%v17,%v18,%v17,%v22 /* Replace null chars with first char.  */
bca718
+	j	.Lslow_loop_acc /* Accept part is prepared -> process.  */
bca718
+
bca718
+.Lslow_next_acc_onbb:
bca718
+	vfenezb	%v18,%v17,%v17	/* Find zero in loaded bytes of accept part.  */
bca718
+	vlgvb	%r8,%v18,7	/* Load byte index of zero.  */
bca718
+	clrjl	%r8,%r9,.Lslow_next_acc_notonbb /* Found a zero in loaded bytes
bca718
+						    -> Prepare vr.  */
bca718
+	vl	%v17,0(%r5,%r3)	/* Load over boundary ...  */
bca718
+	lghi	%r8,0		/* r8=0 -> no zero in this part of acc,
bca718
+				   Check for zero is in jump-target.  */
bca718
+	j	.Lslow_next_acc_notonbb /* ... and search for zero in
bca718
+					    fully loaded vreg again.  */
bca718
+END(__strspn_vx)
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/strspn.c b/sysdeps/s390/multiarch/strspn.c
bca718
new file mode 100644
bca718
index 0000000..48dd77b
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/strspn.c
bca718
@@ -0,0 +1,27 @@
bca718
+/* Multiple versions of strspn.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# include <string.h>
bca718
+# include <ifunc-resolve.h>
bca718
+
bca718
+s390_vx_libc_ifunc2 (__strspn, strspn)
bca718
+
bca718
+#else
bca718
+# include <string/strspn.c>
bca718
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
bca718
diff --git a/sysdeps/s390/multiarch/wcsspn-c.c b/sysdeps/s390/multiarch/wcsspn-c.c
bca718
new file mode 100644
bca718
index 0000000..93af16c
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcsspn-c.c
bca718
@@ -0,0 +1,31 @@
bca718
+/* Default wcsspn implementation for S/390.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# define WCSSPN  __wcsspn_c
bca718
+
bca718
+# include <wchar.h>
bca718
+extern __typeof (wcsspn) __wcsspn_c;
bca718
+# ifdef SHARED
bca718
+#  undef libc_hidden_def
bca718
+#  define libc_hidden_def(name)				\
bca718
+  __hidden_ver1 (__wcsspn_c, __GI_wcsspn, __wcsspn_c);
bca718
+# endif /* SHARED */
bca718
+
bca718
+# include <wcsmbs/wcsspn.c>
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/wcsspn-vx.S b/sysdeps/s390/multiarch/wcsspn-vx.S
bca718
new file mode 100644
bca718
index 0000000..4ed8e84
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcsspn-vx.S
bca718
@@ -0,0 +1,270 @@
bca718
+/* Vector optimized 32/64 bit S/390 version of wcsspn.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+
bca718
+# include "sysdep.h"
bca718
+# include "asm-syntax.h"
bca718
+
bca718
+	.text
bca718
+
bca718
+/* size_t wcsspn (const wchar_t *s, const wchar_t * accept)
bca718
+   The wcsspn() function calculates the length of the initial segment
bca718
+   of s which consists entirely of characters in accept.
bca718
+
bca718
+   This method checks the length of accept string. If it fits entirely
bca718
+   in one vector register, a fast algorithm is used, which does not need
bca718
+   to check multiple parts of accept-string. Otherwise a slower full
bca718
+   check of accept-string is used.
bca718
+
bca718
+   register overview:
bca718
+   r3:  pointer to start of accept-string
bca718
+   r2:  pointer to start of search-string
bca718
+   r4:  loaded byte count of vl search-string
bca718
+   r0:  found byte index
bca718
+   r1:  current return len of s
bca718
+   v16: search-string
bca718
+   v17: accept-string
bca718
+   v18: temp-vreg
bca718
+
bca718
+   ONLY FOR SLOW:
bca718
+   v19: first accept-string
bca718
+   v20: zero for preparing acc-vector
bca718
+   v21: global mask; 1 indicates a match between
bca718
+	search-string-vreg and any accept-character
bca718
+   v22: current mask; 1 indicates a match between
bca718
+	search-string-vreg and any accept-character in current acc-vreg
bca718
+   v30, v31: for re-/storing registers r6, r8, r9
bca718
+   r5:  current len of accept-string
bca718
+   r6:	zero-index in search-string or 16 if no zero
bca718
+	or min(zero-index, loaded byte count)
bca718
+   r8:	>0, if former accept-string-part contains a zero,
bca718
+	otherwise =0;
bca718
+   r9: loaded byte count of vlbb accept-string
bca718
+*/
bca718
+ENTRY(__wcsspn_vx)
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+
bca718
+	tmll	%r2,3		/* Test if s is 4-byte aligned?  */
bca718
+	jne	.Lfallback	/* And use common-code variant if not.  */
bca718
+
bca718
+	/*
bca718
+	  Check if accept-string fits in one vreg:
bca718
+	  ----------------------------------------
bca718
+	*/
bca718
+	vlbb	%v17,0(%r3),6	/* Load accept.  */
bca718
+	lcbb	%r4,0(%r3),6
bca718
+	jo	.Lcheck_onbb	/* Special case if accept lays
bca718
+				   on block-boundary.  */
bca718
+.Lcheck_notonbb:
bca718
+	vistrfs	%v17,%v17	/* Fill with zeros after first zero.  */
bca718
+	je	.Lfast		/* Zero found -> accept fits in one vreg.  */
bca718
+	j	.Lslow		/* No zero -> accept exceeds one vreg.  */
bca718
+
bca718
+.Lcheck_onbb:
bca718
+	/* Accept lays on block-boundary.  */
bca718
+	nill	%r4,65532	/* Recognize only fully loaded characters.  */
bca718
+	je	.Lcheck_onbb2	/* Reload vr if no full wchar_t.  */
bca718
+	vfenezf	%v18,%v17,%v17	/* Search zero in loaded accept bytes.  */
bca718
+	vlgvb	%r0,%v18,7	/* Get index of zero or 16 if not found.  */
bca718
+	clrjl	%r0,%r4,.Lcheck_notonbb /* Zero index < loaded bytes count ->
bca718
+					    Accept fits in one vreg;
bca718
+					    Fill with zeros and proceed
bca718
+					    with FAST.  */
bca718
+.Lcheck_onbb2:
bca718
+	vl	%v17,0(%r3)	/* Load accept, which exceeds loaded bytes.  */
bca718
+	j	.Lcheck_notonbb /* Check if accept fits in one vreg.  */
bca718
+
bca718
+
bca718
+	/*
bca718
+	  Search s for accept in one vreg
bca718
+	  -------------------------------
bca718
+	*/
bca718
+.Lfast:
bca718
+	/* Complete accept-string in v17 and remaining bytes are zero.  */
bca718
+
bca718
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
bca718
+	lcbb	%r1,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
bca718
+
bca718
+	vfaezfs	%v16,%v16,%v17,8 /* Find first element in v16
bca718
+				    unequal to any in v17
bca718
+				    or first zero element.  */
bca718
+
bca718
+	vlgvb	%r0,%v16,7	/* Load byte index of found element.  */
bca718
+	/* If found index is within loaded bytes (%r0 < %r1),
bca718
+	   return with found element index (=equal count).  */
bca718
+	clr	%r0,%r1
bca718
+	srlg	%r0,%r0,2	/* Convert byte-count to character-count.  */
bca718
+	locgrl	%r2,%r0
bca718
+	blr	%r14
bca718
+
bca718
+	/* Align s to 16 byte.  */
bca718
+	risbgn	%r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
bca718
+	lghi	%r1,16		/* current_len = 16.  */
bca718
+	slr	%r1,%r4		/* Compute bytes to 16bytes boundary.  */
bca718
+
bca718
+.Lfast_loop:
bca718
+	vl	%v16,0(%r1,%r2)	/* Load search-string.  */
bca718
+	vfaezfs	%v16,%v16,%v17,8 /* Find first element in v16
bca718
+				    unequal to any in v17
bca718
+				    or first zero element.  */
bca718
+	jno	.Lfast_loop_found
bca718
+	vl	%v16,16(%r1,%r2)
bca718
+	vfaezfs	%v16,%v16,%v17,8
bca718
+	jno	.Lfast_loop_found16
bca718
+	vl	%v16,32(%r1,%r2)
bca718
+	vfaezfs	%v16,%v16,%v17,8
bca718
+	jno	.Lfast_loop_found32
bca718
+	vl	%v16,48(%r1,%r2)
bca718
+	vfaezfs	%v16,%v16,%v17,8
bca718
+	jno	.Lfast_loop_found48
bca718
+
bca718
+	aghi	%r1,64
bca718
+	j	.Lfast_loop	/* Loop if no element was unequal to accept
bca718
+				   and not zero.  */
bca718
+
bca718
+	/* Found unequal or zero element.  */
bca718
+.Lfast_loop_found48:
bca718
+	aghi	%r1,16
bca718
+.Lfast_loop_found32:
bca718
+	aghi	%r1,16
bca718
+.Lfast_loop_found16:
bca718
+	aghi	%r1,16
bca718
+.Lfast_loop_found:
bca718
+	vlgvb	%r0,%v16,7	/* Load byte index of found element.  */
bca718
+	algrk	%r2,%r1,%r0	/* And add it to current len.  */
bca718
+	srlg	%r2,%r2,2	/* Convert byte-count to character-count.  */
bca718
+	br	%r14
bca718
+
bca718
+
bca718
+	/*
bca718
+	  Search s for accept in multiple vregs
bca718
+	  -------------------------------------
bca718
+	*/
bca718
+.Lslow:
bca718
+	/* Save registers.  */
bca718
+	vlvgg	%v30,%r6,0
bca718
+	vlvgp	%v31,%r8,%r9
bca718
+	lghi	%r1,0		/* Zero out current len.  */
bca718
+
bca718
+	/* accept in v17 without zero.  */
bca718
+	vlr	%v19,%v17	/* Save first acc-part for a fast reload.  */
bca718
+	vzero	%v20		/* Zero for preparing acc-vector.  */
bca718
+
bca718
+	/* Align s to 16 byte.  */
bca718
+	risbg	%r0,%r2,60,128+63,0 /* Test if s is aligned and
bca718
+				     %r0 = bits 60-63 'and' 15.  */
bca718
+	je	.Lslow_loop_str /* If s is aligned, loop aligned */
bca718
+	lghi	%r4,15
bca718
+	slr	%r4,%r0		/* Compute highest index to load (15-x).  */
bca718
+	vll	%v16,%r4,0(%r2) /* Load up to 16byte boundary (vll needs
bca718
+				   highest index, remaining bytes are 0).  */
bca718
+	aghi	%r4,1		/* Work with loaded byte count.  */
bca718
+	vzero	%v21		/* Zero out global mask.  */
bca718
+	lghi	%r5,0		/* Set current len of accept-string to zero.  */
bca718
+	vfenezf	%v18,%v16,%v16	/* Find zero in current string-part.  */
bca718
+	lghi	%r8,0		/* There is no zero in first accept-part.  */
bca718
+	vlgvb	%r6,%v18,7	/* Load byte index of zero or 16
bca718
+				   if there is no zero.  */
bca718
+	clr	%r4,%r6		/* cc==1 if loaded byte count < zero-index.  */
bca718
+	locrl	%r6,%r4		/* Load on cc==1.  */
bca718
+	j	.Lslow_loop_acc
bca718
+
bca718
+	/* Process s in 16byte aligned loop.  */
bca718
+.Lslow_next_str:
bca718
+	vlr	%v17,%v19	/* Load first part of accept (no zero).  */
bca718
+	algfr	%r1,%r4		/* Add loaded byte count to current len.  */
bca718
+.Lslow_loop_str:
bca718
+	vl	%v16,0(%r1,%r2)	/* Load search-string.  */
bca718
+	lghi	%r4,16		/* Loaded byte count is 16.  */
bca718
+	vzero	%v21		/* Zero out global mask.  */
bca718
+	lghi	%r5,0		/* Set current len of accept-string to zero.  */
bca718
+	vfenezf	%v18,%v16,%v16	/* Find zero in current string-part.  */
bca718
+	lghi	%r8,0		/* There is no zero in first accept-part.  */
bca718
+	vlgvb	%r6,%v18,7	/* Load byte index of zero or 16 if no zero.  */
bca718
+
bca718
+.Lslow_loop_acc:
bca718
+	vfaef	%v22,%v16,%v17,4 /* Create matching-mask (1 in mask ->
bca718
+				    character matches any accepted character in
bca718
+				    this accept-string-part) IN=0, RT=1.  */
bca718
+	vo	%v21,%v21,%v22	/* global-mask = global- | matching-mask.  */
bca718
+	vfenezf	%v18,%v21,%v21	/* Find first zero in global-mask.  */
bca718
+	vlgvb	%r0,%v18,7	/* Get first found zero-index
bca718
+				   (= first mismatch).  */
bca718
+	clrjl	%r0,%r6,.Lslow_next_acc /* Mismatch-index < min(lbc,zero-index)
bca718
+					   -> Process this string-part
bca718
+					      with next acc-part.  */
bca718
+	clrjhe	%r0,%r4,.Lslow_next_str /* Found-index >= loaded byte count
bca718
+					   -> All loaded bytes are matching
bca718
+					      any accept-character
bca718
+					      and are not zero.  */
bca718
+	/* All bytes are matching any characters in accept-string
bca718
+	   and search-string is fully processed (found-index == zero-index).  */
bca718
+.Lslow_add_lbc_end:
bca718
+	algrk	%r2,%r1,%r0	/* Add matching characters to current len.  */
bca718
+	srlg	%r2,%r2,2	/* Convert byte-count to character-count.  */
bca718
+	/* Restore registers.  */
bca718
+	vlgvg	%r6,%v30,0
bca718
+	vlgvg	%r8,%v31,0
bca718
+	vlgvg	%r9,%v31,1
bca718
+	br	%r14
bca718
+
bca718
+.Lslow_next_acc:
bca718
+	clijh	%r8,0,.Lslow_add_lbc_end /* There was a zero in last acc-part
bca718
+					    -> Add found index to current len
bca718
+					       and end.  */
bca718
+	vlbb	%v17,16(%r5,%r3),6 /* Load next accept part.  */
bca718
+	aghi	%r5,16		/* Increment current len of accept-string.  */
bca718
+	lcbb	%r9,0(%r5,%r3),6 /* Get loaded byte count of accept-string.  */
bca718
+	jo	.Lslow_next_acc_onbb /* Jump away if accept-string is
bca718
+					on block-boundary.  */
bca718
+.Lslow_next_acc_notonbb:
bca718
+	vistrfs	%v17,%v17	/* Fill with zeros after first zero.  */
bca718
+	jo	.Lslow_loop_acc /* No zero found -> no preparation needed.  */
bca718
+
bca718
+.Lslow_next_acc_prepare_zero:
bca718
+	/* Zero in accept-part: fill zeros with first-accept-character.  */
bca718
+	vlgvf	%r8,%v17,0	/* Load first element of acc-part.  */
bca718
+	clije	%r8,0,.Lslow_add_lbc_end /* End if zero is first character
bca718
+					     in this part of accept-string.  */
bca718
+	/* r8>0 -> zero found in this acc-part.  */
bca718
+	vrepf	%v18,%v17,0	/* Replicate first char accross all chars.  */
bca718
+	vceqf	%v22,%v20,%v17	/* Create a mask (v22) of null chars
bca718
+				   by comparing with 0 (v20).  */
bca718
+	vsel	%v17,%v18,%v17,%v22 /* Replace null chars with first char.  */
bca718
+	j	.Lslow_loop_acc /* Accept part is prepared -> process.  */
bca718
+
bca718
+.Lslow_next_acc_onbb:
bca718
+	nill	%r9,65532	/* Recognize only fully loaded characters.  */
bca718
+	je	.Lslow_next_acc_onbb2 /* Reload vr, if we loaded no full
bca718
+					  wchar_t.  */
bca718
+	vfenezf	%v18,%v17,%v17	/* Find zero in loaded bytes of accept part.  */
bca718
+	vlgvb	%r8,%v18,7	/* Load byte index of zero.  */
bca718
+	clrjl	%r8,%r9,.Lslow_next_acc_notonbb /* Found a zero in loaded bytes
bca718
+						   -> Prepare vreg.  */
bca718
+.Lslow_next_acc_onbb2:
bca718
+	vl	%v17,0(%r5,%r3)	/* Load over boundary ...  */
bca718
+	lghi	%r8,0		/* r8=0 -> no zero in this part of acc,
bca718
+				   check for zero is in jump-target.  */
bca718
+	j	.Lslow_next_acc_notonbb /* ... and search for zero in
bca718
+					   fully loaded vreg again.  */
bca718
+.Lfallback:
bca718
+	jg	__wcsspn_c
bca718
+END(__wcsspn_vx)
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/wcsspn.c b/sysdeps/s390/multiarch/wcsspn.c
bca718
new file mode 100644
bca718
index 0000000..3b3041c
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcsspn.c
bca718
@@ -0,0 +1,27 @@
bca718
+/* Multiple versions of wcsspn.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# include <wchar.h>
bca718
+# include <ifunc-resolve.h>
bca718
+
bca718
+s390_vx_libc_ifunc2 (__wcsspn, wcsspn)
bca718
+
bca718
+#else
bca718
+# include <wcsmbs/wcsspn.c>
bca718
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
bca718
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
bca718
index de3635d..843a23c 100644
bca718
--- a/wcsmbs/Makefile
bca718
+++ b/wcsmbs/Makefile
bca718
@@ -42,7 +42,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
bca718
 	    mbrtoc16 c16rtomb
bca718
 
bca718
 strop-tests :=  wcscmp wcsncmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
bca718
-		wcpcpy wcsncpy wcpncpy wcscat wcsncat wcschrnul
bca718
+		wcpcpy wcsncpy wcpncpy wcscat wcsncat wcschrnul wcsspn
bca718
 tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
bca718
 	 tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \
bca718
 	 tst-c16c32-1 wcsatcliff $(addprefix test-,$(strop-tests))
bca718
diff --git a/wcsmbs/test-wcsspn-ifunc.c b/wcsmbs/test-wcsspn-ifunc.c
bca718
new file mode 100644
bca718
index 0000000..73f288f
bca718
--- /dev/null
bca718
+++ b/wcsmbs/test-wcsspn-ifunc.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Test and measure IFUNC implementations of wcsspn function.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#define TEST_IFUNC 1
bca718
+#include "test-wcsspn.c"
bca718
diff --git a/wcsmbs/test-wcsspn.c b/wcsmbs/test-wcsspn.c
bca718
new file mode 100644
bca718
index 0000000..171043c
bca718
--- /dev/null
bca718
+++ b/wcsmbs/test-wcsspn.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Test wcsspn functions.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#define WIDE 1
bca718
+#include "../string/test-strspn.c"
bca718
diff --git a/wcsmbs/wcsspn.c b/wcsmbs/wcsspn.c
bca718
index dad72b4..3e84726 100644
bca718
--- a/wcsmbs/wcsspn.c
bca718
+++ b/wcsmbs/wcsspn.c
bca718
@@ -18,6 +18,9 @@
bca718
 
bca718
 #include <wchar.h>
bca718
 
bca718
+#ifdef WCSSPN
bca718
+# define wcsspn WCSSPN
bca718
+#endif
bca718
 
bca718
 /* Return the length of the maximum initial segment
bca718
    of WCS which contains only wide-characters in ACCEPT.  */
bca718
-- 
bca718
2.3.0
bca718