00db10
From f0954299ecdccf6a70cf904b8f499d15a5af3928 Mon Sep 17 00:00:00 2001
00db10
From: Stefan Liebler <stli@linux.vnet.ibm.com>
00db10
Date: Thu, 8 Oct 2015 13:22:47 +0200
00db10
Subject: [PATCH 28/30] S390: Optimize wmemset.
00db10
00db10
upstream-commit-id: 2e9e166761fed5dfaa53480412bef0656f1b5306
00db10
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00078.html
00db10
00db10
This patch provides optimized version of wmemset with the z13 vector
00db10
instructions.
00db10
00db10
ChangeLog:
00db10
00db10
	* sysdeps/s390/multiarch/wmemset-c.c: New File.
00db10
	* sysdeps/s390/multiarch/wmemset-vx.S: Likewise.
00db10
	* sysdeps/s390/multiarch/wmemset.c: Likewise.
00db10
	* sysdeps/s390/multiarch/Makefile
00db10
	(sysdep_routines): Add wmemset functions.
00db10
	* sysdeps/s390/multiarch/ifunc-impl-list-common.c
00db10
	(__libc_ifunc_impl_list_common): Add ifunc test for wmemset.
00db10
	* wcsmbs/wmemset.c: Use WMEMSET if defined.
00db10
	* string/test-memset.c: Add wmemset support.
00db10
	* wcsmbs/test-wmemset.c: New File.
00db10
	* wcsmbs/Makefile (strop-tests): Add wmemset.
00db10
	* benchtests/bench-memset.c: Add wmemset support.
00db10
	* benchtests/bench-wmemset.c: New File.
00db10
	* benchtests/Makefile (wcsmbs-bench): Add wmemset.
00db10
---
00db10
 benchtests/Makefile                      |   2 +-
00db10
 benchtests/bench-memset.c                |  63 +++++++++-----
00db10
 benchtests/bench-wmemset.c               |  20 +++++
00db10
 string/test-memset.c                     |  88 ++++++++++++-------
00db10
 sysdeps/s390/multiarch/Makefile          |   3 +-
00db10
 sysdeps/s390/multiarch/ifunc-impl-list.c |   2 +
00db10
 sysdeps/s390/multiarch/wmemset-c.c       |  31 +++++++
00db10
 sysdeps/s390/multiarch/wmemset-vx.S      | 142 +++++++++++++++++++++++++++++++
00db10
 sysdeps/s390/multiarch/wmemset.c         |  27 ++++++
00db10
 wcsmbs/Makefile                          |   2 +-
00db10
 wcsmbs/test-wmemset-ifunc.c              |  20 +++++
00db10
 wcsmbs/test-wmemset.c                    |  20 +++++
00db10
 wcsmbs/wmemset.c                         |   3 +
00db10
 13 files changed, 368 insertions(+), 55 deletions(-)
00db10
 create mode 100644 benchtests/bench-wmemset.c
00db10
 create mode 100644 sysdeps/s390/multiarch/wmemset-c.c
00db10
 create mode 100644 sysdeps/s390/multiarch/wmemset-vx.S
00db10
 create mode 100644 sysdeps/s390/multiarch/wmemset.c
00db10
 create mode 100644 wcsmbs/test-wmemset-ifunc.c
00db10
 create mode 100644 wcsmbs/test-wmemset.c
00db10
00db10
diff --git a/benchtests/Makefile b/benchtests/Makefile
00db10
index b4b3127..b5edfdd 100644
00db10
--- a/benchtests/Makefile
00db10
+++ b/benchtests/Makefile
00db10
@@ -40,7 +40,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
00db10
 		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
00db10
 wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \
00db10
 		wcsncmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \
00db10
-		wmemchr
00db10
+		wmemchr wmemset
00db10
 string-bench-all := $(string-bench) ${wcsmbs-bench}
00db10
 
00db10
 stdlib-bench := strtod
00db10
diff --git a/benchtests/bench-memset.c b/benchtests/bench-memset.c
00db10
index 9786ce7..66c3c45 100644
00db10
--- a/benchtests/bench-memset.c
00db10
+++ b/benchtests/bench-memset.c
00db10
@@ -20,12 +20,29 @@
00db10
 #ifdef TEST_BZERO
00db10
 # define TEST_NAME "bzero"
00db10
 #else
00db10
-# define TEST_NAME "memset"
00db10
-#endif
00db10
+# ifndef WIDE
00db10
+#  define TEST_NAME "memset"
00db10
+# else
00db10
+#  define TEST_NAME "wmemset"
00db10
+# endif /* WIDE */
00db10
+#endif /* !TEST_BZERO */
00db10
 #define MIN_PAGE_SIZE 131072
00db10
 #include "bench-string.h"
00db10
 
00db10
-char *simple_memset (char *, int, size_t);
00db10
+#ifndef WIDE
00db10
+# define MEMSET memset
00db10
+# define CHAR char
00db10
+# define SIMPLE_MEMSET simple_memset
00db10
+# define MEMCMP memcmp
00db10
+#else
00db10
+# include <wchar.h>
00db10
+# define MEMSET wmemset
00db10
+# define CHAR wchar_t
00db10
+# define SIMPLE_MEMSET simple_wmemset
00db10
+# define MEMCMP wmemcmp
00db10
+#endif /* WIDE */
00db10
+
00db10
+CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
00db10
 
00db10
 #ifdef TEST_BZERO
00db10
 typedef void (*proto_t) (char *, size_t);
00db10
@@ -39,7 +56,7 @@ IMPL (bzero, 1)
00db10
 void
00db10
 simple_bzero (char *s, size_t n)
00db10
 {
00db10
-  simple_memset (s, 0, n);
00db10
+  SIMPLE_MEMSET (s, 0, n);
00db10
 }
00db10
 
00db10
 void
00db10
@@ -48,46 +65,50 @@ builtin_bzero (char *s, size_t n)
00db10
   __builtin_bzero (s, n);
00db10
 }
00db10
 #else
00db10
-typedef char *(*proto_t) (char *, int, size_t);
00db10
-char *builtin_memset (char *, int, size_t);
00db10
+typedef CHAR *(*proto_t) (CHAR *, int, size_t);
00db10
 
00db10
-IMPL (simple_memset, 0)
00db10
+IMPL (SIMPLE_MEMSET, 0)
00db10
+# ifndef WIDE
00db10
+char *builtin_memset (char *, int, size_t);
00db10
 IMPL (builtin_memset, 0)
00db10
-IMPL (memset, 1)
00db10
+# endif /* !WIDE */
00db10
+IMPL (MEMSET, 1)
00db10
 
00db10
+# ifndef WIDE
00db10
 char *
00db10
 builtin_memset (char *s, int c, size_t n)
00db10
 {
00db10
   return __builtin_memset (s, c, n);
00db10
 }
00db10
-#endif
00db10
+# endif /* !WIDE */
00db10
+#endif /* !TEST_BZERO */
00db10
 
00db10
-char *
00db10
+CHAR *
00db10
 inhibit_loop_to_libcall
00db10
-simple_memset (char *s, int c, size_t n)
00db10
+SIMPLE_MEMSET (CHAR *s, int c, size_t n)
00db10
 {
00db10
-  char *r = s, *end = s + n;
00db10
+  CHAR *r = s, *end = s + n;
00db10
   while (r < end)
00db10
     *r++ = c;
00db10
   return s;
00db10
 }
00db10
 
00db10
 static void
00db10
-do_one_test (impl_t *impl, char *s, int c __attribute ((unused)), size_t n)
00db10
+do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n)
00db10
 {
00db10
   size_t i, iters = INNER_LOOP_ITERS;
00db10
   timing_t start, stop, cur;
00db10
-  char tstbuf[n];
00db10
+  CHAR tstbuf[n];
00db10
 #ifdef TEST_BZERO
00db10
   simple_bzero (tstbuf, n);
00db10
   CALL (impl, s, n);
00db10
   if (memcmp (s, tstbuf, n) != 0)
00db10
 #else
00db10
-  char *res = CALL (impl, s, c, n);
00db10
+  CHAR *res = CALL (impl, s, c, n);
00db10
   if (res != s
00db10
-      || simple_memset (tstbuf, c, n) != tstbuf
00db10
-      || memcmp (s, tstbuf, n) != 0)
00db10
-#endif
00db10
+      || SIMPLE_MEMSET (tstbuf, c, n) != tstbuf
00db10
+      || MEMCMP (s, tstbuf, n) != 0)
00db10
+#endif /* !TEST_BZERO */
00db10
     {
00db10
       error (0, 0, "Wrong result in function %s", impl->name);
00db10
       ret = 1;
00db10
@@ -101,7 +122,7 @@ do_one_test (impl_t *impl, char *s, int c __attribute ((unused)), size_t n)
00db10
       CALL (impl, s, n);
00db10
 #else
00db10
       CALL (impl, s, c, n);
00db10
-#endif
00db10
+#endif /* !TEST_BZERO */
00db10
     }
00db10
   TIMING_NOW (stop);
00db10
 
00db10
@@ -114,13 +135,13 @@ static void
00db10
 do_test (size_t align, int c, size_t len)
00db10
 {
00db10
   align &= 7;
00db10
-  if (align + len > page_size)
00db10
+  if ((align + len) * sizeof (CHAR) > page_size)
00db10
     return;
00db10
 
00db10
   printf ("Length %4zd, alignment %2zd, c %2d:", len, align, c);
00db10
 
00db10
   FOR_EACH_IMPL (impl, 0)
00db10
-    do_one_test (impl, (char *) buf1 + align, c, len);
00db10
+    do_one_test (impl, (CHAR *) (buf1) + align, c, len);
00db10
 
00db10
   putchar ('\n');
00db10
 }
00db10
diff --git a/benchtests/bench-wmemset.c b/benchtests/bench-wmemset.c
00db10
new file mode 100644
00db10
index 0000000..540829c
00db10
--- /dev/null
00db10
+++ b/benchtests/bench-wmemset.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Measure wmemset functions.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#define WIDE 1
00db10
+#include "bench-memset.c"
00db10
diff --git a/string/test-memset.c b/string/test-memset.c
00db10
index e556a88..99fc282 100644
00db10
--- a/string/test-memset.c
00db10
+++ b/string/test-memset.c
00db10
@@ -21,12 +21,33 @@
00db10
 #ifdef TEST_BZERO
00db10
 # define TEST_NAME "bzero"
00db10
 #else
00db10
-# define TEST_NAME "memset"
00db10
-#endif
00db10
+# ifndef WIDE
00db10
+#  define TEST_NAME "memset"
00db10
+# else
00db10
+#  define TEST_NAME "wmemset"
00db10
+# endif /* WIDE */
00db10
+#endif /* !TEST_BZERO */
00db10
 #define MIN_PAGE_SIZE 131072
00db10
 #include "test-string.h"
00db10
 
00db10
-char *simple_memset (char *, int, size_t);
00db10
+#ifndef WIDE
00db10
+# define MEMSET memset
00db10
+# define CHAR char
00db10
+# define UCHAR unsigned char
00db10
+# define SIMPLE_MEMSET simple_memset
00db10
+# define MEMCMP memcmp
00db10
+# define BIG_CHAR CHAR_MAX
00db10
+#else
00db10
+# include <wchar.h>
00db10
+# define MEMSET wmemset
00db10
+# define CHAR wchar_t
00db10
+# define UCHAR wchar_t
00db10
+# define SIMPLE_MEMSET simple_wmemset
00db10
+# define MEMCMP wmemcmp
00db10
+# define BIG_CHAR WCHAR_MAX
00db10
+#endif /* WIDE */
00db10
+
00db10
+CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
00db10
 
00db10
 #ifdef TEST_BZERO
00db10
 typedef void (*proto_t) (char *, size_t);
00db10
@@ -40,7 +61,7 @@ IMPL (bzero, 1)
00db10
 void
00db10
 simple_bzero (char *s, size_t n)
00db10
 {
00db10
-  simple_memset (s, 0, n);
00db10
+  SIMPLE_MEMSET (s, 0, n);
00db10
 }
00db10
 
00db10
 void
00db10
@@ -49,44 +70,48 @@ builtin_bzero (char *s, size_t n)
00db10
   __builtin_bzero (s, n);
00db10
 }
00db10
 #else
00db10
-typedef char *(*proto_t) (char *, int, size_t);
00db10
-char *builtin_memset (char *, int, size_t);
00db10
+typedef CHAR *(*proto_t) (CHAR *, int, size_t);
00db10
 
00db10
-IMPL (simple_memset, 0)
00db10
+IMPL (SIMPLE_MEMSET, 0)
00db10
+# ifndef WIDE
00db10
+char *builtin_memset (char *, int, size_t);
00db10
 IMPL (builtin_memset, 0)
00db10
-IMPL (memset, 1)
00db10
+# endif /* !WIDE */
00db10
+IMPL (MEMSET, 1)
00db10
 
00db10
+# ifndef WIDE
00db10
 char *
00db10
 builtin_memset (char *s, int c, size_t n)
00db10
 {
00db10
   return __builtin_memset (s, c, n);
00db10
 }
00db10
-#endif
00db10
+# endif /* !WIDE */
00db10
+#endif /* !TEST_BZERO */
00db10
 
00db10
-char *
00db10
+CHAR *
00db10
 inhibit_loop_to_libcall
00db10
-simple_memset (char *s, int c, size_t n)
00db10
+SIMPLE_MEMSET (CHAR *s, int c, size_t n)
00db10
 {
00db10
-  char *r = s, *end = s + n;
00db10
+  CHAR *r = s, *end = s + n;
00db10
   while (r < end)
00db10
     *r++ = c;
00db10
   return s;
00db10
 }
00db10
 
00db10
 static void
00db10
-do_one_test (impl_t *impl, char *s, int c __attribute ((unused)), size_t n)
00db10
+do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n)
00db10
 {
00db10
-  char tstbuf[n];
00db10
+  CHAR tstbuf[n];
00db10
 #ifdef TEST_BZERO
00db10
   simple_bzero (tstbuf, n);
00db10
   CALL (impl, s, n);
00db10
   if (memcmp (s, tstbuf, n) != 0)
00db10
 #else
00db10
-  char *res = CALL (impl, s, c, n);
00db10
+  CHAR *res = CALL (impl, s, c, n);
00db10
   if (res != s
00db10
-      || simple_memset (tstbuf, c, n) != tstbuf
00db10
-      || memcmp (s, tstbuf, n) != 0)
00db10
-#endif
00db10
+      || SIMPLE_MEMSET (tstbuf, c, n) != tstbuf
00db10
+      || MEMCMP (s, tstbuf, n) != 0)
00db10
+#endif /* !TEST_BZERO */
00db10
     {
00db10
       error (0, 0, "Wrong result in function %s", impl->name);
00db10
       ret = 1;
00db10
@@ -98,11 +123,11 @@ static void
00db10
 do_test (size_t align, int c, size_t len)
00db10
 {
00db10
   align &= 7;
00db10
-  if (align + len > page_size)
00db10
+  if ((align + len) * sizeof (CHAR) > page_size)
00db10
     return;
00db10
 
00db10
   FOR_EACH_IMPL (impl, 0)
00db10
-    do_one_test (impl, (char *) buf1 + align, c, len);
00db10
+    do_one_test (impl, (CHAR *) (buf1) + align, c, len);
00db10
 }
00db10
 
00db10
 #ifndef TEST_BZERO
00db10
@@ -111,18 +136,19 @@ do_random_tests (void)
00db10
 {
00db10
   size_t i, j, k, n, align, len, size;
00db10
   int c, o;
00db10
-  unsigned char *p, *res;
00db10
+  UCHAR *p, *res;
00db10
+  UCHAR *p2 = (UCHAR *) buf2;
00db10
 
00db10
-  for (i = 0; i < 65536; ++i)
00db10
-    buf2[i] = random () & 255;
00db10
+  for (i = 0; i < 65536 / sizeof (CHAR); ++i)
00db10
+    p2[i] = random () & BIG_CHAR;
00db10
 
00db10
   for (n = 0; n < ITERATIONS; n++)
00db10
     {
00db10
       if ((random () & 31) == 0)
00db10
-	size = 65536;
00db10
+	size = 65536 / sizeof (CHAR);
00db10
       else
00db10
 	size = 512;
00db10
-      p = buf1 + page_size - size;
00db10
+      p = (UCHAR *) (buf1 + page_size) - size;
00db10
       len = random () & (size - 1);
00db10
       align = size - len - (random () & 31);
00db10
       if (align > size)
00db10
@@ -132,10 +158,10 @@ do_random_tests (void)
00db10
       if ((random () & 7) == 0)
00db10
 	c = 0;
00db10
       else
00db10
-	c = random () & 255;
00db10
-      o = random () & 255;
00db10
+	c = random () & BIG_CHAR;
00db10
+      o = random () & BIG_CHAR;
00db10
       if (o == c)
00db10
-        o = (c + 1) & 255;
00db10
+	o = (c + 1) & BIG_CHAR;
00db10
       j = len + align + 128;
00db10
       if (j > size)
00db10
 	j = size;
00db10
@@ -152,11 +178,11 @@ do_random_tests (void)
00db10
 	{
00db10
 	  for (i = 0; i < len; ++i)
00db10
 	    {
00db10
-	      p[i + align] = buf2[i];
00db10
+	      p[i + align] = p2[i];
00db10
 	      if (p[i + align] == c)
00db10
 		p[i + align] = o;
00db10
 	    }
00db10
-	  res = (unsigned char *) CALL (impl, (char *) p + align, c, len);
00db10
+	  res = (UCHAR *) CALL (impl, (CHAR *) p + align, c, len);
00db10
 	  if (res != p + align)
00db10
 	    {
00db10
 	      error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %d, %zd) %p != %p",
00db10
@@ -190,7 +216,7 @@ do_random_tests (void)
00db10
 	}
00db10
     }
00db10
 }
00db10
-#endif
00db10
+#endif /* !TEST_BZERO */
00db10
 
00db10
 int
00db10
 test_main (void)
00db10
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
00db10
index 87dff0f..eac88e0 100644
00db10
--- a/sysdeps/s390/multiarch/Makefile
00db10
+++ b/sysdeps/s390/multiarch/Makefile
00db10
@@ -37,5 +37,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
00db10
 		   wcsspn wcsspn-vx wcsspn-c \
00db10
 		   wcspbrk wcspbrk-vx wcspbrk-c \
00db10
 		   wcscspn wcscspn-vx wcscspn-c \
00db10
-		   wmemchr wmemchr-vx wmemchr-c
00db10
+		   wmemchr wmemchr-vx wmemchr-c \
00db10
+		   wmemset wmemset-vx wmemset-c
00db10
 endif
00db10
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
index c90fb6b..44d534b 100644
00db10
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
@@ -133,6 +133,8 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
00db10
 
00db10
   IFUNC_VX_IMPL (memccpy);
00db10
 
00db10
+  IFUNC_VX_IMPL (wmemset);
00db10
+
00db10
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
00db10
 
00db10
   return i;
00db10
diff --git a/sysdeps/s390/multiarch/wmemset-c.c b/sysdeps/s390/multiarch/wmemset-c.c
00db10
new file mode 100644
00db10
index 0000000..59c9a7e
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wmemset-c.c
00db10
@@ -0,0 +1,31 @@
00db10
+/* Default wmemset implementation for S/390.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
00db10
+# define WMEMSET  __wmemset_c
00db10
+
00db10
+# include <wchar.h>
00db10
+extern __typeof (wmemset) __wmemset_c;
00db10
+# ifdef SHARED
00db10
+#  undef libc_hidden_def
00db10
+#  define libc_hidden_def(name)					\
00db10
+  __hidden_ver1 (__wmemset_c, __GI_wmemset, __wmemset_c);
00db10
+# endif /* SHARED */
00db10
+
00db10
+# include <wcsmbs/wmemset.c>
00db10
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
00db10
diff --git a/sysdeps/s390/multiarch/wmemset-vx.S b/sysdeps/s390/multiarch/wmemset-vx.S
00db10
new file mode 100644
00db10
index 0000000..dae2c29
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wmemset-vx.S
00db10
@@ -0,0 +1,142 @@
00db10
+/* Vector Optimized 32/64 bit S/390 version of wmemset.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
00db10
+
00db10
+# include "sysdep.h"
00db10
+# include "asm-syntax.h"
00db10
+
00db10
+	.text
00db10
+
00db10
+/* wchar_t *wmemset(wchar_t *dest, wchar_t wc, size_t n)
00db10
+   Fill an array of wide-characters with a constant wide character
00db10
+   and returns dest.
00db10
+
00db10
+   Register usage:
00db10
+   -r0=tmp
00db10
+   -r1=tmp
00db10
+   -r2=dest or current-pointer
00db10
+   -r3=wc
00db10
+   -r4=n
00db10
+   -r5=tmp
00db10
+   -v16=replicated wc
00db10
+   -v17,v18,v19=copy of v16 for vstm
00db10
+   -v31=saved dest for return
00db10
+*/
00db10
+ENTRY(__wmemset_vx)
00db10
+	.machine "z13"
00db10
+	.machinemode "zarch_nohighgprs"
00db10
+
00db10
+# if !defined __s390x__
00db10
+	llgfr	%r4,%r4
00db10
+# endif /* !defined __s390x__ */
00db10
+
00db10
+	vlvgg	%v31,%r2,0	/* Save destination pointer for return.  */
00db10
+	clgije	%r4,0,.Lend
00db10
+
00db10
+	vlvgf	%v16,%r3,0	/* Generate vector with wchar_t wc.  */
00db10
+	vrepf	%v16,%v16,0
00db10
+
00db10
+	/* Check range of maxlen and convert to byte-count.  */
00db10
+# ifdef __s390x__
00db10
+	tmhh	%r4,49152	/* Test bit 0 or 1 of maxlen.  */
00db10
+	lghi	%r5,-4		/* Max byte-count is 18446744073709551612.  */
00db10
+# else
00db10
+	tmlh	%r4,49152	/* Test bit 0 or 1 of maxlen.  */
00db10
+	llilf	%r5,4294967292	/* Max byte-count is 4294967292.  */
00db10
+# endif /* !__s390x__ */
00db10
+	sllg	%r4,%r4,2	/* Convert character-count to byte-count.  */
00db10
+	locgrne	%r4,%r5		/* Use max byte-count, if bit 0/1 was one.  */
00db10
+
00db10
+	/* Align dest to 16 byte.  */
00db10
+	risbg	%r0,%r2,60,128+63,0 /* Test if s is aligned and
00db10
+				       %r3 = bits 60-63 'and' 15.  */
00db10
+	je	.Lpreloop	/* If s is aligned, loop aligned.  */
00db10
+	tmll	%r2,3		/* Test if s is 4-byte aligned?  */
00db10
+	jne	.Lfallback	/* And use common-code variant if not.  */
00db10
+	lghi	%r1,16
00db10
+	slr	%r1,%r0		/* Compute byte count to load (16-x).  */
00db10
+	clgr	%r1,%r4
00db10
+	locgrh	%r1,%r4		/* min (byte count, n)  */
00db10
+	aghik	%r5,%r1,-1	/* vstl needs highest index.  */
00db10
+	vstl	%v16,%r5,0(%r2)	/* Store remaining bytes.  */
00db10
+	clgrje	%r1,%r4,.Lend	/* Return if n bytes where set.  */
00db10
+	slgr	%r4,%r1		/* Compute remaining byte count.  */
00db10
+	la	%r2,0(%r1,%r2)
00db10
+
00db10
+.Lpreloop:
00db10
+	/* Now we are 16-byte aligned.  */
00db10
+	clgijl	%r4,17,.Lremaining
00db10
+	srlg	%r1,%r4,8	/* Split into 256byte blocks */
00db10
+	clgije	%r1,0,.Lpreloop64
00db10
+	vlr	%v17,%v16
00db10
+	vlr	%v18,%v16
00db10
+	vlr	%v19,%v16
00db10
+
00db10
+.Lloop256:
00db10
+	vstm	%v16,%v19,0(%r2)
00db10
+	vstm	%v16,%v19,64(%r2)
00db10
+	vstm	%v16,%v19,128(%r2)
00db10
+	vstm	%v16,%v19,192(%r2)
00db10
+	la	%r2,256(%r2)
00db10
+	brctg	%r1,.Lloop256	/* Loop until all blocks are processed.  */
00db10
+
00db10
+	llgfr	%r4,%r4
00db10
+	nilf	%r4,255		/* Get remaining bytes */
00db10
+	je	.Lend		/* Skip store remaining bytes if zero.  */
00db10
+
00db10
+.Lpreloop64:
00db10
+	clgijl	%r4,17,.Lremaining
00db10
+	clgijl	%r4,33,.Lpreloop16
00db10
+	srlg	%r1,%r4,5	/* Split into 32byte blocks */
00db10
+
00db10
+.Lloop32:
00db10
+	vst	%v16,0(%r2)
00db10
+	vst	%v16,16(%r2)
00db10
+	la	%r2,32(%r2)
00db10
+	brctg	%r1,.Lloop32	/* Loop until all blocks are processed.  */
00db10
+
00db10
+	llgfr	%r4,%r4
00db10
+	nilf	%r4,31		/* Get remaining bytes */
00db10
+	je	.Lend		/* Skip store remaining bytes if zero.  */
00db10
+
00db10
+.Lpreloop16:
00db10
+	clgijl	%r4,17,.Lremaining
00db10
+	srlg	%r1,%r4,4	/* Split into 16byte blocks */
00db10
+
00db10
+.Lloop16:
00db10
+	vst	%v16,0(%r2)
00db10
+	la	%r2,16(%r2)
00db10
+	brctg	%r1,.Lloop16	/* Loop until all blocks are processed.  */
00db10
+
00db10
+	llgfr	%r4,%r4
00db10
+	nilf	%r4,15		/* Get remaining bytes */
00db10
+	je	.Lend		/* Skip store remaining bytes if zero.  */
00db10
+
00db10
+.Lremaining:
00db10
+	aghi	%r4,-1		/* vstl needs highest index.  */
00db10
+	vstl	%v16,%r4,0(%r2)
00db10
+
00db10
+.Lend:
00db10
+	vlgvg	%r2,%v31,0	/* Load saved dest for return value.  */
00db10
+	br	%r14
00db10
+.Lfallback:
00db10
+	srlg	%r4,%r4,2	/* Convert byte-count to character-count.  */
00db10
+	jg	__wmemset_c
00db10
+END(__wmemset_vx)
00db10
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
00db10
diff --git a/sysdeps/s390/multiarch/wmemset.c b/sysdeps/s390/multiarch/wmemset.c
00db10
new file mode 100644
00db10
index 0000000..1225fc1
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wmemset.c
00db10
@@ -0,0 +1,27 @@
00db10
+/* Multiple versions of wmemset.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
00db10
+# include <wchar.h>
00db10
+# include <ifunc-resolve.h>
00db10
+
00db10
+s390_vx_libc_ifunc2 (__wmemset, wmemset)
00db10
+
00db10
+#else
00db10
+# include <wcsmbs/wmemset.c>
00db10
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
00db10
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
00db10
index f8bc401..1ca3ace 100644
00db10
--- a/wcsmbs/Makefile
00db10
+++ b/wcsmbs/Makefile
00db10
@@ -43,7 +43,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
00db10
 
00db10
 strop-tests :=  wcscmp wcsncmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
00db10
 		wcpcpy wcsncpy wcpncpy wcscat wcsncat wcschrnul wcsspn wcspbrk \
00db10
-		wcscspn wmemchr
00db10
+		wcscspn wmemchr wmemset
00db10
 tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
00db10
 	 tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \
00db10
 	 tst-c16c32-1 wcsatcliff $(addprefix test-,$(strop-tests))
00db10
diff --git a/wcsmbs/test-wmemset-ifunc.c b/wcsmbs/test-wmemset-ifunc.c
00db10
new file mode 100644
00db10
index 0000000..b58b6bd
00db10
--- /dev/null
00db10
+++ b/wcsmbs/test-wmemset-ifunc.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Test and measure IFUNC implementations of wmemset function.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#define TEST_IFUNC 1
00db10
+#include "test-wmemset.c"
00db10
diff --git a/wcsmbs/test-wmemset.c b/wcsmbs/test-wmemset.c
00db10
new file mode 100644
00db10
index 0000000..c03c759
00db10
--- /dev/null
00db10
+++ b/wcsmbs/test-wmemset.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Test wmemset functions.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#define WIDE 1
00db10
+#include "../string/test-memset.c"
00db10
diff --git a/wcsmbs/wmemset.c b/wcsmbs/wmemset.c
00db10
index cc9a725..8049bb8 100644
00db10
--- a/wcsmbs/wmemset.c
00db10
+++ b/wcsmbs/wmemset.c
00db10
@@ -18,6 +18,9 @@
00db10
 
00db10
 #include <wchar.h>
00db10
 
00db10
+#ifdef WMEMSET
00db10
+# define wmemset WMEMSET
00db10
+#endif
00db10
 
00db10
 wchar_t *
00db10
 wmemset (s, c, n)
00db10
-- 
00db10
2.3.0
00db10