olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone
ce426f
From 712d46fa89e1341b3bffc27ca2ab5d892e4b14e1 Mon Sep 17 00:00:00 2001
ce426f
From: Stefan Liebler <stli@linux.vnet.ibm.com>
ce426f
Date: Thu, 8 Oct 2015 11:16:05 +0200
ce426f
Subject: [PATCH 17/30] S390: Optimize strncat wcsncat.
ce426f
ce426f
upstream-commit-id: e1fe91180e4e29549f35f8ecd705b0bb4f208606
ce426f
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00162.html
ce426f
ce426f
This patch provides optimized versions of strncat and wcsncat with the z13
ce426f
vector instructions.
ce426f
ce426f
ChangeLog:
ce426f
ce426f
	* sysdeps/s390/multiarch/strncat-c.c: New File.
ce426f
	* sysdeps/s390/multiarch/strncat-vx.S: Likewise.
ce426f
	* sysdeps/s390/multiarch/strncat.c: Likewise.
ce426f
	* sysdeps/s390/multiarch/wcsncat-c.c: Likewise.
ce426f
	* sysdeps/s390/multiarch/wcsncat-vx.S: Likewise.
ce426f
	* sysdeps/s390/multiarch/wcsncat.c: Likewise.
ce426f
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add strncat and
ce426f
	wcsncat functions.
ce426f
	* sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
	(__libc_ifunc_impl_list): Add ifunc test for strncat, wcsncat.
ce426f
	* wcsmbs/wcsncat.c (WCSNCAT): Define and use macro.
ce426f
	* string/test-strncat.c: Add wcsncat support.
ce426f
	* wcsmbs/test-wcsncat.c: New File.
ce426f
	* wcsmbs/Makefile (strop-tests): Add wcsncat.
ce426f
	* benchtests/bench-strncat.c: Add wcsncat support.
ce426f
	* benchtests/bench-wcsncat.c: New File.
ce426f
	* benchtests/Makefile (wcsmbs-bench): Add wcsncat.
ce426f
---
ce426f
 benchtests/Makefile                      |   2 +-
ce426f
 benchtests/bench-strncat.c               |  99 +++++++-----
ce426f
 benchtests/bench-wcsncat.c               |  20 +++
ce426f
 string/test-strncat.c                    | 132 +++++++++------
ce426f
 sysdeps/s390/multiarch/Makefile          |   6 +-
ce426f
 sysdeps/s390/multiarch/ifunc-impl-list.c |   3 +
ce426f
 sysdeps/s390/multiarch/strncat-c.c       |  23 +++
ce426f
 sysdeps/s390/multiarch/strncat-vx.S      | 239 ++++++++++++++++++++++++++++
ce426f
 sysdeps/s390/multiarch/strncat.c         |  27 ++++
ce426f
 sysdeps/s390/multiarch/wcsncat-c.c       |  25 +++
ce426f
 sysdeps/s390/multiarch/wcsncat-vx.S      | 265 +++++++++++++++++++++++++++++++
ce426f
 sysdeps/s390/multiarch/wcsncat.c         |  27 ++++
ce426f
 wcsmbs/Makefile                          |   2 +-
ce426f
 wcsmbs/test-wcsncat-ifunc.c              |  20 +++
ce426f
 wcsmbs/test-wcsncat.c                    |  20 +++
ce426f
 wcsmbs/wcsncat.c                         |   5 +-
ce426f
 16 files changed, 823 insertions(+), 92 deletions(-)
ce426f
 create mode 100644 benchtests/bench-wcsncat.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/strncat-c.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/strncat-vx.S
ce426f
 create mode 100644 sysdeps/s390/multiarch/strncat.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/wcsncat-c.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/wcsncat-vx.S
ce426f
 create mode 100644 sysdeps/s390/multiarch/wcsncat.c
ce426f
 create mode 100644 wcsmbs/test-wcsncat-ifunc.c
ce426f
 create mode 100644 wcsmbs/test-wcsncat.c
ce426f
ce426f
diff --git a/benchtests/Makefile b/benchtests/Makefile
ce426f
index 91db23c..fd8b7ee 100644
ce426f
--- a/benchtests/Makefile
ce426f
+++ b/benchtests/Makefile
ce426f
@@ -38,7 +38,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
ce426f
 		strcat strchr strchrnul strcmp strcpy strcspn strlen \
ce426f
 		strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
ce426f
 		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
ce426f
-wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat
ce426f
+wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat
ce426f
 string-bench-all := $(string-bench) ${wcsmbs-bench}
ce426f
 
ce426f
 stdlib-bench := strtod
ce426f
diff --git a/benchtests/bench-strncat.c b/benchtests/bench-strncat.c
ce426f
index 2a17817..8f3339d 100644
ce426f
--- a/benchtests/bench-strncat.c
ce426f
+++ b/benchtests/bench-strncat.c
ce426f
@@ -1,5 +1,5 @@
ce426f
 /* Measure strncat functions.
ce426f
-   Copyright (C) 2013 Free Software Foundation, Inc.
ce426f
+   Copyright (C) 2013-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
@@ -17,33 +17,58 @@
ce426f
    <http://www.gnu.org/licenses/>.  */
ce426f
 
ce426f
 #define TEST_MAIN
ce426f
-#define TEST_NAME "strncat"
ce426f
+#ifndef WIDE
ce426f
+# define TEST_NAME "strncat"
ce426f
+#else
ce426f
+# define TEST_NAME "wcsncat"
ce426f
+#endif /* WIDE */
ce426f
 #include "bench-string.h"
ce426f
 
ce426f
-typedef char *(*proto_t) (char *, const char *, size_t);
ce426f
-char *stupid_strncat (char *, const char *, size_t);
ce426f
-char *simple_strncat (char *, const char *, size_t);
ce426f
-
ce426f
-IMPL (stupid_strncat, 0)
ce426f
-IMPL (strncat, 2)
ce426f
-
ce426f
-char *
ce426f
-stupid_strncat (char *dst, const char *src, size_t n)
ce426f
+#ifndef WIDE
ce426f
+# define STRNCAT strncat
ce426f
+# define CHAR char
ce426f
+# define SIMPLE_STRNCAT simple_strncat
ce426f
+# define STUPID_STRNCAT stupid_strncat
ce426f
+# define STRLEN strlen
ce426f
+# define MEMCMP memcmp
ce426f
+# define BIG_CHAR CHAR_MAX
ce426f
+# define SMALL_CHAR 127
ce426f
+#else
ce426f
+# include <wchar.h>
ce426f
+# define STRNCAT wcsncat
ce426f
+# define CHAR wchar_t
ce426f
+# define SIMPLE_STRNCAT simple_wcsncat
ce426f
+# define STUPID_STRNCAT stupid_wcsncat
ce426f
+# define STRLEN wcslen
ce426f
+# define MEMCMP wmemcmp
ce426f
+# define BIG_CHAR WCHAR_MAX
ce426f
+# define SMALL_CHAR 1273
ce426f
+#endif /* WIDE */
ce426f
+
ce426f
+typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
ce426f
+CHAR *STUPID_STRNCAT (CHAR *, const CHAR *, size_t);
ce426f
+CHAR *SIMPLE_STRNCAT (CHAR *, const CHAR *, size_t);
ce426f
+
ce426f
+IMPL (STUPID_STRNCAT, 0)
ce426f
+IMPL (STRNCAT, 2)
ce426f
+
ce426f
+CHAR *
ce426f
+STUPID_STRNCAT (CHAR *dst, const CHAR *src, size_t n)
ce426f
 {
ce426f
-  char *ret = dst;
ce426f
+  CHAR *ret = dst;
ce426f
   while (*dst++ != '\0');
ce426f
   --dst;
ce426f
   while (n--)
ce426f
-    if ( (*dst++ = *src++) == '\0')
ce426f
+    if ((*dst++ = *src++) == '\0')
ce426f
       return ret;
ce426f
   *dst = '\0';
ce426f
   return ret;
ce426f
 }
ce426f
 
ce426f
 static void
ce426f
-do_one_test (impl_t *impl, char *dst, const char *src, size_t n)
ce426f
+do_one_test (impl_t *impl, CHAR *dst, const CHAR *src, size_t n)
ce426f
 {
ce426f
-  size_t k = strlen (dst), i, iters = INNER_LOOP_ITERS;
ce426f
+  size_t k = STRLEN (dst), i, iters = INNER_LOOP_ITERS;
ce426f
   timing_t start, stop, cur;
ce426f
 
ce426f
   if (CALL (impl, dst, src, n) != dst)
ce426f
@@ -54,10 +79,10 @@ do_one_test (impl_t *impl, char *dst, const char *src, size_t n)
ce426f
       return;
ce426f
     }
ce426f
 
ce426f
-  size_t len = strlen (src);
ce426f
-  if (memcmp (dst + k, src, len + 1 > n ? n : len + 1) != 0)
ce426f
+  size_t len = STRLEN (src);
ce426f
+  if (MEMCMP (dst + k, src, len + 1 > n ? n : len + 1) != 0)
ce426f
     {
ce426f
-      error (0, 0, "Incorrect cancatination in function %s",
ce426f
+      error (0, 0, "Incorrect concatenation in function %s",
ce426f
 	     impl->name);
ce426f
       ret = 1;
ce426f
       return;
ce426f
@@ -88,20 +113,20 @@ do_test (size_t align1, size_t align2, size_t len1, size_t len2,
ce426f
 	 size_t n, int max_char)
ce426f
 {
ce426f
   size_t i;
ce426f
-  char *s1, *s2;
ce426f
+  CHAR *s1, *s2;
ce426f
 
ce426f
   align1 &= 7;
ce426f
-  if (align1 + len1 >= page_size)
ce426f
+  if ((align1 + len1) * sizeof (CHAR) >= page_size)
ce426f
     return;
ce426f
-  if (align1 + n > page_size)
ce426f
+  if ((align1 + n) * sizeof (CHAR) > page_size)
ce426f
     return;
ce426f
   align2 &= 7;
ce426f
-  if (align2 + len1 + len2 >= page_size)
ce426f
+  if ((align2 + len1 + len2) * sizeof (CHAR) >= page_size)
ce426f
     return;
ce426f
-  if (align2 + len1 + n > page_size)
ce426f
+  if ((align2 + len1 + n) * sizeof (CHAR) > page_size)
ce426f
     return;
ce426f
-  s1 = (char *) (buf1 + align1);
ce426f
-  s2 = (char *) (buf2 + align2);
ce426f
+  s1 = (CHAR *) (buf1) + align1;
ce426f
+  s2 = (CHAR *) (buf2) + align2;
ce426f
 
ce426f
   for (i = 0; i < len1; ++i)
ce426f
     s1[i] = 32 + 23 * i % (max_char - 32);
ce426f
@@ -136,25 +161,25 @@ main (void)
ce426f
 
ce426f
   for (n = 2; n <= 2048; n*=4)
ce426f
     {
ce426f
-      do_test (0, 2, 2, 2, n, 127);
ce426f
-      do_test (0, 0, 4, 4, n, 127);
ce426f
-      do_test (4, 0, 4, 4, n, 255);
ce426f
-      do_test (0, 0, 8, 8, n, 127);
ce426f
-      do_test (0, 8, 8, 8, n, 127);
ce426f
+      do_test (0, 2, 2, 2, n, SMALL_CHAR);
ce426f
+      do_test (0, 0, 4, 4, n, SMALL_CHAR);
ce426f
+      do_test (4, 0, 4, 4, n, BIG_CHAR);
ce426f
+      do_test (0, 0, 8, 8, n, SMALL_CHAR);
ce426f
+      do_test (0, 8, 8, 8, n, SMALL_CHAR);
ce426f
 
ce426f
       for (i = 1; i < 8; ++i)
ce426f
 	{
ce426f
-	  do_test (0, 0, 8 << i, 8 << i, n, 127);
ce426f
-	  do_test (8 - i, 2 * i, 8 << i, 8 << i, n, 127);
ce426f
-	  do_test (0, 0, 8 << i, 2 << i, n, 127);
ce426f
-	  do_test (8 - i, 2 * i, 8 << i, 2 << i, n, 127);
ce426f
+	  do_test (0, 0, 8 << i, 8 << i, n, SMALL_CHAR);
ce426f
+	  do_test (8 - i, 2 * i, 8 << i, 8 << i, n, SMALL_CHAR);
ce426f
+	  do_test (0, 0, 8 << i, 2 << i, n, SMALL_CHAR);
ce426f
+	  do_test (8 - i, 2 * i, 8 << i, 2 << i, n, SMALL_CHAR);
ce426f
 	}
ce426f
 
ce426f
       for (i = 1; i < 8; ++i)
ce426f
 	{
ce426f
-	  do_test (i, 2 * i, 8 << i, 1, n, 127);
ce426f
-	  do_test (2 * i, i, 8 << i, 1, n, 255);
ce426f
-	  do_test (i, i, 8 << i, 10, n, 127);
ce426f
+	  do_test (i, 2 * i, 8 << i, 1, n, SMALL_CHAR);
ce426f
+	  do_test (2 * i, i, 8 << i, 1, n, BIG_CHAR);
ce426f
+	  do_test (i, i, 8 << i, 10, n, SMALL_CHAR);
ce426f
 	}
ce426f
     }
ce426f
 
ce426f
diff --git a/benchtests/bench-wcsncat.c b/benchtests/bench-wcsncat.c
ce426f
new file mode 100644
ce426f
index 0000000..b9d7c3f
ce426f
--- /dev/null
ce426f
+++ b/benchtests/bench-wcsncat.c
ce426f
@@ -0,0 +1,20 @@
ce426f
+/* Measure wcsncat 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-strncat.c"
ce426f
diff --git a/string/test-strncat.c b/string/test-strncat.c
ce426f
index 2bfe25f..790d8aa 100644
ce426f
--- a/string/test-strncat.c
ce426f
+++ b/string/test-strncat.c
ce426f
@@ -17,33 +17,64 @@
ce426f
    <http://www.gnu.org/licenses/>.  */
ce426f
 
ce426f
 #define TEST_MAIN
ce426f
-#define TEST_NAME "strncat"
ce426f
+#ifndef WIDE
ce426f
+# define TEST_NAME "strncat"
ce426f
+#else
ce426f
+# define TEST_NAME "wcsncat"
ce426f
+#endif /* WIDE */
ce426f
 #include "test-string.h"
ce426f
 
ce426f
-typedef char *(*proto_t) (char *, const char *, size_t);
ce426f
-char *stupid_strncat (char *, const char *, size_t);
ce426f
-char *simple_strncat (char *, const char *, size_t);
ce426f
+#ifndef WIDE
ce426f
+# define STRNCAT strncat
ce426f
+# define CHAR char
ce426f
+# define UCHAR unsigned char
ce426f
+# define SIMPLE_STRNCAT simple_strncat
ce426f
+# define STUPID_STRNCAT stupid_strncat
ce426f
+# define STRLEN strlen
ce426f
+# define MEMSET memset
ce426f
+# define MEMCPY memcpy
ce426f
+# define MEMCMP memcmp
ce426f
+# define BIG_CHAR CHAR_MAX
ce426f
+# define SMALL_CHAR 127
ce426f
+#else
ce426f
+# include <wchar.h>
ce426f
+# define STRNCAT wcsncat
ce426f
+# define CHAR wchar_t
ce426f
+# define UCHAR wchar_t
ce426f
+# define SIMPLE_STRNCAT simple_wcsncat
ce426f
+# define STUPID_STRNCAT stupid_wcsncat
ce426f
+# define STRLEN wcslen
ce426f
+# define MEMSET wmemset
ce426f
+# define MEMCPY wmemcpy
ce426f
+# define MEMCMP wmemcmp
ce426f
+# define BIG_CHAR WCHAR_MAX
ce426f
+# define SMALL_CHAR 1273
ce426f
+#endif /* WIDE */
ce426f
 
ce426f
-IMPL (stupid_strncat, 0)
ce426f
-IMPL (strncat, 2)
ce426f
+typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
ce426f
+CHAR *STUPID_STRNCAT (CHAR *, const CHAR *, size_t);
ce426f
+CHAR *SIMPLE_STRNCAT (CHAR *, const CHAR *, size_t);
ce426f
 
ce426f
-char *
ce426f
-stupid_strncat (char *dst, const char *src, size_t n)
ce426f
+IMPL (STUPID_STRNCAT, 0)
ce426f
+IMPL (STRNCAT, 2)
ce426f
+
ce426f
+CHAR *
ce426f
+STUPID_STRNCAT (CHAR *dst, const CHAR *src, size_t n)
ce426f
 {
ce426f
-  char *ret = dst;
ce426f
+  CHAR *ret = dst;
ce426f
   while (*dst++ != '\0');
ce426f
   --dst;
ce426f
   while (n--)
ce426f
-    if ( (*dst++ = *src++) == '\0')
ce426f
+    if ((*dst++ = *src++) == '\0')
ce426f
       return ret;
ce426f
   *dst = '\0';
ce426f
   return ret;
ce426f
 }
ce426f
 
ce426f
 static void
ce426f
-do_one_test (impl_t *impl, char *dst, const char *src, size_t n)
ce426f
+do_one_test (impl_t *impl, CHAR *dst, const CHAR *src, size_t n)
ce426f
 {
ce426f
-  size_t k = strlen (dst);
ce426f
+  size_t k = STRLEN (dst);
ce426f
   if (CALL (impl, dst, src, n) != dst)
ce426f
     {
ce426f
       error (0, 0, "Wrong result in function %s %p != %p", impl->name,
ce426f
@@ -52,10 +83,10 @@ do_one_test (impl_t *impl, char *dst, const char *src, size_t n)
ce426f
       return;
ce426f
     }
ce426f
 
ce426f
-  size_t len = strlen (src);
ce426f
-  if (memcmp (dst + k, src, len + 1 > n ? n : len + 1) != 0)
ce426f
+  size_t len = STRLEN (src);
ce426f
+  if (MEMCMP (dst + k, src, len + 1 > n ? n : len + 1) != 0)
ce426f
     {
ce426f
-      error (0, 0, "Incorrect cancatination in function %s",
ce426f
+      error (0, 0, "Incorrect concatenation in function %s",
ce426f
 	     impl->name);
ce426f
       ret = 1;
ce426f
       return;
ce426f
@@ -74,20 +105,20 @@ do_test (size_t align1, size_t align2, size_t len1, size_t len2,
ce426f
 	 size_t n, int max_char)
ce426f
 {
ce426f
   size_t i;
ce426f
-  char *s1, *s2;
ce426f
+  CHAR *s1, *s2;
ce426f
 
ce426f
   align1 &= 7;
ce426f
-  if (align1 + len1 >= page_size)
ce426f
+  if ((align1 + len1) * sizeof (CHAR) >= page_size)
ce426f
     return;
ce426f
-  if (align1 + n > page_size)
ce426f
+  if ((align1 + n) * sizeof (CHAR) > page_size)
ce426f
     return;
ce426f
   align2 &= 7;
ce426f
-  if (align2 + len1 + len2 >= page_size)
ce426f
+  if ((align2 + len1 + len2) * sizeof (CHAR) >= page_size)
ce426f
     return;
ce426f
-  if (align2 + len1 + n > page_size)
ce426f
+  if ((align2 + len1 + n) * sizeof (CHAR) > page_size)
ce426f
     return;
ce426f
-  s1 = (char *) (buf1 + align1);
ce426f
-  s2 = (char *) (buf2 + align2);
ce426f
+  s1 = (CHAR *) (buf1) + align1;
ce426f
+  s2 = (CHAR *) (buf2) + align2;
ce426f
 
ce426f
   for (i = 0; i < len1; ++i)
ce426f
     s1[i] = 32 + 23 * i % (max_char - 32);
ce426f
@@ -107,9 +138,10 @@ static void
ce426f
 do_random_tests (void)
ce426f
 {
ce426f
   size_t i, j, n, align1, align2, len1, len2, N;
ce426f
-  unsigned char *p1 = buf1 + page_size - 512;
ce426f
-  unsigned char *p2 = buf2 + page_size - 512;
ce426f
-  unsigned char *res;
ce426f
+  UCHAR *p1 = (UCHAR *) (buf1 + page_size) - 512;
ce426f
+  UCHAR *p2 = (UCHAR *) (buf2 + page_size) - 512;
ce426f
+  UCHAR *p3 = (UCHAR *) buf1;
ce426f
+  UCHAR *res;
ce426f
   fprintf (stdout, "Number of iterations in random test = %zd\n",
ce426f
 	   ITERATIONS);
ce426f
   for (n = 0; n < ITERATIONS; n++)
ce426f
@@ -148,26 +180,26 @@ do_random_tests (void)
ce426f
 	    p1[i] = 0;
ce426f
 	  else
ce426f
 	    {
ce426f
-	      p1[i] = random () & 255;
ce426f
+	      p1[i] = random () & BIG_CHAR;
ce426f
 	      if (i >= align1 && i < len1 + align1 && !p1[i])
ce426f
-		p1[i] = (random () & 127) + 3;
ce426f
+		p1[i] = (random () & SMALL_CHAR) + 3;
ce426f
 	    }
ce426f
 	}
ce426f
       for (i = 0; i < len2; i++)
ce426f
 	{
ce426f
-	  buf1[i] = random () & 255;
ce426f
-	  if (!buf1[i])
ce426f
-	    buf1[i] = (random () & 127) + 3;
ce426f
+	  p3[i] = random () & BIG_CHAR;
ce426f
+	  if (!p3[i])
ce426f
+	    p3[i] = (random () & SMALL_CHAR) + 3;
ce426f
 	}
ce426f
-      buf1[len2] = 0;
ce426f
+      p3[len2] = 0;
ce426f
 
ce426f
       FOR_EACH_IMPL (impl, 1)
ce426f
 	{
ce426f
-	  memset (p2 - 64, '\1', align2 + 64);
ce426f
-	  memset (p2 + align2 + len2 + 1, '\1', 512 - align2 - len2 - 1);
ce426f
-	  memcpy (p2 + align2, buf1, len2 + 1);
ce426f
-	  res = (unsigned char *) CALL (impl, (char *) (p2 + align2),
ce426f
-					(char *) (p1 + align1), N);
ce426f
+	  MEMSET (p2 - 64, '\1', align2 + 64);
ce426f
+	  MEMSET (p2 + align2 + len2 + 1, '\1', 512 - align2 - len2 - 1);
ce426f
+	  MEMCPY (p2 + align2, p3, len2 + 1);
ce426f
+	  res = (UCHAR *) CALL (impl, (CHAR *) (p2 + align2),
ce426f
+				(CHAR *) (p1 + align1), N);
ce426f
 	  if (res != p2 + align2)
ce426f
 	    {
ce426f
 	      error (0, 0, "Iteration %zd - wrong result in function %s "
ce426f
@@ -187,7 +219,7 @@ do_random_tests (void)
ce426f
 		  break;
ce426f
 		}
ce426f
 	    }
ce426f
-	  if (memcmp (p2 + align2, buf1, len2))
ce426f
+	  if (MEMCMP (p2 + align2, p3, len2))
ce426f
 	    {
ce426f
 	      error (0, 0, "Iteration %zd - garbage in string before, %s "
ce426f
 		     "(%zd, %zd, %zd, %zd, %zd)",
ce426f
@@ -220,7 +252,7 @@ do_random_tests (void)
ce426f
 		  ret = 1;
ce426f
 		}
ce426f
 	    }
ce426f
-	  if (memcmp (p1 + align1, p2 + align2 + len2,
ce426f
+	  if (MEMCMP (p1 + align1, p2 + align2 + len2,
ce426f
 		      (len1 + 1) > N ? N : len1 + 1))
ce426f
 	    {
ce426f
 	      error (0, 0, "Iteration %zd - different strings, %s "
ce426f
@@ -246,25 +278,25 @@ main (void)
ce426f
 
ce426f
   for (n = 2; n <= 2048; n*=4)
ce426f
     {
ce426f
-      do_test (0, 2, 2, 2, n, 127);
ce426f
-      do_test (0, 0, 4, 4, n, 127);
ce426f
-      do_test (4, 0, 4, 4, n, 255);
ce426f
-      do_test (0, 0, 8, 8, n, 127);
ce426f
-      do_test (0, 8, 8, 8, n, 127);
ce426f
+      do_test (0, 2, 2, 2, n, SMALL_CHAR);
ce426f
+      do_test (0, 0, 4, 4, n, SMALL_CHAR);
ce426f
+      do_test (4, 0, 4, 4, n, BIG_CHAR);
ce426f
+      do_test (0, 0, 8, 8, n, SMALL_CHAR);
ce426f
+      do_test (0, 8, 8, 8, n, SMALL_CHAR);
ce426f
 
ce426f
       for (i = 1; i < 8; ++i)
ce426f
 	{
ce426f
-	  do_test (0, 0, 8 << i, 8 << i, n, 127);
ce426f
-	  do_test (8 - i, 2 * i, 8 << i, 8 << i, n, 127);
ce426f
-	  do_test (0, 0, 8 << i, 2 << i, n, 127);
ce426f
-	  do_test (8 - i, 2 * i, 8 << i, 2 << i, n, 127);
ce426f
+	  do_test (0, 0, 8 << i, 8 << i, n, SMALL_CHAR);
ce426f
+	  do_test (8 - i, 2 * i, 8 << i, 8 << i, n, SMALL_CHAR);
ce426f
+	  do_test (0, 0, 8 << i, 2 << i, n, SMALL_CHAR);
ce426f
+	  do_test (8 - i, 2 * i, 8 << i, 2 << i, n, SMALL_CHAR);
ce426f
 	}
ce426f
 
ce426f
       for (i = 1; i < 8; ++i)
ce426f
 	{
ce426f
-	  do_test (i, 2 * i, 8 << i, 1, n, 127);
ce426f
-	  do_test (2 * i, i, 8 << i, 1, n, 255);
ce426f
-	  do_test (i, i, 8 << i, 10, n, 127);
ce426f
+	  do_test (i, 2 * i, 8 << i, 1, n, SMALL_CHAR);
ce426f
+	  do_test (2 * i, i, 8 << i, 1, n, BIG_CHAR);
ce426f
+	  do_test (i, i, 8 << i, 10, n, SMALL_CHAR);
ce426f
 	}
ce426f
     }
ce426f
 
ce426f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
ce426f
index 6283999..33c1398 100644
ce426f
--- a/sysdeps/s390/multiarch/Makefile
ce426f
+++ b/sysdeps/s390/multiarch/Makefile
ce426f
@@ -5,7 +5,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
ce426f
 		   stpcpy stpcpy-vx stpcpy-c \
ce426f
 		   strncpy strncpy-vx \
ce426f
 		   stpncpy stpncpy-vx stpncpy-c \
ce426f
-		   strcat strcat-vx strcat-c
ce426f
+		   strcat strcat-vx strcat-c \
ce426f
+		   strncat strncat-vx strncat-c
ce426f
 endif
ce426f
 
ce426f
 ifeq ($(subdir),wcsmbs)
ce426f
@@ -15,5 +16,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
ce426f
 		   wcpcpy wcpcpy-vx wcpcpy-c \
ce426f
 		   wcsncpy wcsncpy-vx wcsncpy-c \
ce426f
 		   wcpncpy wcpncpy-vx wcpncpy-c \
ce426f
-		   wcscat wcscat-vx wcscat-c
ce426f
+		   wcscat wcscat-vx wcscat-c \
ce426f
+		   wcsncat wcsncat-vx wcsncat-c
ce426f
 endif
ce426f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
index ccf4dea..1e57c0e 100644
ce426f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
@@ -100,6 +100,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
ce426f
   IFUNC_VX_IMPL (strcat);
ce426f
   IFUNC_VX_IMPL (wcscat);
ce426f
 
ce426f
+  IFUNC_VX_IMPL (strncat);
ce426f
+  IFUNC_VX_IMPL (wcsncat);
ce426f
+
ce426f
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
ce426f
 
ce426f
   return i;
ce426f
diff --git a/sysdeps/s390/multiarch/strncat-c.c b/sysdeps/s390/multiarch/strncat-c.c
ce426f
new file mode 100644
ce426f
index 0000000..f90f0e0
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/strncat-c.c
ce426f
@@ -0,0 +1,23 @@
ce426f
+/* Default strncat 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 STRNCAT  __strncat_c
ce426f
+
ce426f
+# include <string/strncat.c>
ce426f
+#endif
ce426f
diff --git a/sysdeps/s390/multiarch/strncat-vx.S b/sysdeps/s390/multiarch/strncat-vx.S
ce426f
new file mode 100644
ce426f
index 0000000..7f35696
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/strncat-vx.S
ce426f
@@ -0,0 +1,239 @@
ce426f
+/* Vector optimized 32/64 bit S/390 version of strncat.
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
+/* char * strncat (const char *dest, const char *src, size_t n)
ce426f
+   Concatenate two strings - at most n characters of src.
ce426f
+
ce426f
+   Register usage:
ce426f
+   -r0=saved dest pointer for return
ce426f
+   -r1=tmp
ce426f
+   -r2=dest
ce426f
+   -r3=src
ce426f
+   -r4=n
ce426f
+   -r5=current_len
ce426f
+   -r6=tmp
ce426f
+   -r7=tmp
ce426f
+   -v16=part of src
ce426f
+   -v17=index of zero
ce426f
+   -v18=part of src
ce426f
+   -v31=register save area for r6, r7
ce426f
+*/
ce426f
+ENTRY(__strncat_vx)
ce426f
+	.machine "z13"
ce426f
+	.machinemode "zarch_nohighgprs"
ce426f
+
ce426f
+# if !defined __s390x__
ce426f
+	llgfr	%r4,%r4
ce426f
+# endif /* !defined __s390x__ */
ce426f
+
ce426f
+	clgfi	%r4,0
ce426f
+	ber	%r14		/* Nothing to do, if n == 0.  */
ce426f
+	lgr	%r0,%r2		/* Save destination pointer for return.  */
ce426f
+	vlvgp	%v31,%r6,%r7	/* Save registers.  */
ce426f
+
ce426f
+	/* STRLEN
ce426f
+	   %r1 = loaded bytes (tmp)
ce426f
+	   %r6 = zero byte index (tmp)
ce426f
+	   %r2 = dst
ce426f
+	*/
ce426f
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
ce426f
+	lcbb	%r1,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
ce426f
+
ce426f
+	vfenezb	%v16,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	vlgvb	%r5,%v16,7	/* Load zero index or 16 if not found.  */
ce426f
+	clrjl	%r5,%r1,.Llen_end /* Found zero within loaded bytes, end.  */
ce426f
+
ce426f
+	/* Align s to 16 byte.  */
ce426f
+	risbgn	%r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
ce426f
+	lghi	%r5,16		/* current_len = 16.  */
ce426f
+	slr	%r5,%r1		/* Compute bytes to 16bytes boundary.  */
ce426f
+
ce426f
+	/* Find zero in 16byte aligned loop.  */
ce426f
+.Llen_loop:
ce426f
+	vl	%v16,0(%r5,%r2)	/* Load s.  */
ce426f
+	vfenezbs %v16,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	je	.Llen_found	/* Jump away if zero was found.  */
ce426f
+	vl	%v16,16(%r5,%r2)
ce426f
+	vfenezbs %v16,%v16,%v16
ce426f
+	je	.Llen_found16
ce426f
+	vl	%v16,32(%r5,%r2)
ce426f
+	vfenezbs %v16,%v16,%v16
ce426f
+	je	.Llen_found32
ce426f
+	vl	%v16,48(%r5,%r2)
ce426f
+	vfenezbs %v16,%v16,%v16
ce426f
+	je	.Llen_found48
ce426f
+
ce426f
+	aghi	%r5,64
ce426f
+	j	.Llen_loop	/* No zero -> loop.  */
ce426f
+
ce426f
+.Llen_found48:
ce426f
+	aghi	%r5,16
ce426f
+.Llen_found32:
ce426f
+	aghi	%r5,16
ce426f
+.Llen_found16:
ce426f
+	aghi	%r5,16
ce426f
+.Llen_found:
ce426f
+	vlgvb	%r1,%v16,7	/* Load byte index of zero.  */
ce426f
+	algr	%r5,%r1
ce426f
+
ce426f
+.Llen_end:
ce426f
+	/* STRCPY
ce426f
+	   %r1 = zero byte index (tmp)
ce426f
+	   %r6 = loaded bytes (tmp)
ce426f
+	   %r3 = curr src pointer
ce426f
+	   %r2 = curr dst pointer
ce426f
+	   %r7 = border, tmp
ce426f
+	*/
ce426f
+	la	%r2,0(%r5,%r2)	/* strcpy at end of dst-string.  */
ce426f
+
ce426f
+	vlbb	%v16,0(%r3),6	/* Load s until next 4k-byte boundary.  */
ce426f
+	lcbb	%r6,0(%r3),6	/* Get bytes to 4k-byte boundary or 16.  */
ce426f
+	llgfr	%r6,%r6		/* Convert 32bit to 64bit.  */
ce426f
+
ce426f
+	lghi	%r5,0		/* current_len = 0.  */
ce426f
+
ce426f
+	clgrjle	%r4,%r6,.Lcpy_remaining_v16 /* If n <= loaded-bytes
ce426f
+					       -> process remaining.  */
ce426f
+
ce426f
+	/* n > loaded-byte-count.  */
ce426f
+	vfenezb	%v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
ce426f
+	clrjl	%r1,%r6,.Lcpy_found_v16_store /* Found zero within loaded
ce426f
+						 bytes, copy and return.  */
ce426f
+
ce426f
+	/* Align s to 16 byte.  */
ce426f
+	risbgn	%r7,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
ce426f
+	lghi	%r5,15		/* current_len = 15.  */
ce426f
+	slr	%r5,%r7		/* Compute highest index to 16byte boundary.  */
ce426f
+
ce426f
+	/* Zero not found and n > loaded-byte-count.  */
ce426f
+	vstl	%v16,%r5,0(%r2)	/* Copy loaded characters - no zero.  */
ce426f
+	ahi	%r5,1		/* Start loop at next character.  */
ce426f
+
ce426f
+	/*
ce426f
+	  Now we are 16byte aligned, so we can load a full vreg
ce426f
+	  without page fault.
ce426f
+	 */
ce426f
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
ce426f
+	aghi	%r1,64
ce426f
+	clgrjl	%r1,%r4,.Lcpy_loop64
ce426f
+
ce426f
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
ce426f
+	clgijl	%r4,17,.Lcpy_remaining_v16 /* If n <=16,
ce426f
+					       process remaining bytes.  */
ce426f
+.Lcpy_lt64:
ce426f
+	lgr	%r7,%r4
ce426f
+	slgfi	%r7,16		/* border_len = n - 16.  */
ce426f
+
ce426f
+	/* If current_len >= border then process remaining bytes.  */
ce426f
+	clgrjhe	%r5,%r7,.Lcpy_remaining_v16
ce426f
+	vfenezbs %v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	je	.Lcpy_found_v16 /* Jump away if zero was found.  */
ce426f
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
ce426f
+	vst	%v16,0(%r5,%r2)	/* Store previous part without zero to dst.  */
ce426f
+	aghi	%r5,16
ce426f
+
ce426f
+	clgrjhe	%r5,%r7,.Lcpy_remaining_v18
ce426f
+	vfenezbs %v17,%v18,%v18
ce426f
+	je	.Lcpy_found_v18
ce426f
+	vl	%v16,16(%r5,%r3)
ce426f
+	vst	%v18,0(%r5,%r2)
ce426f
+	aghi	%r5,16
ce426f
+
ce426f
+	clgrjhe	%r5,%r7,.Lcpy_remaining_v16
ce426f
+	vfenezbs %v17,%v16,%v16
ce426f
+	je	.Lcpy_found_v16
ce426f
+	vl	%v18,16(%r5,%r3)
ce426f
+	vst	%v16,0(%r5,%r2)
ce426f
+	aghi	%r5,16
ce426f
+
ce426f
+.Lcpy_remaining_v18:
ce426f
+	vlr	%v16,%v18
ce426f
+.Lcpy_remaining_v16:
ce426f
+	/* v16 contains the remaining bytes [1...16].
ce426f
+	   Store remaining bytes and append string-termination.  */
ce426f
+	vfenezb	%v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	slgrk	%r7,%r4,%r5	/* Remaining bytes = maxlen - current_len.  */
ce426f
+	aghi	%r7,-1		/* vstl needs highest index.  */
ce426f
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
ce426f
+	la	%r2,0(%r5,%r2)	/* vstl has no index register.  */
ce426f
+	/* Zero-index within remaining-bytes, store up to zero and end.  */
ce426f
+	clgrjle	%r1,%r7,.Lcpy_found_v16_store
ce426f
+	vstl	%v16,%r7,0(%r2)	/* Store remaining bytes.  */
ce426f
+	lghi	%r1,0
ce426f
+	stc	%r1,1(%r7,%r2)	/* Store string-null-termination beyond n.  */
ce426f
+.Lcpy_end:
ce426f
+	/* Restore saved registers.  */
ce426f
+	vlgvg	%r6,%v31,0
ce426f
+	vlgvg	%r7,%v31,1
ce426f
+	lgr	%r2,%r0		/* Load saved dest-ptr.  */
ce426f
+	br	%r14
ce426f
+
ce426f
+.Lcpy_found_v16_32:
ce426f
+	aghi	%r5,32
ce426f
+	j	.Lcpy_found_v16
ce426f
+.Lcpy_found_v18_48:
ce426f
+	aghi	%r5,32
ce426f
+.Lcpy_found_v18_16:
ce426f
+	aghi	%r5,16
ce426f
+.Lcpy_found_v18:
ce426f
+	vlr	%v16,%v18
ce426f
+.Lcpy_found_v16:
ce426f
+	/* v16 contains a zero. Store remaining bytes to zero. current_len
ce426f
+	   has not reached border, thus checking for n is not needed!  */
ce426f
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
ce426f
+	la	%r2,0(%r5,%r2)
ce426f
+.Lcpy_found_v16_store:
ce426f
+	vstl	%v16,%r1,0(%r2)	/* Copy characters including zero.  */
ce426f
+	j	.Lcpy_end
ce426f
+
ce426f
+	/* Find zero in 16byte aligned loop.  */
ce426f
+.Lcpy_loop64:
ce426f
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
ce426f
+	vfenezbs %v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	je	.Lcpy_found_v16 /* Jump away if zero was found.  */
ce426f
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
ce426f
+	vst	%v16,0(%r5,%r2)	/* Store previous part without zero to dst.  */
ce426f
+	vfenezbs %v17,%v18,%v18
ce426f
+	je	.Lcpy_found_v18_16
ce426f
+	vl	%v16,32(%r5,%r3)
ce426f
+	vst	%v18,16(%r5,%r2)
ce426f
+	vfenezbs %v17,%v16,%v16
ce426f
+	je	.Lcpy_found_v16_32
ce426f
+	vl	%v18,48(%r5,%r3)
ce426f
+	vst	%v16,32(%r5,%r2)
ce426f
+	vfenezbs %v17,%v18,%v18
ce426f
+	je	.Lcpy_found_v18_48
ce426f
+	vst	%v18,48(%r5,%r2)
ce426f
+
ce426f
+	aghi	%r5,64
ce426f
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
ce426f
+	aghi	%r1,64
ce426f
+	clgrjl	%r1,%r4,.Lcpy_loop64
ce426f
+
ce426f
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
ce426f
+	j	.Lcpy_lt64
ce426f
+END(__strncat_vx)
ce426f
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
ce426f
diff --git a/sysdeps/s390/multiarch/strncat.c b/sysdeps/s390/multiarch/strncat.c
ce426f
new file mode 100644
ce426f
index 0000000..82e87ad
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/strncat.c
ce426f
@@ -0,0 +1,27 @@
ce426f
+/* Multiple versions of strncat.
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 <string.h>
ce426f
+# include <ifunc-resolve.h>
ce426f
+
ce426f
+s390_vx_libc_ifunc2 (__strncat, strncat)
ce426f
+
ce426f
+#else
ce426f
+# include <string/strncat.c>
ce426f
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
ce426f
diff --git a/sysdeps/s390/multiarch/wcsncat-c.c b/sysdeps/s390/multiarch/wcsncat-c.c
ce426f
new file mode 100644
ce426f
index 0000000..4938ef2
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/wcsncat-c.c
ce426f
@@ -0,0 +1,25 @@
ce426f
+/* Default wcsncat 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 WCSNCAT  __wcsncat_c
ce426f
+
ce426f
+# include <wchar.h>
ce426f
+extern __typeof (wcsncat) __wcsncat_c;
ce426f
+# include <wcsmbs/wcsncat.c>
ce426f
+#endif
ce426f
diff --git a/sysdeps/s390/multiarch/wcsncat-vx.S b/sysdeps/s390/multiarch/wcsncat-vx.S
ce426f
new file mode 100644
ce426f
index 0000000..7e0653e
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/wcsncat-vx.S
ce426f
@@ -0,0 +1,265 @@
ce426f
+/* Vector optimized 32/64 bit S/390 version of wcsncat.
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 * wcsncat (wchar_t *dest, const wchar_t *src, size_t n)
ce426f
+   Concatenate two strings - at most n characters of src.
ce426f
+
ce426f
+   Register usage:
ce426f
+   -r0=saved dest pointer for return
ce426f
+   -r1=tmp
ce426f
+   -r2=dest
ce426f
+   -r3=src
ce426f
+   -r4=n
ce426f
+   -r5=current_len
ce426f
+   -r6=tmp
ce426f
+   -r7=tmp
ce426f
+   -v16=part of src
ce426f
+   -v17=index of zero
ce426f
+   -v18=part of src
ce426f
+   -v31=register save area for r6, r7
ce426f
+*/
ce426f
+ENTRY(__wcsncat_vx)
ce426f
+	.machine "z13"
ce426f
+	.machinemode "zarch_nohighgprs"
ce426f
+
ce426f
+# if !defined __s390x__
ce426f
+	llgfr	%r4,%r4
ce426f
+# endif /* !defined __s390x__ */
ce426f
+
ce426f
+	clgfi	%r4,0
ce426f
+	ber	%r14		/* Nothing to do, if n == 0.  */
ce426f
+
ce426f
+	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
ce426f
+	lcbb	%r1,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
ce426f
+
ce426f
+	/* If either src or dest is not 4byte aligned, use __wcsncat_c.  */
ce426f
+	tmll	%r2,3		/* Test if s is 4-byte aligned?   */
ce426f
+	jne	.Lfallback	/* And use common-code variant if not.  */
ce426f
+	tmll	%r3,3		/* Test if src is 4-byte aligned?   */
ce426f
+	jne	.Lfallback	/* And use common-code variant if not.  */
ce426f
+
ce426f
+	lgr	%r0,%r2		/* Save destination pointer for return.  */
ce426f
+	vlvgp	%v31,%r6,%r7	/* Save registers.  */
ce426f
+
ce426f
+	/* WCSLEN
ce426f
+	   %r1 = loaded bytes (tmp)
ce426f
+	   %r6 = zero byte index (tmp)
ce426f
+	   %r2 = dst
ce426f
+	*/
ce426f
+	vfenezf	%v16,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	vlgvb	%r5,%v16,7	/* Load zero index or 16 if not found.  */
ce426f
+	clrjl	%r5,%r1,.Llen_end /* Found zero within loaded bytes, end.  */
ce426f
+
ce426f
+	/* Align s to 16 byte.  */
ce426f
+	risbgn	%r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
ce426f
+	lghi	%r5,16		/* current_len = 16.  */
ce426f
+	slr	%r5,%r1		/* Compute bytes to 16bytes boundary.  */
ce426f
+
ce426f
+	/* Find zero in 16byte aligned loop.  */
ce426f
+.Llen_loop:
ce426f
+	vl	%v16,0(%r5,%r2)	/* Load s.  */
ce426f
+	vfenezfs %v16,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	je	.Llen_found	/* Jump away if zero was found.  */
ce426f
+	vl	%v16,16(%r5,%r2)
ce426f
+	vfenezfs %v16,%v16,%v16
ce426f
+	je	.Llen_found16
ce426f
+	vl	%v16,32(%r5,%r2)
ce426f
+	vfenezfs %v16,%v16,%v16
ce426f
+	je	.Llen_found32
ce426f
+	vl	%v16,48(%r5,%r2)
ce426f
+	vfenezfs %v16,%v16,%v16
ce426f
+	je	.Llen_found48
ce426f
+
ce426f
+	aghi	%r5,64
ce426f
+	j	.Llen_loop	/* No zero -> loop.  */
ce426f
+
ce426f
+.Llen_found48:
ce426f
+	aghi	%r5,16
ce426f
+.Llen_found32:
ce426f
+	aghi	%r5,16
ce426f
+.Llen_found16:
ce426f
+	aghi	%r5,16
ce426f
+.Llen_found:
ce426f
+	vlgvb	%r1,%v16,7	/* Load byte index of zero.  */
ce426f
+	algr	%r5,%r1
ce426f
+
ce426f
+.Llen_end:
ce426f
+	/* WCSNCPY
ce426f
+	   %r1 = zero byte index (tmp)
ce426f
+	   %r6 = loaded bytes (tmp)
ce426f
+	   %r3 = curr src pointer
ce426f
+	   %r2 = curr dst pointer
ce426f
+	   %r7 = border, tmp
ce426f
+	*/
ce426f
+	la	%r2,0(%r5,%r2)	/* strcpy at end of dst-string.  */
ce426f
+
ce426f
+	vlbb	%v16,0(%r3),6	/* Load s until next 4k-byte boundary.  */
ce426f
+	lcbb	%r6,0(%r3),6	/* Get bytes to 4k-byte boundary or 16.  */
ce426f
+	llgfr	%r6,%r6		/* Convert 32bit to 64bit.  */
ce426f
+
ce426f
+	lghi	%r5,0		/* current_len = 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	%r1,-4		/* Max byte-count is 18446744073709551612.  */
ce426f
+# else
ce426f
+	tmlh	%r4,49152	/* Test bit 0 or 1 of maxlen.  */
ce426f
+	llilf	%r1,4294967292	/* Max byte-count is 4294967292.  */
ce426f
+# endif /* !__s390x__ */
ce426f
+	sllg	%r4,%r4,2	/* Convert character-count to byte-count.  */
ce426f
+	locgrne	%r4,%r1		/* Use max byte-count, if bit 0/1 was one.  */
ce426f
+
ce426f
+	clgrjle	%r4,%r6,.Lcpy_remaining_v16 /* If n <= loaded-bytes
ce426f
+					       -> process remaining.  */
ce426f
+
ce426f
+	/* n > loaded-byte-count.  */
ce426f
+	vfenezf	%v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
ce426f
+	clrjl	%r1,%r6,.Lcpy_found_v16_store /* Found zero within loaded bytes,
ce426f
+					         copy and return.  */
ce426f
+
ce426f
+	/* Align s to 16 byte.  */
ce426f
+	risbgn	%r1,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
ce426f
+	lghi	%r5,15		/* current_len = 15.  */
ce426f
+	slr	%r5,%r1		/* Compute highest index to 16byte boundary.  *
ce426f
+
ce426f
+	/* Zero not found and maxlen > loaded-byte-count.  */
ce426f
+	vstl	%v16,%r5,0(%r2)	/* Copy loaded characters - no zero.  */
ce426f
+	ahi	%r5,1		/* Start loop at next character.  */
ce426f
+
ce426f
+	/*
ce426f
+	  Now we are 16byte aligned, so we can load a full vreg
ce426f
+	  without page fault.
ce426f
+	 */
ce426f
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
ce426f
+	aghi	%r1,64
ce426f
+	clgrjl	%r1,%r4,.Lcpy_loop64
ce426f
+
ce426f
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
ce426f
+	clgijl	%r4,17,.Lcpy_remaining_v16 /* If n <=16,
ce426f
+					       process remaining bytes.  */
ce426f
+.Lcpy_lt64:
ce426f
+	lgr	%r7,%r4
ce426f
+	slgfi	%r7,16		/* border_len = n - 16.  */
ce426f
+
ce426f
+	clgrjhe	%r5,%r7,.Lcpy_remaining_v16
ce426f
+	vfenezfs %v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	je	.Lcpy_found_v16 /* Jump away if zero was found.  */
ce426f
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
ce426f
+	vst	%v16,0(%r5,%r2)	/* Save previous part without zero to dst.  */
ce426f
+	aghi	%r5,16
ce426f
+
ce426f
+	clgrjhe	%r5,%r7,.Lcpy_remaining_v18
ce426f
+	vfenezfs %v17,%v18,%v18
ce426f
+	je	.Lcpy_found_v18
ce426f
+	vl	%v16,16(%r5,%r3)
ce426f
+	vst	%v18,0(%r5,%r2)
ce426f
+	aghi	%r5,16
ce426f
+
ce426f
+	clgrjhe	%r5,%r7,.Lcpy_remaining_v16
ce426f
+	vfenezfs %v17,%v16,%v16
ce426f
+	je	.Lcpy_found_v16
ce426f
+	vl	%v18,16(%r5,%r3)
ce426f
+	vst	%v16,0(%r5,%r2)
ce426f
+	aghi	%r5,16
ce426f
+
ce426f
+.Lcpy_remaining_v18:
ce426f
+	vlr	%v16,%v18
ce426f
+.Lcpy_remaining_v16:
ce426f
+	/* v16 contains the remaining bytes [1...16].
ce426f
+	   Store remaining bytes and append string-termination.  */
ce426f
+	vfenezf	%v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	slgrk	%r7,%r4,%r5	/* Remaining bytes = maxlen - current_len.  */
ce426f
+	aghi	%r7,-1		/* vstl needs highest index.  */
ce426f
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
ce426f
+	la	%r2,0(%r5,%r2)	/* vstl has no index register.  */
ce426f
+	/* Zero-index within remaining-bytes, store up to zero and end.  */
ce426f
+	clgrjle	%r1,%r7,.Lcpy_found_v16_store
ce426f
+	vstl	%v16,%r7,0(%r2)	/* Store remaining bytes.  */
ce426f
+	lghi	%r1,0
ce426f
+	st	%r1,1(%r7,%r2)	/* Store string-null-termination beyond n.  */
ce426f
+.Lcpy_end:
ce426f
+	/* Restore saved registers.  */
ce426f
+	vlgvg	%r6,%v31,0
ce426f
+	vlgvg	%r7,%v31,1
ce426f
+	lgr	%r2,%r0		/* Load saved dest-ptr.  */
ce426f
+	br	%r14
ce426f
+
ce426f
+.Lcpy_found_v16_32:
ce426f
+	aghi	%r5,32
ce426f
+	j	.Lcpy_found_v16
ce426f
+.Lcpy_found_v18_48:
ce426f
+	aghi	%r5,32
ce426f
+.Lcpy_found_v18_16:
ce426f
+	aghi	%r5,16
ce426f
+.Lcpy_found_v18:
ce426f
+	vlr	%v16,%v18
ce426f
+.Lcpy_found_v16:
ce426f
+	/* v16 contains a zero. Store remaining bytes to zero. current_len
ce426f
+	   has not reached border, thus checking for n is not needed!  */
ce426f
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
ce426f
+	la	%r2,0(%r5,%r2)
ce426f
+.Lcpy_found_v16_store:
ce426f
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
ce426f
+	vstl	%v16,%r1,0(%r2)	/* Copy characters including zero.  */
ce426f
+	j	.Lcpy_end
ce426f
+
ce426f
+	/* Find zero in 16byte aligned loop.  */
ce426f
+.Lcpy_loop2:
ce426f
+	vl	%v16,16(%r5,%r3)
ce426f
+	vst	%v18,0(%r5,%r2)
ce426f
+	aghi	%r5,16
ce426f
+
ce426f
+.Lcpy_loop64:
ce426f
+	vl	%v16,0(%r5,%r3)
ce426f
+	vfenezfs %v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	je	.Lcpy_found_v16 /* Jump away if zero was found.  */
ce426f
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
ce426f
+	vst	%v16,0(%r5,%r2)	/* Save previous part without zero to dst.  */
ce426f
+	vfenezfs %v17,%v18,%v18
ce426f
+	je	.Lcpy_found_v18_16
ce426f
+	vl	%v16,32(%r5,%r3)
ce426f
+	vst	%v18,16(%r5,%r2)
ce426f
+	vfenezfs %v17,%v16,%v16
ce426f
+	je	.Lcpy_found_v16_32
ce426f
+	vl	%v18,48(%r5,%r3)
ce426f
+	vst	%v16,32(%r5,%r2)
ce426f
+	vfenezfs %v17,%v18,%v18
ce426f
+	je	.Lcpy_found_v18_48
ce426f
+	vst	%v18,48(%r5,%r2)
ce426f
+
ce426f
+	aghi	%r5,64
ce426f
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
ce426f
+	aghi	%r1,64
ce426f
+	clgrjl	%r1,%r4,.Lcpy_loop64
ce426f
+
ce426f
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
ce426f
+	j	.Lcpy_lt64
ce426f
+
ce426f
+.Lfallback:
ce426f
+	jg	__wcsncat_c
ce426f
+END(__wcsncat_vx)
ce426f
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
ce426f
diff --git a/sysdeps/s390/multiarch/wcsncat.c b/sysdeps/s390/multiarch/wcsncat.c
ce426f
new file mode 100644
ce426f
index 0000000..621444d
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/wcsncat.c
ce426f
@@ -0,0 +1,27 @@
ce426f
+/* Multiple versions of wcsncat.
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 (__wcsncat, wcsncat)
ce426f
+
ce426f
+#else
ce426f
+# include <wcsmbs/wcsncat.c>
ce426f
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
ce426f
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
ce426f
index 9bfc78c..44b1502 100644
ce426f
--- a/wcsmbs/Makefile
ce426f
+++ b/wcsmbs/Makefile
ce426f
@@ -42,7 +42,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
ce426f
 	    mbrtoc16 c16rtomb
ce426f
 
ce426f
 strop-tests :=  wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
ce426f
-		wcpcpy wcsncpy wcpncpy wcscat
ce426f
+		wcpcpy wcsncpy wcpncpy wcscat wcsncat
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-wcsncat-ifunc.c b/wcsmbs/test-wcsncat-ifunc.c
ce426f
new file mode 100644
ce426f
index 0000000..5497f7d
ce426f
--- /dev/null
ce426f
+++ b/wcsmbs/test-wcsncat-ifunc.c
ce426f
@@ -0,0 +1,20 @@
ce426f
+/* Test and measure IFUNC implementations of wcsncat 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-wcsncat.c"
ce426f
diff --git a/wcsmbs/test-wcsncat.c b/wcsmbs/test-wcsncat.c
ce426f
new file mode 100644
ce426f
index 0000000..8b91a18
ce426f
--- /dev/null
ce426f
+++ b/wcsmbs/test-wcsncat.c
ce426f
@@ -0,0 +1,20 @@
ce426f
+/* Test wcsncat 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-strncat.c"
ce426f
diff --git a/wcsmbs/wcsncat.c b/wcsmbs/wcsncat.c
ce426f
index 2131466..21a3a1e 100644
ce426f
--- a/wcsmbs/wcsncat.c
ce426f
+++ b/wcsmbs/wcsncat.c
ce426f
@@ -18,10 +18,13 @@
ce426f
 
ce426f
 #include <wchar.h>
ce426f
 
ce426f
+#ifndef WCSNCAT
ce426f
+# define WCSNCAT wcsncat
ce426f
+#endif
ce426f
 
ce426f
 /* Append no more than N wide-character of SRC onto DEST.  */
ce426f
 wchar_t *
ce426f
-wcsncat (dest, src, n)
ce426f
+WCSNCAT (dest, src, n)
ce426f
      wchar_t *dest;
ce426f
      const wchar_t *src;
ce426f
      size_t n;
ce426f
-- 
ce426f
2.3.0
ce426f