ce426f
From b403bd489e63561185fda4d7d1de2b1f627608d9 Mon Sep 17 00:00:00 2001
ce426f
From: Stefan Liebler <stli@linux.vnet.ibm.com>
ce426f
Date: Thu, 8 Oct 2015 11:10:59 +0200
ce426f
Subject: [PATCH 15/30] S390: Optimize stpncpy and wcpncpy.
ce426f
ce426f
upstream-commit-id: b3a0c176d1185621c4dd2bb3a51ec961bdb29123
ce426f
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00158.html
ce426f
ce426f
This patch provides optimized versions of stpncpy and wcpncpy with the z13
ce426f
vector instructions.
ce426f
ce426f
ChangeLog:
ce426f
ce426f
	* sysdeps/s390/multiarch/stpncpy-c.c: New File.
ce426f
	* sysdeps/s390/multiarch/stpncpy-vx.S: Likewise.
ce426f
	* sysdeps/s390/multiarch/stpncpy.c: Likewise.
ce426f
	* sysdeps/s390/multiarch/wcpncpy-c.c: Likewise.
ce426f
	* sysdeps/s390/multiarch/wcpncpy-vx.S: Likewise.
ce426f
	* sysdeps/s390/multiarch/wcpncpy.c: Likewise.
ce426f
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add stpncpy and
ce426f
	wcpncpy functions.
ce426f
	* sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
	(__libc_ifunc_impl_list): Add ifunc test for stpncpy, wcpncpy.
ce426f
	* wcsmbs/wcpncpy.c: Use WCPNCPY if defined.
ce426f
	* string/test-stpncpy.c: Add wcpncpy support.
ce426f
	* wcsmbs/test-wcpncpy.c: New File.
ce426f
	* wcsmbs/Makefile (strop-tests): Add wcpncpy.
ce426f
	* benchtests/bench-stpncpy.c: Add wcpncpy support.
ce426f
	* benchtests/bench-wcpncpy.c: New File.
ce426f
	* benchtests/Makefile (wcsmbs-bench): Add wcpncpy.
ce426f
---
ce426f
 benchtests/Makefile                      |   2 +-
ce426f
 benchtests/bench-stpncpy.c               |  40 ++++--
ce426f
 benchtests/bench-wcpncpy.c               |  20 +++
ce426f
 string/test-stpncpy.c                    |  40 ++++--
ce426f
 sysdeps/s390/multiarch/Makefile          |   6 +-
ce426f
 sysdeps/s390/multiarch/ifunc-impl-list.c |   3 +
ce426f
 sysdeps/s390/multiarch/stpncpy-c.c       |  28 ++++
ce426f
 sysdeps/s390/multiarch/stpncpy-vx.S      | 200 ++++++++++++++++++++++++++++
ce426f
 sysdeps/s390/multiarch/stpncpy.c         |  28 ++++
ce426f
 sysdeps/s390/multiarch/wcpncpy-c.c       |  25 ++++
ce426f
 sysdeps/s390/multiarch/wcpncpy-vx.S      | 222 +++++++++++++++++++++++++++++++
ce426f
 sysdeps/s390/multiarch/wcpncpy.c         |  28 ++++
ce426f
 wcsmbs/Makefile                          |   2 +-
ce426f
 wcsmbs/test-wcpncpy-ifunc.c              |  20 +++
ce426f
 wcsmbs/test-wcpncpy.c                    |  20 +++
ce426f
 wcsmbs/wcpncpy.c                         |   5 +
ce426f
 16 files changed, 663 insertions(+), 26 deletions(-)
ce426f
 create mode 100644 benchtests/bench-wcpncpy.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/stpncpy-c.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/stpncpy-vx.S
ce426f
 create mode 100644 sysdeps/s390/multiarch/stpncpy.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/wcpncpy-c.c
ce426f
 create mode 100644 sysdeps/s390/multiarch/wcpncpy-vx.S
ce426f
 create mode 100644 sysdeps/s390/multiarch/wcpncpy.c
ce426f
 create mode 100644 wcsmbs/test-wcpncpy-ifunc.c
ce426f
 create mode 100644 wcsmbs/test-wcpncpy.c
ce426f
ce426f
diff --git a/benchtests/Makefile b/benchtests/Makefile
ce426f
index f898258..dfab95f 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
ce426f
+wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy
ce426f
 string-bench-all := $(string-bench) ${wcsmbs-bench}
ce426f
 
ce426f
 stdlib-bench := strtod
ce426f
diff --git a/benchtests/bench-stpncpy.c b/benchtests/bench-stpncpy.c
ce426f
index 65ed800..e428102 100644
ce426f
--- a/benchtests/bench-stpncpy.c
ce426f
+++ b/benchtests/bench-stpncpy.c
ce426f
@@ -18,18 +18,36 @@
ce426f
 
ce426f
 #define STRNCPY_RESULT(dst, len, n) ((dst) + ((len) > (n) ? (n) : (len)))
ce426f
 #define TEST_MAIN
ce426f
-#define TEST_NAME "stpncpy"
ce426f
+#ifndef WIDE
ce426f
+# define TEST_NAME "stpncpy"
ce426f
+#else
ce426f
+# define TEST_NAME "wcpncpy"
ce426f
+#endif /* WIDE */
ce426f
 #include "bench-string.h"
ce426f
+#ifndef WIDE
ce426f
+# define CHAR char
ce426f
+# define SIMPLE_STPNCPY simple_stpncpy
ce426f
+# define STUPID_STPNCPY stupid_stpncpy
ce426f
+# define STPNCPY stpncpy
ce426f
+# define STRNLEN strnlen
ce426f
+#else
ce426f
+# include <wchar.h>
ce426f
+# define CHAR wchar_t
ce426f
+# define SIMPLE_STPNCPY simple_wcpncpy
ce426f
+# define STUPID_STPNCPY stupid_wcpncpy
ce426f
+# define STPNCPY wcpncpy
ce426f
+# define STRNLEN wcsnlen
ce426f
+#endif /* WIDE */
ce426f
 
ce426f
-char *simple_stpncpy (char *, const char *, size_t);
ce426f
-char *stupid_stpncpy (char *, const char *, size_t);
ce426f
+CHAR *SIMPLE_STPNCPY (CHAR *, const CHAR *, size_t);
ce426f
+CHAR *STUPID_STPNCPY (CHAR *, const CHAR *, size_t);
ce426f
 
ce426f
-IMPL (stupid_stpncpy, 0)
ce426f
-IMPL (simple_stpncpy, 0)
ce426f
-IMPL (stpncpy, 1)
ce426f
+IMPL (STUPID_STPNCPY, 0)
ce426f
+IMPL (SIMPLE_STPNCPY, 0)
ce426f
+IMPL (STPNCPY, 1)
ce426f
 
ce426f
-char *
ce426f
-simple_stpncpy (char *dst, const char *src, size_t n)
ce426f
+CHAR *
ce426f
+SIMPLE_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
ce426f
 {
ce426f
   while (n--)
ce426f
     if ((*dst++ = *src++) == '\0')
ce426f
@@ -43,10 +61,10 @@ simple_stpncpy (char *dst, const char *src, size_t n)
ce426f
   return dst;
ce426f
 }
ce426f
 
ce426f
-char *
ce426f
-stupid_stpncpy (char *dst, const char *src, size_t n)
ce426f
+CHAR *
ce426f
+STUPID_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
ce426f
 {
ce426f
-  size_t nc = strnlen (src, n);
ce426f
+  size_t nc = STRNLEN (src, n);
ce426f
   size_t i;
ce426f
 
ce426f
   for (i = 0; i < nc; ++i)
ce426f
diff --git a/benchtests/bench-wcpncpy.c b/benchtests/bench-wcpncpy.c
ce426f
new file mode 100644
ce426f
index 0000000..8aa529e
ce426f
--- /dev/null
ce426f
+++ b/benchtests/bench-wcpncpy.c
ce426f
@@ -0,0 +1,20 @@
ce426f
+/* Measure wcpncpy 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-stpncpy.c"
ce426f
diff --git a/string/test-stpncpy.c b/string/test-stpncpy.c
ce426f
index 8647299..69c8181 100644
ce426f
--- a/string/test-stpncpy.c
ce426f
+++ b/string/test-stpncpy.c
ce426f
@@ -19,18 +19,36 @@
ce426f
 
ce426f
 #define STRNCPY_RESULT(dst, len, n) ((dst) + ((len) > (n) ? (n) : (len)))
ce426f
 #define TEST_MAIN
ce426f
-#define TEST_NAME "stpncpy"
ce426f
+#ifndef WIDE
ce426f
+# define TEST_NAME "stpncpy"
ce426f
+#else
ce426f
+# define TEST_NAME "wcpncpy"
ce426f
+#endif /* WIDE */
ce426f
 #include "test-string.h"
ce426f
+#ifndef WIDE
ce426f
+# define CHAR char
ce426f
+# define SIMPLE_STPNCPY simple_stpncpy
ce426f
+# define STUPID_STPNCPY stupid_stpncpy
ce426f
+# define STPNCPY stpncpy
ce426f
+# define STRNLEN strnlen
ce426f
+#else
ce426f
+# include <wchar.h>
ce426f
+# define CHAR wchar_t
ce426f
+# define SIMPLE_STPNCPY simple_wcpncpy
ce426f
+# define STUPID_STPNCPY stupid_wcpncpy
ce426f
+# define STPNCPY wcpncpy
ce426f
+# define STRNLEN wcsnlen
ce426f
+#endif /* WIDE */
ce426f
 
ce426f
-char *simple_stpncpy (char *, const char *, size_t);
ce426f
-char *stupid_stpncpy (char *, const char *, size_t);
ce426f
+CHAR *SIMPLE_STPNCPY (CHAR *, const CHAR *, size_t);
ce426f
+CHAR *STUPID_STPNCPY (CHAR *, const CHAR *, size_t);
ce426f
 
ce426f
-IMPL (stupid_stpncpy, 0)
ce426f
-IMPL (simple_stpncpy, 0)
ce426f
-IMPL (stpncpy, 1)
ce426f
+IMPL (STUPID_STPNCPY, 0)
ce426f
+IMPL (SIMPLE_STPNCPY, 0)
ce426f
+IMPL (STPNCPY, 1)
ce426f
 
ce426f
-char *
ce426f
-simple_stpncpy (char *dst, const char *src, size_t n)
ce426f
+CHAR *
ce426f
+SIMPLE_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
ce426f
 {
ce426f
   while (n--)
ce426f
     if ((*dst++ = *src++) == '\0')
ce426f
@@ -44,10 +62,10 @@ simple_stpncpy (char *dst, const char *src, size_t n)
ce426f
   return dst;
ce426f
 }
ce426f
 
ce426f
-char *
ce426f
-stupid_stpncpy (char *dst, const char *src, size_t n)
ce426f
+CHAR *
ce426f
+STUPID_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
ce426f
 {
ce426f
-  size_t nc = strnlen (src, n);
ce426f
+  size_t nc = STRNLEN (src, n);
ce426f
   size_t i;
ce426f
 
ce426f
   for (i = 0; i < nc; ++i)
ce426f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
ce426f
index 0dff2dc..98b588f 100644
ce426f
--- a/sysdeps/s390/multiarch/Makefile
ce426f
+++ b/sysdeps/s390/multiarch/Makefile
ce426f
@@ -3,7 +3,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
ce426f
 		   strnlen strnlen-vx strnlen-c \
ce426f
 		   strcpy strcpy-vx \
ce426f
 		   stpcpy stpcpy-vx stpcpy-c \
ce426f
-		   strncpy strncpy-vx
ce426f
+		   strncpy strncpy-vx \
ce426f
+		   stpncpy stpncpy-vx stpncpy-c
ce426f
 endif
ce426f
 
ce426f
 ifeq ($(subdir),wcsmbs)
ce426f
@@ -11,5 +12,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
ce426f
 		   wcsnlen wcsnlen-vx wcsnlen-c \
ce426f
 		   wcscpy wcscpy-vx wcscpy-c \
ce426f
 		   wcpcpy wcpcpy-vx wcpcpy-c \
ce426f
-		   wcsncpy wcsncpy-vx wcsncpy-c
ce426f
+		   wcsncpy wcsncpy-vx wcsncpy-c \
ce426f
+		   wcpncpy wcpncpy-vx wcpncpy-c
ce426f
 endif
ce426f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
index 940421d..ca69983 100644
ce426f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
ce426f
@@ -94,6 +94,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
ce426f
   IFUNC_VX_IMPL (strncpy);
ce426f
   IFUNC_VX_IMPL (wcsncpy);
ce426f
 
ce426f
+  IFUNC_VX_IMPL (stpncpy);
ce426f
+  IFUNC_VX_IMPL (wcpncpy);
ce426f
+
ce426f
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
ce426f
 
ce426f
   return i;
ce426f
diff --git a/sysdeps/s390/multiarch/stpncpy-c.c b/sysdeps/s390/multiarch/stpncpy-c.c
ce426f
new file mode 100644
ce426f
index 0000000..40dd8bd
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/stpncpy-c.c
ce426f
@@ -0,0 +1,28 @@
ce426f
+/* Default stpncpy 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 STPNCPY  __stpncpy_c
ce426f
+# ifdef SHARED
ce426f
+#  undef libc_hidden_def
ce426f
+#  define libc_hidden_def(name)  \
ce426f
+     __hidden_ver1 (__stpncpy_c, __GI___stpncpy, __stpncpy_c);
ce426f
+# endif /* SHARED */
ce426f
+
ce426f
+# include <string/stpncpy.c>
ce426f
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
ce426f
diff --git a/sysdeps/s390/multiarch/stpncpy-vx.S b/sysdeps/s390/multiarch/stpncpy-vx.S
ce426f
new file mode 100644
ce426f
index 0000000..36f6b93
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/stpncpy-vx.S
ce426f
@@ -0,0 +1,200 @@
ce426f
+/* Vector optimized 32/64 bit S/390 version of stpncpy.
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 * stpncpy (char *dest, const char *src, size_t n)
ce426f
+   Copies at most n characters of string src to dest
ce426f
+   returning a pointer to its end or dest+n
ce426f
+   if src is smaller than n.
ce426f
+
ce426f
+   Register usage:
ce426f
+   -%r0 = return value
ce426f
+   -%r1 = zero byte index
ce426f
+   -%r2 = curr dst pointer
ce426f
+   -%r3 = curr src pointer
ce426f
+   -%r4 = n
ce426f
+   -%r5 = current_len
ce426f
+   -%r6 = loaded bytes
ce426f
+   -%r7 = border, tmp
ce426f
+*/
ce426f
+ENTRY(__stpncpy_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
+	la	%r0,0(%r4,%r2)	/* Save destination pointer + n for return.  */
ce426f
+	vlvgp	%v31,%r6,%r7	/* Save registers.  */
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,.Lremaining_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,.Lfound_v16_store /* Found zero within loaded bytes,
ce426f
+					     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
+	/* Now we are 16byte aligned, so we can load a full vreg
ce426f
+	   without page fault.  */
ce426f
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
ce426f
+	aghi	%r1,64
ce426f
+	clgrjl	%r1,%r4,.Lloop64
ce426f
+
ce426f
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
ce426f
+	clgijl	%r4,17,.Lremaining_v16	/* If n <= 16, process remaining
ce426f
+					   bytes.  */
ce426f
+.Llt64:
ce426f
+	lgr	%r7,%r4
ce426f
+	slgfi	%r7,16		/* border_len = n - 16.  */
ce426f
+
ce426f
+	clgrjhe	%r5,%r7,.Lremaining_v16 /* If current_len >= border
ce426f
+					   then process remaining bytes.  */
ce426f
+	vfenezbs %v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	je	.Lfound_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,.Lremaining_v18
ce426f
+	vfenezbs %v17,%v18,%v18
ce426f
+	je	.Lfound_v18
ce426f
+	vl	%v16,16(%r5,%r3)
ce426f
+	vst	%v18,0(%r5,%r2)
ce426f
+	aghi	%r5,16
ce426f
+
ce426f
+	clgrjhe	%r5,%r7,.Lremaining_v16
ce426f
+	vfenezbs %v17,%v16,%v16
ce426f
+	je	.Lfound_v16
ce426f
+	vl	%v18,16(%r5,%r3)
ce426f
+	vst	%v16,0(%r5,%r2)
ce426f
+	aghi	%r5,16
ce426f
+
ce426f
+.Lremaining_v18:
ce426f
+	vlr	%v16,%v18
ce426f
+.Lremaining_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
+	la	%r2,0(%r5,%r2)	/* vstl has no index register.  */
ce426f
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
ce426f
+	/* Zero in remaining bytes? -> jump away (zero-index <= max-index).  */
ce426f
+	clrjle	%r1,%r7,.Lfound_v16_store
ce426f
+	vstl	%v16,%r7,0(%r2)	/* Store remaining bytes without null
ce426f
+				   termination!  */
ce426f
+.Lend:
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
+.Lfound_v16_32:
ce426f
+	aghi	%r5,32
ce426f
+	j	.Lfound_v16
ce426f
+.Lfound_v18_48:
ce426f
+	aghi	%r5,32
ce426f
+.Lfound_v18_16:
ce426f
+	aghi	%r5,16
ce426f
+.Lfound_v18:
ce426f
+	vlr	%v16,%v18
ce426f
+.Lfound_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)	/* vstl has no support for index-register.  */
ce426f
+.Lfound_v16_store:
ce426f
+	vstl	%v16,%r1,0(%r2)	/* Copy characters including zero.  */
ce426f
+	/* Fill remaining bytes with zero - remaining count always > 0.  */
ce426f
+	algr	%r5,%r1		/* Remaining bytes (=%r4) = ...  */
ce426f
+	slgr	%r4,%r5		/* = maxlen - (currlen + zero_index + 1) */
ce426f
+	la	%r2,0(%r1,%r2)	/* Pointer to zero. start filling beyond.  */
ce426f
+	lgr	%r0,%r2		/* Save return-pointer to found zero.  */
ce426f
+	clgije	%r4,1,.Lend	/* Skip zero-filling, if found zero is last
ce426f
+				   possible character.
ce426f
+				   (1 is substracted from r4 below!).  */
ce426f
+	aghi	%r4,-2		/* mvc with exrl needs count - 1.
ce426f
+				   (additional -1, see remaining bytes above) */
ce426f
+	srlg	%r6,%r4,8	/* Split into 256 byte blocks.  */
ce426f
+	ltgr	%r6,%r6
ce426f
+	je	.Lzero_lt256
ce426f
+.Lzero_loop256:
ce426f
+	mvc	1(256,%r2),0(%r2) /* Fill 256 zeros at once.  */
ce426f
+	la	%r2,256(%r2)
ce426f
+	brctg	%r6,.Lzero_loop256 /* Loop until all blocks are processed.  */
ce426f
+.Lzero_lt256:
ce426f
+	exrl	%r4,.Lmvc_lt256
ce426f
+	j	.Lend
ce426f
+.Lmvc_lt256:
ce426f
+	mvc	1(1,%r2),0(%r2)
ce426f
+
ce426f
+.Lloop64:
ce426f
+	vl	%v16,0(%r5,%r3)
ce426f
+	vfenezbs %v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	je	.Lfound_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
+	vfenezbs %v17,%v18,%v18
ce426f
+	je	.Lfound_v18_16
ce426f
+	vl	%v16,32(%r5,%r3)
ce426f
+	vst	%v18,16(%r5,%r2)
ce426f
+	vfenezbs %v17,%v16,%v16
ce426f
+	je	.Lfound_v16_32
ce426f
+	vl	%v18,48(%r5,%r3)
ce426f
+	vst	%v16,32(%r5,%r2)
ce426f
+	vfenezbs %v17,%v18,%v18
ce426f
+	je	.Lfound_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,.Lloop64
ce426f
+
ce426f
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
ce426f
+	j	.Llt64
ce426f
+END(__stpncpy_vx)
ce426f
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
ce426f
diff --git a/sysdeps/s390/multiarch/stpncpy.c b/sysdeps/s390/multiarch/stpncpy.c
ce426f
new file mode 100644
ce426f
index 0000000..894a33b
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/stpncpy.c
ce426f
@@ -0,0 +1,28 @@
ce426f
+/* Multiple versions of stpncpy.
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_ifunc (__stpncpy)
ce426f
+weak_alias (__stpncpy, stpncpy)
ce426f
+
ce426f
+#else
ce426f
+# include <string/stpncpy.c>
ce426f
+#endif  /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
ce426f
diff --git a/sysdeps/s390/multiarch/wcpncpy-c.c b/sysdeps/s390/multiarch/wcpncpy-c.c
ce426f
new file mode 100644
ce426f
index 0000000..e49b2ef
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/wcpncpy-c.c
ce426f
@@ -0,0 +1,25 @@
ce426f
+/* Default wcsncpy 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 WCPNCPY  __wcpncpy_c
ce426f
+
ce426f
+# include <wchar.h>
ce426f
+extern __typeof (__wcpncpy) __wcpncpy_c;
ce426f
+# include <wcsmbs/wcpncpy.c>
ce426f
+#endif
ce426f
diff --git a/sysdeps/s390/multiarch/wcpncpy-vx.S b/sysdeps/s390/multiarch/wcpncpy-vx.S
ce426f
new file mode 100644
ce426f
index 0000000..335ea58
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/wcpncpy-vx.S
ce426f
@@ -0,0 +1,222 @@
ce426f
+/* Vector optimized 32/64 bit S/390 version of wcpncpy.
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 * wcpncpy (wchar_t *dest, const wchar_t *src, size_t n)
ce426f
+   Copies at most n characters of string src to dest
ce426f
+   returning a pointer to its end or dest+n
ce426f
+   if src is smaller than n.
ce426f
+
ce426f
+   Register usage:
ce426f
+   -%r0 = return value
ce426f
+   -%r1 = zero byte index
ce426f
+   -%r2 = curr dst pointer
ce426f
+   -%r3 = curr src pointer
ce426f
+   -%r4 = n
ce426f
+   -%r5 = current_len
ce426f
+   -%r6 = loaded bytes
ce426f
+   -%r7 = border, tmp
ce426f
+*/
ce426f
+ENTRY(__wcpncpy_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(%r3),6	/* Load s until next 4k-byte boundary.  */
ce426f
+
ce426f
+	tmll	%r3,3		/* Test if s is 4-byte aligned?  */
ce426f
+	jne	.Lfallback	/* And use common-code variant if not.  */
ce426f
+
ce426f
+	vlvgp	%v31,%r6,%r7	/* Save registers.  */
ce426f
+	lghi	%r5,0		/* current_len = 0.  */
ce426f
+
ce426f
+	lcbb	%r6,0(%r3),6	/* Get bytes to 4k-byte boundary or 16.  */
ce426f
+	llgfr	%r6,%r6		/* Convert 32bit to 64bit.  */
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
+	la	%r0,0(%r4,%r2)	/* Save destination pointer + n for return.  */
ce426f
+
ce426f
+	clgrjle	%r4,%r6,.Lremaining_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
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
ce426f
+	clrjl	%r1,%r6,.Lfound_v16_store /* Found zero within loaded bytes,
ce426f
+					     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
+	/* Now we are 16byte aligned, so we can load a full vreg
ce426f
+	   without page fault.  */
ce426f
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
ce426f
+	aghi	%r1,64
ce426f
+	clgrjl	%r1,%r4,.Lloop64
ce426f
+
ce426f
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
ce426f
+	clgijl	%r4,17,.Lremaining_v16	/* If n <=16,
ce426f
+					   process remaining bytes.  */
ce426f
+.Llt64:
ce426f
+	lgr	%r7,%r4
ce426f
+	slgfi	%r7,16		/* border_len = n - 16.  */
ce426f
+
ce426f
+	clgrjhe	%r5,%r7,.Lremaining_v16 /* If current_len >= border
ce426f
+					   then process remaining bytes.  */
ce426f
+	vfenezfs %v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	je	.Lfound_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,.Lremaining_v18
ce426f
+	vfenezfs %v17,%v18,%v18
ce426f
+	je	.Lfound_v18
ce426f
+	vl	%v16,16(%r5,%r3)
ce426f
+	vst	%v18,0(%r5,%r2)
ce426f
+	aghi	%r5,16
ce426f
+
ce426f
+	clgrjhe	%r5,%r7,.Lremaining_v16
ce426f
+	vfenezfs %v17,%v16,%v16
ce426f
+	je	.Lfound_v16
ce426f
+	vl	%v18,16(%r5,%r3)
ce426f
+	vst	%v16,0(%r5,%r2)
ce426f
+	aghi	%r5,16
ce426f
+
ce426f
+.Lremaining_v18:
ce426f
+	vlr	%v16,%v18
ce426f
+.Lremaining_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
+	la	%r2,0(%r5,%r2)	/* vstl has no index register.  */
ce426f
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
ce426f
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
ce426f
+	/* Zero in remaining bytes? -> jump away (zero-index <= max-index).  */
ce426f
+	clrjle	%r1,%r7,.Lfound_v16_store
ce426f
+	vstl	%v16,%r7,0(%r2)	/* Store remaining bytes without null
ce426f
+				   termination!  */
ce426f
+.Lend:
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
+.Lfound_v16_32:
ce426f
+	aghi	%r5,32
ce426f
+	j	.Lfound_v16
ce426f
+.Lfound_v18_48:
ce426f
+	aghi	%r5,32
ce426f
+.Lfound_v18_16:
ce426f
+	aghi	%r5,16
ce426f
+.Lfound_v18:
ce426f
+	vlr	%v16,%v18
ce426f
+.Lfound_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)	/* vstl has no support for index-register.  */
ce426f
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
ce426f
+.Lfound_v16_store:
ce426f
+	vstl	%v16,%r1,0(%r2)	/* Copy characters including zero.  */
ce426f
+	/* Fill remaining bytes with zero - remaining byte count always > 0.  */
ce426f
+	algr	%r5,%r1		/* Remaining bytes (=%r4) = ...  */
ce426f
+	slgr	%r4,%r5		/* = n - (currlen + zero_index + 1) */
ce426f
+	la	%r2,0(%r1,%r2)	/* Pointer to zero. start filling beyond.  */
ce426f
+	lay	%r0,-3(%r2)	/* Save return-pointer to found zero.  */
ce426f
+	clgije	%r4,1,.Lend	/* Skip zero-filling, if found-zero is last
ce426f
+				   possible character.
ce426f
+				   (1 is substracted from r4 below!).  */
ce426f
+	aghi	%r4,-2		/* mvc with exrl needs count - 1.
ce426f
+				   (additional -1, see remaining bytes above) */
ce426f
+	srlg	%r6,%r4,8	/* Split into 256 byte blocks.  */
ce426f
+	ltgr	%r6,%r6
ce426f
+	je	.Lzero_lt256
ce426f
+.Lzero_loop256:
ce426f
+	mvc	1(256,%r2),0(%r2) /* Fill 256 zeros at once.  */
ce426f
+	la	%r2,256(%r2)
ce426f
+	brctg	%r6,.Lzero_loop256 /* Loop until all blocks are processed.  */
ce426f
+.Lzero_lt256:
ce426f
+	exrl	%r4,.Lmvc_lt256
ce426f
+	j	.Lend
ce426f
+.Lmvc_lt256:
ce426f
+	mvc	1(1,%r2),0(%r2)
ce426f
+
ce426f
+	/* Find zero in 16byte aligned loop.  */
ce426f
+.Lloop64:
ce426f
+	vl	%v16,0(%r5,%r3)
ce426f
+	vfenezfs %v17,%v16,%v16	/* Find element not equal with zero search.  */
ce426f
+	je	.Lfound_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
+	vfenezfs %v17,%v18,%v18
ce426f
+	je	.Lfound_v18_16
ce426f
+	vl	%v16,32(%r5,%r3)
ce426f
+	vst	%v18,16(%r5,%r2)
ce426f
+	vfenezfs %v17,%v16,%v16
ce426f
+	je	.Lfound_v16_32
ce426f
+	vl	%v18,48(%r5,%r3)
ce426f
+	vst	%v16,32(%r5,%r2)
ce426f
+	vfenezfs %v17,%v18,%v18
ce426f
+	je	.Lfound_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,.Lloop64
ce426f
+
ce426f
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
ce426f
+	j	.Llt64
ce426f
+
ce426f
+.Lfallback:
ce426f
+	jg	__wcpncpy_c
ce426f
+END(__wcpncpy_vx)
ce426f
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
ce426f
diff --git a/sysdeps/s390/multiarch/wcpncpy.c b/sysdeps/s390/multiarch/wcpncpy.c
ce426f
new file mode 100644
ce426f
index 0000000..3db7b8b
ce426f
--- /dev/null
ce426f
+++ b/sysdeps/s390/multiarch/wcpncpy.c
ce426f
@@ -0,0 +1,28 @@
ce426f
+/* Multiple versions of wcpncpy.
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_ifunc (__wcpncpy)
ce426f
+weak_alias (__wcpncpy, wcpncpy)
ce426f
+
ce426f
+#else
ce426f
+# include <wcsmbs/wcpncpy.c>
ce426f
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
ce426f
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
ce426f
index c26ab0c..89b5b3b 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
ce426f
+		wcpcpy wcsncpy wcpncpy
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-wcpncpy-ifunc.c b/wcsmbs/test-wcpncpy-ifunc.c
ce426f
new file mode 100644
ce426f
index 0000000..0685487
ce426f
--- /dev/null
ce426f
+++ b/wcsmbs/test-wcpncpy-ifunc.c
ce426f
@@ -0,0 +1,20 @@
ce426f
+/* Test and measure IFUNC implementations of wcpncpy 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-wcpncpy.c"
ce426f
diff --git a/wcsmbs/test-wcpncpy.c b/wcsmbs/test-wcpncpy.c
ce426f
new file mode 100644
ce426f
index 0000000..de302b4
ce426f
--- /dev/null
ce426f
+++ b/wcsmbs/test-wcpncpy.c
ce426f
@@ -0,0 +1,20 @@
ce426f
+/* Test wcpncpy 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-stpncpy.c"
ce426f
diff --git a/wcsmbs/wcpncpy.c b/wcsmbs/wcpncpy.c
ce426f
index 2fab857..6337a87 100644
ce426f
--- a/wcsmbs/wcpncpy.c
ce426f
+++ b/wcsmbs/wcpncpy.c
ce426f
@@ -18,6 +18,9 @@
ce426f
 
ce426f
 #include <wchar.h>
ce426f
 
ce426f
+#ifdef WCPNCPY
ce426f
+# define __wcpncpy WCPNCPY
ce426f
+#endif
ce426f
 
ce426f
 /* Copy no more than N wide-characters of SRC to DEST, returning the
ce426f
    address of the last character written into DEST.  */
ce426f
@@ -82,4 +85,6 @@ __wcpncpy (dest, src, n)
ce426f
   return dest - 1;
ce426f
 }
ce426f
 
ce426f
+#ifndef WCPNCPY
ce426f
 weak_alias (__wcpncpy, wcpncpy)
ce426f
+#endif
ce426f
-- 
ce426f
2.3.0
ce426f