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