00db10
From 74fa8494fa732a0bd63b14b60ea0f1e542e0cee6 Mon Sep 17 00:00:00 2001
00db10
From: Stefan Liebler <stli@linux.vnet.ibm.com>
00db10
Date: Thu, 8 Oct 2015 11:09:04 +0200
00db10
Subject: [PATCH 14/30] S390: Optimize strncpy and wcsncpy.
00db10
00db10
upstream-commit-id: d183b96ee6dc694e95f212c9272a178163351b19
00db10
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00160.html
00db10
00db10
This patch provides optimized versions of strncpy and wcsncpy with the z13
00db10
vector instructions.
00db10
00db10
ChangeLog:
00db10
00db10
	* sysdeps/s390/multiarch/strncpy-vx.S: New File.
00db10
	* sysdeps/s390/multiarch/strncpy.c: Likewise.
00db10
	* sysdeps/s390/multiarch/wcsncpy-c.c: Likewise.
00db10
	* sysdeps/s390/multiarch/wcsncpy-vx.S: Likewise.
00db10
	* sysdeps/s390/multiarch/wcsncpy.c: Likewise.
00db10
	* sysdeps/s390/s390-32/multiarch/strncpy.c: Likewise.
00db10
	* sysdeps/s390/s390-64/multiarch/strncpy.c: Likewise.
00db10
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add strncpy and
00db10
	wcsncpy functions.
00db10
	* wcsmbs/wcsncpy.c: Use WCSNCPY if defined.
00db10
	* sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
	(__libc_ifunc_impl_list): Add ifunc test for strncpy, wcsncpy.
00db10
	* string/test-strncpy.c: Add wcsncpy support.
00db10
	* wcsmbs/test-wcsncpy.c: New File.
00db10
	* wcsmbs/Makefile (strop-tests): Add wcsncpy.
00db10
	* benchtests/bench-strncpy.c: Add wcsncpy support.
00db10
	* benchtests/bench-wcsncpy.c: New File.
00db10
	* benchtests/Makefile (wcsmbs-bench): Add wcsncpy
00db10
---
00db10
 benchtests/Makefile                      |   2 +-
00db10
 benchtests/bench-strncpy.c               | 108 ++++++++++-----
00db10
 benchtests/bench-wcsncpy.c               |  20 +++
00db10
 string/test-strncpy.c                    | 129 +++++++++++-------
00db10
 sysdeps/s390/multiarch/Makefile          |   6 +-
00db10
 sysdeps/s390/multiarch/ifunc-impl-list.c |   3 +
00db10
 sysdeps/s390/multiarch/strncpy-vx.S      | 207 ++++++++++++++++++++++++++++
00db10
 sysdeps/s390/multiarch/strncpy.c         |  24 ++++
00db10
 sysdeps/s390/multiarch/wcsncpy-c.c       |  25 ++++
00db10
 sysdeps/s390/multiarch/wcsncpy-vx.S      | 223 +++++++++++++++++++++++++++++++
00db10
 sysdeps/s390/multiarch/wcsncpy.c         |  28 ++++
00db10
 sysdeps/s390/s390-32/multiarch/strncpy.c |  21 +++
00db10
 sysdeps/s390/s390-64/multiarch/strncpy.c |  21 +++
00db10
 wcsmbs/Makefile                          |   2 +-
00db10
 wcsmbs/test-wcsncpy-ifunc.c              |  20 +++
00db10
 wcsmbs/test-wcsncpy.c                    |  20 +++
00db10
 wcsmbs/wcsncpy.c                         |   5 +
00db10
 17 files changed, 778 insertions(+), 86 deletions(-)
00db10
 create mode 100644 benchtests/bench-wcsncpy.c
00db10
 create mode 100644 sysdeps/s390/multiarch/strncpy-vx.S
00db10
 create mode 100644 sysdeps/s390/multiarch/strncpy.c
00db10
 create mode 100644 sysdeps/s390/multiarch/wcsncpy-c.c
00db10
 create mode 100644 sysdeps/s390/multiarch/wcsncpy-vx.S
00db10
 create mode 100644 sysdeps/s390/multiarch/wcsncpy.c
00db10
 create mode 100644 sysdeps/s390/s390-32/multiarch/strncpy.c
00db10
 create mode 100644 sysdeps/s390/s390-64/multiarch/strncpy.c
00db10
 create mode 100644 wcsmbs/test-wcsncpy-ifunc.c
00db10
 create mode 100644 wcsmbs/test-wcsncpy.c
00db10
00db10
diff --git a/benchtests/Makefile b/benchtests/Makefile
00db10
index 1b491c6..f898258 100644
00db10
--- a/benchtests/Makefile
00db10
+++ b/benchtests/Makefile
00db10
@@ -38,7 +38,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
00db10
 		strcat strchr strchrnul strcmp strcpy strcspn strlen \
00db10
 		strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
00db10
 		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
00db10
-wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy
00db10
+wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy
00db10
 string-bench-all := $(string-bench) ${wcsmbs-bench}
00db10
 
00db10
 stdlib-bench := strtod
00db10
diff --git a/benchtests/bench-strncpy.c b/benchtests/bench-strncpy.c
00db10
index 645925b..2cfd56a 100644
00db10
--- a/benchtests/bench-strncpy.c
00db10
+++ b/benchtests/bench-strncpy.c
00db10
@@ -1,5 +1,5 @@
00db10
 /* Measure strncpy functions.
00db10
-   Copyright (C) 2013 Free Software Foundation, Inc.
00db10
+   Copyright (C) 2013-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
@@ -16,23 +16,56 @@
00db10
    License along with the GNU C Library; if not, see
00db10
    <http://www.gnu.org/licenses/>.  */
00db10
 
00db10
+#ifdef WIDE
00db10
+# include <wchar.h>
00db10
+# define CHAR wchar_t
00db10
+# define UCHAR wchar_t
00db10
+# define BIG_CHAR WCHAR_MAX
00db10
+# define SMALL_CHAR 1273
00db10
+# define MEMCMP wmemcmp
00db10
+# define MEMSET wmemset
00db10
+# define STRNLEN wcsnlen
00db10
+#else
00db10
+# define CHAR char
00db10
+# define UCHAR unsigned char
00db10
+# define BIG_CHAR CHAR_MAX
00db10
+# define SMALL_CHAR 127
00db10
+# define MEMCMP memcmp
00db10
+# define MEMSET memset
00db10
+# define STRNLEN strnlen
00db10
+#endif /* !WIDE */
00db10
+
00db10
 #ifndef STRNCPY_RESULT
00db10
 # define STRNCPY_RESULT(dst, len, n) dst
00db10
 # define TEST_MAIN
00db10
-# define TEST_NAME "strncpy"
00db10
+# ifndef WIDE
00db10
+#  define TEST_NAME "strncpy"
00db10
+# else
00db10
+#  define TEST_NAME "wcsncpy"
00db10
+# endif /* WIDE */
00db10
 # include "bench-string.h"
00db10
 
00db10
-char *simple_strncpy (char *, const char *, size_t);
00db10
-char *stupid_strncpy (char *, const char *, size_t);
00db10
-
00db10
-IMPL (stupid_strncpy, 0)
00db10
-IMPL (simple_strncpy, 0)
00db10
-IMPL (strncpy, 1)
00db10
-
00db10
-char *
00db10
-simple_strncpy (char *dst, const char *src, size_t n)
00db10
+# ifndef WIDE
00db10
+#  define SIMPLE_STRNCPY simple_strncpy
00db10
+#  define STUPID_STRNCPY stupid_strncpy
00db10
+#  define STRNCPY strncpy
00db10
+# else
00db10
+#  define SIMPLE_STRNCPY simple_wcsncpy
00db10
+#  define STUPID_STRNCPY stupid_wcsncpy
00db10
+#  define STRNCPY wcsncpy
00db10
+# endif /* WIDE */
00db10
+
00db10
+CHAR *SIMPLE_STRNCPY (CHAR *, const CHAR *, size_t);
00db10
+CHAR *STUPID_STRNCPY (CHAR *, const CHAR *, size_t);
00db10
+
00db10
+IMPL (STUPID_STRNCPY, 0)
00db10
+IMPL (SIMPLE_STRNCPY, 0)
00db10
+IMPL (STRNCPY, 1)
00db10
+
00db10
+CHAR *
00db10
+SIMPLE_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
00db10
 {
00db10
-  char *ret = dst;
00db10
+  CHAR *ret = dst;
00db10
   while (n--)
00db10
     if ((*dst++ = *src++) == '\0')
00db10
       {
00db10
@@ -43,10 +76,10 @@ simple_strncpy (char *dst, const char *src, size_t n)
00db10
   return ret;
00db10
 }
00db10
 
00db10
-char *
00db10
-stupid_strncpy (char *dst, const char *src, size_t n)
00db10
+CHAR *
00db10
+STUPID_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
00db10
 {
00db10
-  size_t nc = strnlen (src, n);
00db10
+  size_t nc = STRNLEN (src, n);
00db10
   size_t i;
00db10
 
00db10
   for (i = 0; i < nc; ++i)
00db10
@@ -55,12 +88,12 @@ stupid_strncpy (char *dst, const char *src, size_t n)
00db10
     dst[i] = '\0';
00db10
   return dst;
00db10
 }
00db10
-#endif
00db10
+#endif /* !STRNCPY_RESULT */
00db10
 
00db10
-typedef char *(*proto_t) (char *, const char *, size_t);
00db10
+typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
00db10
 
00db10
 static void
00db10
-do_one_test (impl_t *impl, char *dst, const char *src, size_t len, size_t n)
00db10
+do_one_test (impl_t *impl, CHAR *dst, const CHAR *src, size_t len, size_t n)
00db10
 {
00db10
   size_t i, iters = INNER_LOOP_ITERS;
00db10
   timing_t start, stop, cur;
00db10
@@ -73,7 +106,7 @@ do_one_test (impl_t *impl, char *dst, const char *src, size_t len, size_t n)
00db10
       return;
00db10
     }
00db10
 
00db10
-  if (memcmp (dst, src, len > n ? n : len) != 0)
00db10
+  if (memcmp (dst, src, (len > n ? n : len) * sizeof (CHAR)) != 0)
00db10
     {
00db10
       error (0, 0, "Wrong result in function %s", impl->name);
00db10
       ret = 1;
00db10
@@ -109,23 +142,24 @@ static void
00db10
 do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char)
00db10
 {
00db10
   size_t i;
00db10
-  char *s1, *s2;
00db10
+  CHAR *s1, *s2;
00db10
 
00db10
   align1 &= 7;
00db10
-  if (align1 + len >= page_size)
00db10
+  if ((align1 + len) * sizeof (CHAR) >= page_size)
00db10
     return;
00db10
 
00db10
   align2 &= 7;
00db10
-  if (align2 + len >= page_size)
00db10
+  if ((align2 + len) * sizeof (CHAR) >= page_size)
00db10
     return;
00db10
 
00db10
-  s1 = (char *) (buf1 + align1);
00db10
-  s2 = (char *) (buf2 + align2);
00db10
+  s1 = (CHAR *) (buf1 + align1);
00db10
+  s2 = (CHAR *) (buf2 + align2);
00db10
 
00db10
   for (i = 0; i < len; ++i)
00db10
     s1[i] = 32 + 23 * i % (max_char - 32);
00db10
   s1[len] = 0;
00db10
-  for (i = len + 1; i + align1 < page_size && i < len + 64; ++i)
00db10
+  for (i = len + 1; (i + align1) * sizeof (CHAR) < page_size && i < len + 64;
00db10
+       ++i)
00db10
     s1[i] = 32 + 32 * i % (max_char - 32);
00db10
 
00db10
   printf ("Length %4zd, n %4zd, alignment %2zd/%2zd:", len, n, align1, align2);
00db10
@@ -150,22 +184,22 @@ test_main (void)
00db10
 
00db10
   for (i = 1; i < 8; ++i)
00db10
     {
00db10
-      do_test (i, i, 16, 16, 127);
00db10
-      do_test (i, i, 16, 16, 255);
00db10
-      do_test (i, 2 * i, 16, 16, 127);
00db10
-      do_test (2 * i, i, 16, 16, 255);
00db10
-      do_test (8 - i, 2 * i, 1 << i, 2 << i, 127);
00db10
-      do_test (2 * i, 8 - i, 2 << i, 1 << i, 127);
00db10
-      do_test (8 - i, 2 * i, 1 << i, 2 << i, 255);
00db10
-      do_test (2 * i, 8 - i, 2 << i, 1 << i, 255);
00db10
+      do_test (i, i, 16, 16, SMALL_CHAR);
00db10
+      do_test (i, i, 16, 16, BIG_CHAR);
00db10
+      do_test (i, 2 * i, 16, 16, SMALL_CHAR);
00db10
+      do_test (2 * i, i, 16, 16, BIG_CHAR);
00db10
+      do_test (8 - i, 2 * i, 1 << i, 2 << i, SMALL_CHAR);
00db10
+      do_test (2 * i, 8 - i, 2 << i, 1 << i, SMALL_CHAR);
00db10
+      do_test (8 - i, 2 * i, 1 << i, 2 << i, BIG_CHAR);
00db10
+      do_test (2 * i, 8 - i, 2 << i, 1 << i, BIG_CHAR);
00db10
     }
00db10
 
00db10
   for (i = 1; i < 8; ++i)
00db10
     {
00db10
-      do_test (0, 0, 4 << i, 8 << i, 127);
00db10
-      do_test (0, 0, 16 << i, 8 << i, 127);
00db10
-      do_test (8 - i, 2 * i, 4 << i, 8 << i, 127);
00db10
-      do_test (8 - i, 2 * i, 16 << i, 8 << i, 127);
00db10
+      do_test (0, 0, 4 << i, 8 << i, SMALL_CHAR);
00db10
+      do_test (0, 0, 16 << i, 8 << i, SMALL_CHAR);
00db10
+      do_test (8 - i, 2 * i, 4 << i, 8 << i, SMALL_CHAR);
00db10
+      do_test (8 - i, 2 * i, 16 << i, 8 << i, SMALL_CHAR);
00db10
     }
00db10
 
00db10
   return ret;
00db10
diff --git a/benchtests/bench-wcsncpy.c b/benchtests/bench-wcsncpy.c
00db10
new file mode 100644
00db10
index 0000000..d6f63c9
00db10
--- /dev/null
00db10
+++ b/benchtests/bench-wcsncpy.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Measure wcsncpy 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-strncpy.c"
00db10
diff --git a/string/test-strncpy.c b/string/test-strncpy.c
00db10
index a623093..bdccc98 100644
00db10
--- a/string/test-strncpy.c
00db10
+++ b/string/test-strncpy.c
00db10
@@ -17,23 +17,56 @@
00db10
    License along with the GNU C Library; if not, see
00db10
    <http://www.gnu.org/licenses/>.  */
00db10
 
00db10
+#ifdef WIDE
00db10
+# include <wchar.h>
00db10
+# define CHAR wchar_t
00db10
+# define UCHAR wchar_t
00db10
+# define BIG_CHAR WCHAR_MAX
00db10
+# define SMALL_CHAR 1273
00db10
+# define MEMCMP wmemcmp
00db10
+# define MEMSET wmemset
00db10
+# define STRNLEN wcsnlen
00db10
+#else
00db10
+# define CHAR char
00db10
+# define UCHAR unsigned char
00db10
+# define BIG_CHAR CHAR_MAX
00db10
+# define SMALL_CHAR 127
00db10
+# define MEMCMP memcmp
00db10
+# define MEMSET memset
00db10
+# define STRNLEN strnlen
00db10
+#endif /* !WIDE */
00db10
+
00db10
+
00db10
 #ifndef STRNCPY_RESULT
00db10
 # define STRNCPY_RESULT(dst, len, n) dst
00db10
 # define TEST_MAIN
00db10
-# define TEST_NAME "strncpy"
00db10
+# ifndef WIDE
00db10
+#  define TEST_NAME "strncpy"
00db10
+# else
00db10
+#  define TEST_NAME "wcsncpy"
00db10
+# endif /* WIDE */
00db10
 # include "test-string.h"
00db10
+# ifndef WIDE
00db10
+#  define SIMPLE_STRNCPY simple_strncpy
00db10
+#  define STUPID_STRNCPY stupid_strncpy
00db10
+#  define STRNCPY strncpy
00db10
+# else
00db10
+#  define SIMPLE_STRNCPY simple_wcsncpy
00db10
+#  define STUPID_STRNCPY stupid_wcsncpy
00db10
+#  define STRNCPY wcsncpy
00db10
+# endif /* WIDE */
00db10
 
00db10
-char *simple_strncpy (char *, const char *, size_t);
00db10
-char *stupid_strncpy (char *, const char *, size_t);
00db10
+CHAR *SIMPLE_STRNCPY (CHAR *, const CHAR *, size_t);
00db10
+CHAR *STUPID_STRNCPY (CHAR *, const CHAR *, size_t);
00db10
 
00db10
-IMPL (stupid_strncpy, 0)
00db10
-IMPL (simple_strncpy, 0)
00db10
-IMPL (strncpy, 1)
00db10
+IMPL (STUPID_STRNCPY, 0)
00db10
+IMPL (SIMPLE_STRNCPY, 0)
00db10
+IMPL (STRNCPY, 1)
00db10
 
00db10
-char *
00db10
-simple_strncpy (char *dst, const char *src, size_t n)
00db10
+CHAR *
00db10
+SIMPLE_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
00db10
 {
00db10
-  char *ret = dst;
00db10
+  CHAR *ret = dst;
00db10
   while (n--)
00db10
     if ((*dst++ = *src++) == '\0')
00db10
       {
00db10
@@ -44,10 +77,10 @@ simple_strncpy (char *dst, const char *src, size_t n)
00db10
   return ret;
00db10
 }
00db10
 
00db10
-char *
00db10
-stupid_strncpy (char *dst, const char *src, size_t n)
00db10
+CHAR *
00db10
+STUPID_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
00db10
 {
00db10
-  size_t nc = strnlen (src, n);
00db10
+  size_t nc = STRNLEN (src, n);
00db10
   size_t i;
00db10
 
00db10
   for (i = 0; i < nc; ++i)
00db10
@@ -56,12 +89,12 @@ stupid_strncpy (char *dst, const char *src, size_t n)
00db10
     dst[i] = '\0';
00db10
   return dst;
00db10
 }
00db10
-#endif
00db10
+#endif /* !STRNCPY_RESULT */
00db10
 
00db10
-typedef char *(*proto_t) (char *, const char *, size_t);
00db10
+typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
00db10
 
00db10
 static void
00db10
-do_one_test (impl_t *impl, char *dst, const char *src, size_t len, size_t n)
00db10
+do_one_test (impl_t *impl, CHAR *dst, const char *src, size_t len, size_t n)
00db10
 {
00db10
   if (CALL (impl, dst, src, n) != STRNCPY_RESULT (dst, len, n))
00db10
     {
00db10
@@ -71,7 +104,7 @@ do_one_test (impl_t *impl, char *dst, const char *src, size_t len, size_t n)
00db10
       return;
00db10
     }
00db10
 
00db10
-  if (memcmp (dst, src, len > n ? n : len) != 0)
00db10
+  if (memcmp (dst, src, (len > n ? n : len) * sizeof (CHAR)) != 0)
00db10
     {
00db10
       error (0, 0, "Wrong result in function %s", impl->name);
00db10
       ret = 1;
00db10
@@ -96,23 +129,26 @@ static void
00db10
 do_test (size_t align1, size_t align2, size_t len, size_t n, int max_char)
00db10
 {
00db10
   size_t i;
00db10
-  char *s1, *s2;
00db10
+  CHAR *s1, *s2;
00db10
 
00db10
+/* For wcsncpy: align1 and align2 here mean alignment not in bytes,
00db10
+   but in wchar_ts, in bytes it will equal to align * (sizeof (wchar_t)).  */
00db10
   align1 &= 7;
00db10
-  if (align1 + len >= page_size)
00db10
+  if ((align1 + len) * sizeof (CHAR) >= page_size)
00db10
     return;
00db10
 
00db10
   align2 &= 7;
00db10
-  if (align2 + len >= page_size)
00db10
+  if ((align2 + len) * sizeof (CHAR) >= page_size)
00db10
     return;
00db10
 
00db10
-  s1 = (char *) (buf1 + align1);
00db10
-  s2 = (char *) (buf2 + align2);
00db10
+  s1 = (CHAR *) (buf1) + align1;
00db10
+  s2 = (CHAR *) (buf2) + align2;
00db10
 
00db10
   for (i = 0; i < len; ++i)
00db10
     s1[i] = 32 + 23 * i % (max_char - 32);
00db10
   s1[len] = 0;
00db10
-  for (i = len + 1; i + align1 < page_size && i < len + 64; ++i)
00db10
+  for (i = len + 1; (i + align1) * sizeof (CHAR) < page_size && i < len + 64;
00db10
+       ++i)
00db10
     s1[i] = 32 + 32 * i % (max_char - 32);
00db10
 
00db10
   FOR_EACH_IMPL (impl, 0)
00db10
@@ -123,12 +159,16 @@ static void
00db10
 do_random_tests (void)
00db10
 {
00db10
   size_t i, j, n, align1, align2, len, size, mode;
00db10
-  unsigned char *p1 = buf1 + page_size - 512;
00db10
-  unsigned char *p2 = buf2 + page_size - 512;
00db10
-  unsigned char *res;
00db10
+  UCHAR *p1 = (UCHAR *) (buf1 + page_size) - 512;
00db10
+  UCHAR *p2 = (UCHAR *) (buf2 + page_size) - 512;
00db10
+  UCHAR *res;
00db10
 
00db10
   for (n = 0; n < ITERATIONS; n++)
00db10
     {
00db10
+      /* For wcsncpy: align1 and align2 here mean align not in bytes,
00db10
+	 but in wchar_ts, in bytes it will equal to align * (sizeof
00db10
+	 (wchar_t)).  */
00db10
+
00db10
       mode = random ();
00db10
       if (mode & 1)
00db10
 	{
00db10
@@ -166,7 +206,7 @@ do_random_tests (void)
00db10
 	    {
00db10
 	      size = random () & 511;
00db10
 	      if (size + j > 512)
00db10
-		size = 512 - j - (random() & 31);
00db10
+		size = 512 - j - (random () & 31);
00db10
 	    }
00db10
 	  else
00db10
 	    size = 512 - j;
00db10
@@ -182,18 +222,17 @@ do_random_tests (void)
00db10
 	    p1[i] = 0;
00db10
 	  else
00db10
 	    {
00db10
-	      p1[i] = random () & 255;
00db10
+	      p1[i] = random () & BIG_CHAR;
00db10
 	      if (i >= align1 && i < len + align1 && !p1[i])
00db10
-		p1[i] = (random () & 127) + 3;
00db10
+		p1[i] = (random () & SMALL_CHAR) + 3;
00db10
 	    }
00db10
 	}
00db10
 
00db10
       FOR_EACH_IMPL (impl, 1)
00db10
 	{
00db10
-	  memset (p2 - 64, '\1', 512 + 64);
00db10
-	  res = (unsigned char *) CALL (impl,
00db10
-					(char *) (p2 + align2),
00db10
-					(char *) (p1 + align1), size);
00db10
+	  MEMSET (p2 - 64, '\1', 512 + 64);
00db10
+	  res = (UCHAR *) CALL (impl, (CHAR *) (p2 + align2),
00db10
+				(CHAR *) (p1 + align1), size);
00db10
 	  if (res != STRNCPY_RESULT (p2 + align2, len, size))
00db10
 	    {
00db10
 	      error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd) %p != %p",
00db10
@@ -235,7 +274,7 @@ do_random_tests (void)
00db10
 	  j = len + 1;
00db10
 	  if (size < j)
00db10
 	    j = size;
00db10
-	  if (memcmp (p1 + align1, p2 + align2, j))
00db10
+	  if (MEMCMP (p1 + align1, p2 + align2, j))
00db10
 	    {
00db10
 	      error (0, 0, "Iteration %zd - different strings, %s (%zd, %zd, %zd)",
00db10
 		     n, impl->name, align1, align2, len);
00db10
@@ -259,22 +298,22 @@ test_main (void)
00db10
 
00db10
   for (i = 1; i < 8; ++i)
00db10
     {
00db10
-      do_test (i, i, 16, 16, 127);
00db10
-      do_test (i, i, 16, 16, 255);
00db10
-      do_test (i, 2 * i, 16, 16, 127);
00db10
-      do_test (2 * i, i, 16, 16, 255);
00db10
-      do_test (8 - i, 2 * i, 1 << i, 2 << i, 127);
00db10
-      do_test (2 * i, 8 - i, 2 << i, 1 << i, 127);
00db10
-      do_test (8 - i, 2 * i, 1 << i, 2 << i, 255);
00db10
-      do_test (2 * i, 8 - i, 2 << i, 1 << i, 255);
00db10
+      do_test (i, i, 16, 16, SMALL_CHAR);
00db10
+      do_test (i, i, 16, 16, BIG_CHAR);
00db10
+      do_test (i, 2 * i, 16, 16, SMALL_CHAR);
00db10
+      do_test (2 * i, i, 16, 16, BIG_CHAR);
00db10
+      do_test (8 - i, 2 * i, 1 << i, 2 << i, SMALL_CHAR);
00db10
+      do_test (2 * i, 8 - i, 2 << i, 1 << i, SMALL_CHAR);
00db10
+      do_test (8 - i, 2 * i, 1 << i, 2 << i, BIG_CHAR);
00db10
+      do_test (2 * i, 8 - i, 2 << i, 1 << i, BIG_CHAR);
00db10
     }
00db10
 
00db10
   for (i = 1; i < 8; ++i)
00db10
     {
00db10
-      do_test (0, 0, 4 << i, 8 << i, 127);
00db10
-      do_test (0, 0, 16 << i, 8 << i, 127);
00db10
-      do_test (8 - i, 2 * i, 4 << i, 8 << i, 127);
00db10
-      do_test (8 - i, 2 * i, 16 << i, 8 << i, 127);
00db10
+      do_test (0, 0, 4 << i, 8 << i, SMALL_CHAR);
00db10
+      do_test (0, 0, 16 << i, 8 << i, SMALL_CHAR);
00db10
+      do_test (8 - i, 2 * i, 4 << i, 8 << i, SMALL_CHAR);
00db10
+      do_test (8 - i, 2 * i, 16 << i, 8 << i, SMALL_CHAR);
00db10
     }
00db10
 
00db10
   do_random_tests ();
00db10
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
00db10
index 5b57342..0dff2dc 100644
00db10
--- a/sysdeps/s390/multiarch/Makefile
00db10
+++ b/sysdeps/s390/multiarch/Makefile
00db10
@@ -2,12 +2,14 @@ ifeq ($(subdir),string)
00db10
 sysdep_routines += strlen strlen-vx strlen-c \
00db10
 		   strnlen strnlen-vx strnlen-c \
00db10
 		   strcpy strcpy-vx \
00db10
-		   stpcpy stpcpy-vx stpcpy-c
00db10
+		   stpcpy stpcpy-vx stpcpy-c \
00db10
+		   strncpy strncpy-vx
00db10
 endif
00db10
 
00db10
 ifeq ($(subdir),wcsmbs)
00db10
 sysdep_routines += wcslen wcslen-vx wcslen-c \
00db10
 		   wcsnlen wcsnlen-vx wcsnlen-c \
00db10
 		   wcscpy wcscpy-vx wcscpy-c \
00db10
-		   wcpcpy wcpcpy-vx wcpcpy-c
00db10
+		   wcpcpy wcpcpy-vx wcpcpy-c \
00db10
+		   wcsncpy wcsncpy-vx wcsncpy-c
00db10
 endif
00db10
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
index a402301..940421d 100644
00db10
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
@@ -91,6 +91,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
00db10
   IFUNC_VX_IMPL (stpcpy);
00db10
   IFUNC_VX_IMPL (wcpcpy);
00db10
 
00db10
+  IFUNC_VX_IMPL (strncpy);
00db10
+  IFUNC_VX_IMPL (wcsncpy);
00db10
+
00db10
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
00db10
 
00db10
   return i;
00db10
diff --git a/sysdeps/s390/multiarch/strncpy-vx.S b/sysdeps/s390/multiarch/strncpy-vx.S
00db10
new file mode 100644
00db10
index 0000000..c18b9b7
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/strncpy-vx.S
00db10
@@ -0,0 +1,207 @@
00db10
+/* Vector optimized 32/64 bit S/390 version of strncpy.
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
+/* char * strncpy (const char *dest, const char *src, size_t n)
00db10
+   Copy at most n characters of string  src to dest.
00db10
+
00db10
+   Register usage:
00db10
+   -r0=dest pointer for return
00db10
+   -r1=tmp, zero byte index
00db10
+   -r2=dest
00db10
+   -r3=src
00db10
+   -r4=n
00db10
+   -r5=current_len
00db10
+   -r6=tmp, loaded bytes
00db10
+   -r7=tmp, border
00db10
+   -v16=part of src
00db10
+   -v17=index of zero
00db10
+   -v18=part of src
00db10
+   -v31=register save area for r6, r7
00db10
+*/
00db10
+ENTRY(__strncpy_vx)
00db10
+	.machine "z13"
00db10
+	.machinemode "zarch_nohighgprs"
00db10
+
00db10
+# if !defined __s390x__
00db10
+	llgfr	%r4,%r4
00db10
+# endif /* !defined __s390x__ */
00db10
+
00db10
+	clgfi	%r4,0
00db10
+	ber	%r14		/* Nothing to do, if n == 0.  */
00db10
+	lgr	%r0,%r2		/* Save destination pointer for return.  */
00db10
+	vlvgp	%v31,%r6,%r7	/* Save registers.  */
00db10
+
00db10
+	vlbb	%v16,0(%r3),6	/* Load s until next 4k-byte boundary.  */
00db10
+	lcbb	%r6,0(%r3),6	/* Get bytes to 4k-byte boundary or 16.  */
00db10
+	llgfr	%r6,%r6		/* Convert 32bit to 64bit.  */
00db10
+
00db10
+	lghi	%r5,0		/* current_len = 0.  */
00db10
+
00db10
+	clgrjle	%r4,%r6,.Lremaining_v16 /* If n <= loaded-bytes
00db10
+					   -> process remaining.  */
00db10
+
00db10
+	/* n > loaded-byte-count.  */
00db10
+	vfenezb	%v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
00db10
+	clrjl	%r1,%r6,.Lfound_v16_store /* Found zero within loaded bytes,
00db10
+					     copy and return.  */
00db10
+
00db10
+	/* Align s to 16 byte.  */
00db10
+	risbgn	%r7,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
00db10
+	lghi	%r5,15		/* current_len = 15.  */
00db10
+	slr	%r5,%r7		/* Compute highest index to 16byte boundary.  */
00db10
+
00db10
+	/* Zero not found and n > loaded-byte-count.  */
00db10
+	vstl	%v16,%r5,0(%r2)	/* Copy loaded characters - no zero.  */
00db10
+	ahi	%r5,1		/* Start loop at next character.  */
00db10
+
00db10
+	/* Now we are 16byte aligned, so we can load
00db10
+	   a full vreg without page fault.  */
00db10
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
00db10
+	aghi	%r1,64
00db10
+	clgrjl	%r1,%r4,.Lloop64
00db10
+
00db10
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
00db10
+	clgijl	%r4,17,.Lremaining_v16	/* If n <= 16, process remaining
00db10
+					   bytes.  */
00db10
+.Llt64:
00db10
+	lgr	%r7,%r4
00db10
+	slgfi	%r7,16		/* border_len = n - 16.  */
00db10
+
00db10
+	clgrjhe	%r5,%r7,.Lremaining_v16 /* If current_len >= border
00db10
+					   then process remaining bytes.  */
00db10
+	vfenezbs %v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	je	.Lfound_v16	/* Jump away if zero was found.  */
00db10
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
00db10
+	vst	%v16,0(%r5,%r2)	/* Store previous part without zero to dst.  */
00db10
+	aghi	%r5,16
00db10
+
00db10
+	clgrjhe	%r5,%r7,.Lremaining_v18
00db10
+	vfenezbs %v17,%v18,%v18
00db10
+	je	.Lfound_v18
00db10
+	vl	%v16,16(%r5,%r3)
00db10
+	vst	%v18,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+
00db10
+	clgrjhe	%r5,%r7,.Lremaining_v16
00db10
+	vfenezbs %v17,%v16,%v16
00db10
+	je	.Lfound_v16
00db10
+	vl	%v18,16(%r5,%r3)
00db10
+	vst	%v16,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+
00db10
+.Lremaining_v18:
00db10
+	vlr	%v16,%v18
00db10
+.Lremaining_v16:
00db10
+	/* v16 contains the remaining bytes [1...16].
00db10
+	   Store remaining bytes and append string-termination.  */
00db10
+	vfenezb	%v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	slgrk	%r7,%r4,%r5	/* Remaining bytes = maxlen - current_len.  */
00db10
+	aghi	%r7,-1		/* vstl needs highest index.  */
00db10
+	la	%r2,0(%r5,%r2)	/* vstl has no index register.  */
00db10
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
00db10
+	/* Zero in remaining bytes? -> jump away (zero-index < max-index)
00db10
+	   Do not jump away if zero-index == max-index,
00db10
+	   but simply copy zero with vstl below.  */
00db10
+	clrjl	%r1,%r7,.Lfound_v16_store
00db10
+	vstl	%v16,%r7,0(%r2)	/* Store remaining bytes without null
00db10
+				   termination!.  */
00db10
+.Lend:
00db10
+	/* Restore saved registers.  */
00db10
+	vlgvg	%r6,%v31,0
00db10
+	vlgvg	%r7,%v31,1
00db10
+	lgr	%r2,%r0		/* Load saved dest-ptr.  */
00db10
+	br	%r14
00db10
+
00db10
+
00db10
+.Lfound_v16_32:
00db10
+	aghi	%r5,32
00db10
+	j	.Lfound_v16
00db10
+.Lfound_v18_48:
00db10
+	aghi	%r5,32
00db10
+.Lfound_v18_16:
00db10
+	aghi	%r5,16
00db10
+.Lfound_v18:
00db10
+	vlr	%v16,%v18
00db10
+.Lfound_v16:
00db10
+	/* v16 contains a zero. Store remaining bytes to zero. current_len
00db10
+	   has not reached border, thus checking for n is not needed! */
00db10
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
00db10
+	la	%r2,0(%r5,%r2)	/* vstl has no support for index-register.  */
00db10
+.Lfound_v16_store:
00db10
+	vstl	%v16,%r1,0(%r2)	/* Copy characters including zero.  */
00db10
+	/* Fill remaining bytes with zero - remaining count always > 0.  */
00db10
+	algr	%r5,%r1		/* Remaining bytes (=%r4) = ...  */
00db10
+	slgr	%r4,%r5		/* = n - (current_len + zero_index + 1).  */
00db10
+	la	%r2,0(%r1,%r2)	/* Pointer to zero. start filling beyond.  */
00db10
+	aghi	%r4,-2		/* mvc with exrl needs count - 1.
00db10
+				   (additional -1, see remaining bytes above) */
00db10
+	srlg	%r6,%r4,8	/* Split into 256 byte blocks.  */
00db10
+	ltgr	%r6,%r6
00db10
+	je	.Lzero_lt256
00db10
+.Lzero_loop256:
00db10
+	mvc	1(256,%r2),0(%r2) /* Fill 256 zeros at once.  */
00db10
+	la	%r2,256(%r2)
00db10
+	brctg	%r6,.Lzero_loop256 /* Loop until all blocks are processed.  */
00db10
+.Lzero_lt256:
00db10
+	exrl	%r4,.Lmvc_lt256
00db10
+	j	.Lend
00db10
+.Lmvc_lt256:
00db10
+	mvc	1(1,%r2),0(%r2)
00db10
+
00db10
+.Lloop64:
00db10
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
00db10
+	vfenezbs %v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	je	.Lfound_v16	/* Jump away if zero was found.  */
00db10
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
00db10
+	vst	%v16,0(%r5,%r2)	/* Store previous part without zero to dst.  */
00db10
+	vfenezbs %v17,%v18,%v18
00db10
+	je	.Lfound_v18_16
00db10
+	vl	%v16,32(%r5,%r3)
00db10
+	vst	%v18,16(%r5,%r2)
00db10
+	vfenezbs %v17,%v16,%v16
00db10
+	je	.Lfound_v16_32
00db10
+	vl	%v18,48(%r5,%r3)
00db10
+	vst	%v16,32(%r5,%r2)
00db10
+	vfenezbs %v17,%v18,%v18
00db10
+	je	.Lfound_v18_48
00db10
+	vst	%v18,48(%r5,%r2)
00db10
+
00db10
+	aghi	%r5,64
00db10
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
00db10
+	aghi	%r1,64
00db10
+	clgrjl	%r1,%r4,.Lloop64
00db10
+
00db10
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
00db10
+	j	.Llt64
00db10
+END(__strncpy_vx)
00db10
+
00db10
+# define strncpy __strncpy_c
00db10
+# undef libc_hidden_builtin_def
00db10
+# define libc_hidden_builtin_def(name) strong_alias(__strncpy_c, __GI_strncpy)
00db10
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
00db10
+
00db10
+/* Include strncpy-implementation in s390-32/s390-64 subdirectory.  */
00db10
+#include <strncpy.S>
00db10
diff --git a/sysdeps/s390/multiarch/strncpy.c b/sysdeps/s390/multiarch/strncpy.c
00db10
new file mode 100644
00db10
index 0000000..0b0c308
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/strncpy.c
00db10
@@ -0,0 +1,24 @@
00db10
+/* Multiple versions of strncpy.
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 <string.h>
00db10
+# include <ifunc-resolve.h>
00db10
+
00db10
+s390_vx_libc_ifunc2 (__strncpy, strncpy)
00db10
+#endif
00db10
diff --git a/sysdeps/s390/multiarch/wcsncpy-c.c b/sysdeps/s390/multiarch/wcsncpy-c.c
00db10
new file mode 100644
00db10
index 0000000..a46e4ac
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wcsncpy-c.c
00db10
@@ -0,0 +1,25 @@
00db10
+/* Default wcsncpy 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 WCSNCPY  __wcsncpy_c
00db10
+
00db10
+# include <wchar.h>
00db10
+extern __typeof (__wcsncpy) __wcsncpy_c;
00db10
+# include <wcsmbs/wcsncpy.c>
00db10
+#endif
00db10
diff --git a/sysdeps/s390/multiarch/wcsncpy-vx.S b/sysdeps/s390/multiarch/wcsncpy-vx.S
00db10
new file mode 100644
00db10
index 0000000..072a2d4
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wcsncpy-vx.S
00db10
@@ -0,0 +1,223 @@
00db10
+/* Vector optimized 32/64 bit S/390 version of wcsncpy.
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 *wcsncpy (const wchar_t *dest, const wchar_t *src, size_t n)
00db10
+   Copy at most n characters of string  src to dest.
00db10
+
00db10
+   Register usage:
00db10
+   -r0=dest pointer for return
00db10
+   -r1=tmp, zero byte index
00db10
+   -r2=dest
00db10
+   -r3=src
00db10
+   -r4=n
00db10
+   -r5=current_len
00db10
+   -r6=tmp, loaded bytes
00db10
+   -r7=tmp, border
00db10
+   -v16=part of src
00db10
+   -v17=index of zero
00db10
+   -v18=part of src
00db10
+   -v31=register save area for r6, r7
00db10
+*/
00db10
+ENTRY(__wcsncpy_vx)
00db10
+	.machine "z13"
00db10
+	.machinemode "zarch_nohighgprs"
00db10
+
00db10
+# if !defined __s390x__
00db10
+	llgfr	%r4,%r4
00db10
+# endif /* !defined __s390x__ */
00db10
+
00db10
+	clgfi	%r4,0
00db10
+	ber	%r14		/* Nothing to do, if n == 0.  */
00db10
+
00db10
+	vlbb	%v16,0(%r3),6	/* Load s until next 4k-byte boundary.  */
00db10
+
00db10
+	tmll	%r3,3		/* Test if s is 4-byte aligned?  */
00db10
+	jne	.Lfallback	/* And use common-code variant if not.  */
00db10
+
00db10
+	vlvgp	%v31,%r6,%r7	/* Save registers.  */
00db10
+	lgr	%r0,%r2		/* Save destination pointer for return.  */
00db10
+
00db10
+	lcbb	%r6,0(%r3),6	/* Get bytes to 4k-byte boundary or 16.  */
00db10
+	llgfr	%r6,%r6		/* Convert 32bit to 64bit.  */
00db10
+
00db10
+	lghi	%r5,0		/* current_len = 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 n.  */
00db10
+	lghi	%r1,-4		/* Max byte-count is 18446744073709551612.  */
00db10
+# else
00db10
+	tmlh	%r4,49152	/* Test bit 0 or 1 of n.  */
00db10
+	llilf	%r1,4294967292	/* Max byte-count is 4294967292.  */
00db10
+# endif /* !__s390x__ */
00db10
+	sllg	%r4,%r4,2	/* Convert character-count to byte-count.  */
00db10
+	locgrne	%r4,%r1		/* Use max byte-count, if bit 0/1 was one.  */
00db10
+
00db10
+	clgrjle	%r4,%r6,.Lremaining_v16 /* If n <= loaded-bytes
00db10
+					   -> process remaining.  */
00db10
+
00db10
+	/* n > loaded-byte-count.  */
00db10
+	vfenezf	%v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
00db10
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
00db10
+	clrjl	%r1,%r6,.Lfound_v16_store /* Found zero within loaded bytes,
00db10
+					     copy and return.  */
00db10
+
00db10
+	/* Align s to 16 byte.  */
00db10
+	risbgn	%r7,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
00db10
+	lghi	%r5,15		/* current_len = 15.  */
00db10
+	slr	%r5,%r7		/* Compute highest index to 16byte boundary.  */
00db10
+
00db10
+	/* Zero not found and n > loaded-byte-count.  */
00db10
+	vstl	%v16,%r5,0(%r2)	/* Copy loaded characters - no zero.  */
00db10
+	ahi	%r5,1		/* Start loop at next character.  */
00db10
+
00db10
+	/* Now we are 16byte aligned, so we can load
00db10
+	   a full vreg without page fault.  */
00db10
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
00db10
+	aghi	%r1,64
00db10
+	clgrjl	%r1,%r4,.Lloop64
00db10
+
00db10
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
00db10
+	clgijl	%r4,17,.Lremaining_v16	/* If n <=16, process remaining
00db10
+					   bytes.  */
00db10
+.Llt64:
00db10
+	lgr	%r7,%r4
00db10
+	slgfi	%r7,16		/* border_len = maxlen - 16.  */
00db10
+
00db10
+	clgrjhe	%r5,%r7,.Lremaining_v16 /* If current_len >= border
00db10
+					       then process remaining bytes.  */
00db10
+	vfenezfs %v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	je	.Lfound_v16	/* Jump away if zero was found.  */
00db10
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
00db10
+	vst	%v16,0(%r5,%r2)	/* Store previous part without zero to dst.  */
00db10
+	aghi	%r5,16
00db10
+
00db10
+	clgrjhe	%r5,%r7,.Lremaining_v18
00db10
+	vfenezfs %v17,%v18,%v18
00db10
+	je	.Lfound_v18
00db10
+	vl	%v16,16(%r5,%r3)
00db10
+	vst	%v18,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+
00db10
+	clgrjhe	%r5,%r7,.Lremaining_v16
00db10
+	vfenezfs %v17,%v16,%v16
00db10
+	je	.Lfound_v16
00db10
+	vl	%v18,16(%r5,%r3)
00db10
+	vst	%v16,0(%r5,%r2)
00db10
+	aghi	%r5,16
00db10
+
00db10
+.Lremaining_v18:
00db10
+	vlr	%v16,%v18
00db10
+.Lremaining_v16:
00db10
+	/* v16 contains the remaining bytes [1...16].
00db10
+	   Store remaining bytes and append string-termination.  */
00db10
+	vfenezf	%v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	slgrk	%r7,%r4,%r5	/* Remaining bytes = maxlen - current_len.  */
00db10
+	aghi	%r7,-1		/* vstl needs highest index.  */
00db10
+	la	%r2,0(%r5,%r2)	/* vstl has no index register.  */
00db10
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
00db10
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
00db10
+	/* Zero in remaining bytes? -> jump away (zero-index < max-index)
00db10
+	   Do not jump away if zero-index == max-index,
00db10
+	   but simply copy zero with vstl below.  */
00db10
+	clrjl	%r1,%r7,.Lfound_v16_store
00db10
+	vstl	%v16,%r7,0(%r2)	/* Store remaining bytes without null
00db10
+				   termination!.  */
00db10
+.Lend:
00db10
+	/* Restore saved registers.  */
00db10
+	vlgvg	%r6,%v31,0
00db10
+	vlgvg	%r7,%v31,1
00db10
+	lgr	%r2,%r0		/* Load saved dest-ptr.  */
00db10
+	br	%r14
00db10
+
00db10
+.Lfound_v16_32:
00db10
+	aghi	%r5,32
00db10
+	j	.Lfound_v16
00db10
+.Lfound_v18_48:
00db10
+	aghi	%r5,32
00db10
+.Lfound_v18_16:
00db10
+	aghi	%r5,16
00db10
+.Lfound_v18:
00db10
+	vlr	%v16,%v18
00db10
+.Lfound_v16:
00db10
+	/* v16 contains a zero. Store remaining bytes to zero. current_len
00db10
+	   has not reached border, thus checking for n is not needed! */
00db10
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
00db10
+	la	%r2,0(%r5,%r2)	/* vstl has no support for index-register.  */
00db10
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
00db10
+.Lfound_v16_store:
00db10
+	vstl	%v16,%r1,0(%r2)	/* Copy characters including zero.  */
00db10
+	/* Fill remaining bytes with zero - remaining count always > 0.  */
00db10
+	algr	%r5,%r1		/* Remaining bytes (=%r4) = ...  */
00db10
+	slgr	%r4,%r5		/* = maxlen - (currlen + zero_index + 1).  */
00db10
+	la	%r2,0(%r1,%r2)	/* Pointer to zero. start filling beyond.  */
00db10
+	aghi	%r4,-2		/* mvc with exrl needs count - 1.
00db10
+				   (additional -1, see remaining bytes above) */
00db10
+	srlg	%r6,%r4,8	/* Split into 256 byte blocks.  */
00db10
+	ltgr	%r6,%r6
00db10
+	je	.Lzero_lt256
00db10
+.Lzero_loop256:
00db10
+	mvc	1(256,%r2),0(%r2) /* Fill 256 zeros at once.  */
00db10
+	la	%r2,256(%r2)
00db10
+	brctg	%r6,.Lzero_loop256 /* Loop until all blocks are processed.  */
00db10
+.Lzero_lt256:
00db10
+	exrl	%r4,.Lmvc_lt256
00db10
+	j	.Lend
00db10
+.Lmvc_lt256:
00db10
+	mvc	1(1,%r2),0(%r2)
00db10
+
00db10
+	/* Find zero in 16byte aligned loop.  */
00db10
+.Lloop64:
00db10
+	vl	%v16,0(%r5,%r3) /* Load s.  */
00db10
+	vfenezfs %v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	je	.Lfound_v16	/* Jump away if zero was found.  */
00db10
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
00db10
+	vst	%v16,0(%r5,%r2)	/* Store previous part without zero to dst.  */
00db10
+	vfenezfs %v17,%v18,%v18
00db10
+	je	.Lfound_v18_16
00db10
+	vl	%v16,32(%r5,%r3)
00db10
+	vst	%v18,16(%r5,%r2)
00db10
+	vfenezfs %v17,%v16,%v16
00db10
+	je	.Lfound_v16_32
00db10
+	vl	%v18,48(%r5,%r3)
00db10
+	vst	%v16,32(%r5,%r2)
00db10
+	vfenezfs %v17,%v18,%v18
00db10
+	je	.Lfound_v18_48
00db10
+	vst	%v18,48(%r5,%r2)
00db10
+
00db10
+	aghi	%r5,64
00db10
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
00db10
+	aghi	%r1,64
00db10
+	clgrjl	%r1,%r4,.Lloop64
00db10
+
00db10
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
00db10
+	j	.Llt64
00db10
+
00db10
+.Lfallback:
00db10
+	jg	__wcsncpy_c
00db10
+END(__wcsncpy_vx)
00db10
+
00db10
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
00db10
diff --git a/sysdeps/s390/multiarch/wcsncpy.c b/sysdeps/s390/multiarch/wcsncpy.c
00db10
new file mode 100644
00db10
index 0000000..99aa344
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wcsncpy.c
00db10
@@ -0,0 +1,28 @@
00db10
+/* Multiple versions of wcsncpy.
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_ifunc (__wcsncpy)
00db10
+weak_alias (__wcsncpy, wcsncpy)
00db10
+
00db10
+#else
00db10
+# include <wcsmbs/wcsncpy.c>
00db10
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
00db10
diff --git a/sysdeps/s390/s390-32/multiarch/strncpy.c b/sysdeps/s390/s390-32/multiarch/strncpy.c
00db10
new file mode 100644
00db10
index 0000000..bc9c336
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/s390-32/multiarch/strncpy.c
00db10
@@ -0,0 +1,21 @@
00db10
+/* Multiple versions of strncpy.
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
+/* This wrapper-file is needed, because otherwise file
00db10
+   sysdeps/s390/s390-[32|64]/strncpy.S will be used.  */
00db10
+#include <sysdeps/s390/multiarch/strncpy.c>
00db10
diff --git a/sysdeps/s390/s390-64/multiarch/strncpy.c b/sysdeps/s390/s390-64/multiarch/strncpy.c
00db10
new file mode 100644
00db10
index 0000000..bc9c336
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/s390-64/multiarch/strncpy.c
00db10
@@ -0,0 +1,21 @@
00db10
+/* Multiple versions of strncpy.
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
+/* This wrapper-file is needed, because otherwise file
00db10
+   sysdeps/s390/s390-[32|64]/strncpy.S will be used.  */
00db10
+#include <sysdeps/s390/multiarch/strncpy.c>
00db10
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
00db10
index 3b91b6d..c26ab0c 100644
00db10
--- a/wcsmbs/Makefile
00db10
+++ b/wcsmbs/Makefile
00db10
@@ -42,7 +42,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
00db10
 	    mbrtoc16 c16rtomb
00db10
 
00db10
 strop-tests :=  wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
00db10
-		wcpcpy
00db10
+		wcpcpy wcsncpy
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-wcsncpy-ifunc.c b/wcsmbs/test-wcsncpy-ifunc.c
00db10
new file mode 100644
00db10
index 0000000..0141b38
00db10
--- /dev/null
00db10
+++ b/wcsmbs/test-wcsncpy-ifunc.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Test and measure IFUNC implementations of wcsncpy 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-wcsncpy.c"
00db10
diff --git a/wcsmbs/test-wcsncpy.c b/wcsmbs/test-wcsncpy.c
00db10
new file mode 100644
00db10
index 0000000..27de6f8
00db10
--- /dev/null
00db10
+++ b/wcsmbs/test-wcsncpy.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Test wcsncpy 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-strncpy.c"
00db10
diff --git a/wcsmbs/wcsncpy.c b/wcsmbs/wcsncpy.c
00db10
index f134c36..2e3cebe 100644
00db10
--- a/wcsmbs/wcsncpy.c
00db10
+++ b/wcsmbs/wcsncpy.c
00db10
@@ -18,6 +18,9 @@
00db10
 
00db10
 #include <wchar.h>
00db10
 
00db10
+#ifdef WCSNCPY
00db10
+# define __wcsncpy WCSNCPY
00db10
+#endif
00db10
 
00db10
 /* Copy no more than N wide-characters of SRC to DEST.	*/
00db10
 wchar_t *
00db10
@@ -83,4 +86,6 @@ __wcsncpy (dest, src, n)
00db10
 
00db10
   return s;
00db10
 }
00db10
+#ifndef WCSNCPY
00db10
 weak_alias (__wcsncpy, wcsncpy)
00db10
+#endif
00db10
-- 
00db10
2.3.0
00db10