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