bca718
From b403bd489e63561185fda4d7d1de2b1f627608d9 Mon Sep 17 00:00:00 2001
bca718
From: Stefan Liebler <stli@linux.vnet.ibm.com>
bca718
Date: Thu, 8 Oct 2015 11:10:59 +0200
bca718
Subject: [PATCH 15/30] S390: Optimize stpncpy and wcpncpy.
bca718
bca718
upstream-commit-id: b3a0c176d1185621c4dd2bb3a51ec961bdb29123
bca718
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00158.html
bca718
bca718
This patch provides optimized versions of stpncpy and wcpncpy with the z13
bca718
vector instructions.
bca718
bca718
ChangeLog:
bca718
bca718
	* sysdeps/s390/multiarch/stpncpy-c.c: New File.
bca718
	* sysdeps/s390/multiarch/stpncpy-vx.S: Likewise.
bca718
	* sysdeps/s390/multiarch/stpncpy.c: Likewise.
bca718
	* sysdeps/s390/multiarch/wcpncpy-c.c: Likewise.
bca718
	* sysdeps/s390/multiarch/wcpncpy-vx.S: Likewise.
bca718
	* sysdeps/s390/multiarch/wcpncpy.c: Likewise.
bca718
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add stpncpy and
bca718
	wcpncpy functions.
bca718
	* sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
	(__libc_ifunc_impl_list): Add ifunc test for stpncpy, wcpncpy.
bca718
	* wcsmbs/wcpncpy.c: Use WCPNCPY if defined.
bca718
	* string/test-stpncpy.c: Add wcpncpy support.
bca718
	* wcsmbs/test-wcpncpy.c: New File.
bca718
	* wcsmbs/Makefile (strop-tests): Add wcpncpy.
bca718
	* benchtests/bench-stpncpy.c: Add wcpncpy support.
bca718
	* benchtests/bench-wcpncpy.c: New File.
bca718
	* benchtests/Makefile (wcsmbs-bench): Add wcpncpy.
bca718
---
bca718
 benchtests/Makefile                      |   2 +-
bca718
 benchtests/bench-stpncpy.c               |  40 ++++--
bca718
 benchtests/bench-wcpncpy.c               |  20 +++
bca718
 string/test-stpncpy.c                    |  40 ++++--
bca718
 sysdeps/s390/multiarch/Makefile          |   6 +-
bca718
 sysdeps/s390/multiarch/ifunc-impl-list.c |   3 +
bca718
 sysdeps/s390/multiarch/stpncpy-c.c       |  28 ++++
bca718
 sysdeps/s390/multiarch/stpncpy-vx.S      | 200 ++++++++++++++++++++++++++++
bca718
 sysdeps/s390/multiarch/stpncpy.c         |  28 ++++
bca718
 sysdeps/s390/multiarch/wcpncpy-c.c       |  25 ++++
bca718
 sysdeps/s390/multiarch/wcpncpy-vx.S      | 222 +++++++++++++++++++++++++++++++
bca718
 sysdeps/s390/multiarch/wcpncpy.c         |  28 ++++
bca718
 wcsmbs/Makefile                          |   2 +-
bca718
 wcsmbs/test-wcpncpy-ifunc.c              |  20 +++
bca718
 wcsmbs/test-wcpncpy.c                    |  20 +++
bca718
 wcsmbs/wcpncpy.c                         |   5 +
bca718
 16 files changed, 663 insertions(+), 26 deletions(-)
bca718
 create mode 100644 benchtests/bench-wcpncpy.c
bca718
 create mode 100644 sysdeps/s390/multiarch/stpncpy-c.c
bca718
 create mode 100644 sysdeps/s390/multiarch/stpncpy-vx.S
bca718
 create mode 100644 sysdeps/s390/multiarch/stpncpy.c
bca718
 create mode 100644 sysdeps/s390/multiarch/wcpncpy-c.c
bca718
 create mode 100644 sysdeps/s390/multiarch/wcpncpy-vx.S
bca718
 create mode 100644 sysdeps/s390/multiarch/wcpncpy.c
bca718
 create mode 100644 wcsmbs/test-wcpncpy-ifunc.c
bca718
 create mode 100644 wcsmbs/test-wcpncpy.c
bca718
bca718
diff --git a/benchtests/Makefile b/benchtests/Makefile
bca718
index f898258..dfab95f 100644
bca718
--- a/benchtests/Makefile
bca718
+++ b/benchtests/Makefile
bca718
@@ -38,7 +38,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
bca718
 		strcat strchr strchrnul strcmp strcpy strcspn strlen \
bca718
 		strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
bca718
 		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
bca718
-wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy
bca718
+wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy
bca718
 string-bench-all := $(string-bench) ${wcsmbs-bench}
bca718
 
bca718
 stdlib-bench := strtod
bca718
diff --git a/benchtests/bench-stpncpy.c b/benchtests/bench-stpncpy.c
bca718
index 65ed800..e428102 100644
bca718
--- a/benchtests/bench-stpncpy.c
bca718
+++ b/benchtests/bench-stpncpy.c
bca718
@@ -18,18 +18,36 @@
bca718
 
bca718
 #define STRNCPY_RESULT(dst, len, n) ((dst) + ((len) > (n) ? (n) : (len)))
bca718
 #define TEST_MAIN
bca718
-#define TEST_NAME "stpncpy"
bca718
+#ifndef WIDE
bca718
+# define TEST_NAME "stpncpy"
bca718
+#else
bca718
+# define TEST_NAME "wcpncpy"
bca718
+#endif /* WIDE */
bca718
 #include "bench-string.h"
bca718
+#ifndef WIDE
bca718
+# define CHAR char
bca718
+# define SIMPLE_STPNCPY simple_stpncpy
bca718
+# define STUPID_STPNCPY stupid_stpncpy
bca718
+# define STPNCPY stpncpy
bca718
+# define STRNLEN strnlen
bca718
+#else
bca718
+# include <wchar.h>
bca718
+# define CHAR wchar_t
bca718
+# define SIMPLE_STPNCPY simple_wcpncpy
bca718
+# define STUPID_STPNCPY stupid_wcpncpy
bca718
+# define STPNCPY wcpncpy
bca718
+# define STRNLEN wcsnlen
bca718
+#endif /* WIDE */
bca718
 
bca718
-char *simple_stpncpy (char *, const char *, size_t);
bca718
-char *stupid_stpncpy (char *, const char *, size_t);
bca718
+CHAR *SIMPLE_STPNCPY (CHAR *, const CHAR *, size_t);
bca718
+CHAR *STUPID_STPNCPY (CHAR *, const CHAR *, size_t);
bca718
 
bca718
-IMPL (stupid_stpncpy, 0)
bca718
-IMPL (simple_stpncpy, 0)
bca718
-IMPL (stpncpy, 1)
bca718
+IMPL (STUPID_STPNCPY, 0)
bca718
+IMPL (SIMPLE_STPNCPY, 0)
bca718
+IMPL (STPNCPY, 1)
bca718
 
bca718
-char *
bca718
-simple_stpncpy (char *dst, const char *src, size_t n)
bca718
+CHAR *
bca718
+SIMPLE_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
bca718
 {
bca718
   while (n--)
bca718
     if ((*dst++ = *src++) == '\0')
bca718
@@ -43,10 +61,10 @@ simple_stpncpy (char *dst, const char *src, size_t n)
bca718
   return dst;
bca718
 }
bca718
 
bca718
-char *
bca718
-stupid_stpncpy (char *dst, const char *src, size_t n)
bca718
+CHAR *
bca718
+STUPID_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
bca718
 {
bca718
-  size_t nc = strnlen (src, n);
bca718
+  size_t nc = STRNLEN (src, n);
bca718
   size_t i;
bca718
 
bca718
   for (i = 0; i < nc; ++i)
bca718
diff --git a/benchtests/bench-wcpncpy.c b/benchtests/bench-wcpncpy.c
bca718
new file mode 100644
bca718
index 0000000..8aa529e
bca718
--- /dev/null
bca718
+++ b/benchtests/bench-wcpncpy.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Measure wcpncpy functions.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#define WIDE 1
bca718
+#include "bench-stpncpy.c"
bca718
diff --git a/string/test-stpncpy.c b/string/test-stpncpy.c
bca718
index 8647299..69c8181 100644
bca718
--- a/string/test-stpncpy.c
bca718
+++ b/string/test-stpncpy.c
bca718
@@ -19,18 +19,36 @@
bca718
 
bca718
 #define STRNCPY_RESULT(dst, len, n) ((dst) + ((len) > (n) ? (n) : (len)))
bca718
 #define TEST_MAIN
bca718
-#define TEST_NAME "stpncpy"
bca718
+#ifndef WIDE
bca718
+# define TEST_NAME "stpncpy"
bca718
+#else
bca718
+# define TEST_NAME "wcpncpy"
bca718
+#endif /* WIDE */
bca718
 #include "test-string.h"
bca718
+#ifndef WIDE
bca718
+# define CHAR char
bca718
+# define SIMPLE_STPNCPY simple_stpncpy
bca718
+# define STUPID_STPNCPY stupid_stpncpy
bca718
+# define STPNCPY stpncpy
bca718
+# define STRNLEN strnlen
bca718
+#else
bca718
+# include <wchar.h>
bca718
+# define CHAR wchar_t
bca718
+# define SIMPLE_STPNCPY simple_wcpncpy
bca718
+# define STUPID_STPNCPY stupid_wcpncpy
bca718
+# define STPNCPY wcpncpy
bca718
+# define STRNLEN wcsnlen
bca718
+#endif /* WIDE */
bca718
 
bca718
-char *simple_stpncpy (char *, const char *, size_t);
bca718
-char *stupid_stpncpy (char *, const char *, size_t);
bca718
+CHAR *SIMPLE_STPNCPY (CHAR *, const CHAR *, size_t);
bca718
+CHAR *STUPID_STPNCPY (CHAR *, const CHAR *, size_t);
bca718
 
bca718
-IMPL (stupid_stpncpy, 0)
bca718
-IMPL (simple_stpncpy, 0)
bca718
-IMPL (stpncpy, 1)
bca718
+IMPL (STUPID_STPNCPY, 0)
bca718
+IMPL (SIMPLE_STPNCPY, 0)
bca718
+IMPL (STPNCPY, 1)
bca718
 
bca718
-char *
bca718
-simple_stpncpy (char *dst, const char *src, size_t n)
bca718
+CHAR *
bca718
+SIMPLE_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
bca718
 {
bca718
   while (n--)
bca718
     if ((*dst++ = *src++) == '\0')
bca718
@@ -44,10 +62,10 @@ simple_stpncpy (char *dst, const char *src, size_t n)
bca718
   return dst;
bca718
 }
bca718
 
bca718
-char *
bca718
-stupid_stpncpy (char *dst, const char *src, size_t n)
bca718
+CHAR *
bca718
+STUPID_STPNCPY (CHAR *dst, const CHAR *src, size_t n)
bca718
 {
bca718
-  size_t nc = strnlen (src, n);
bca718
+  size_t nc = STRNLEN (src, n);
bca718
   size_t i;
bca718
 
bca718
   for (i = 0; i < nc; ++i)
bca718
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bca718
index 0dff2dc..98b588f 100644
bca718
--- a/sysdeps/s390/multiarch/Makefile
bca718
+++ b/sysdeps/s390/multiarch/Makefile
bca718
@@ -3,7 +3,8 @@ sysdep_routines += strlen strlen-vx strlen-c \
bca718
 		   strnlen strnlen-vx strnlen-c \
bca718
 		   strcpy strcpy-vx \
bca718
 		   stpcpy stpcpy-vx stpcpy-c \
bca718
-		   strncpy strncpy-vx
bca718
+		   strncpy strncpy-vx \
bca718
+		   stpncpy stpncpy-vx stpncpy-c
bca718
 endif
bca718
 
bca718
 ifeq ($(subdir),wcsmbs)
bca718
@@ -11,5 +12,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
bca718
 		   wcsnlen wcsnlen-vx wcsnlen-c \
bca718
 		   wcscpy wcscpy-vx wcscpy-c \
bca718
 		   wcpcpy wcpcpy-vx wcpcpy-c \
bca718
-		   wcsncpy wcsncpy-vx wcsncpy-c
bca718
+		   wcsncpy wcsncpy-vx wcsncpy-c \
bca718
+		   wcpncpy wcpncpy-vx wcpncpy-c
bca718
 endif
bca718
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
index 940421d..ca69983 100644
bca718
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
@@ -94,6 +94,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bca718
   IFUNC_VX_IMPL (strncpy);
bca718
   IFUNC_VX_IMPL (wcsncpy);
bca718
 
bca718
+  IFUNC_VX_IMPL (stpncpy);
bca718
+  IFUNC_VX_IMPL (wcpncpy);
bca718
+
bca718
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
bca718
 
bca718
   return i;
bca718
diff --git a/sysdeps/s390/multiarch/stpncpy-c.c b/sysdeps/s390/multiarch/stpncpy-c.c
bca718
new file mode 100644
bca718
index 0000000..40dd8bd
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/stpncpy-c.c
bca718
@@ -0,0 +1,28 @@
bca718
+/* Default stpncpy implementation for S/390.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# define STPNCPY  __stpncpy_c
bca718
+# ifdef SHARED
bca718
+#  undef libc_hidden_def
bca718
+#  define libc_hidden_def(name)  \
bca718
+     __hidden_ver1 (__stpncpy_c, __GI___stpncpy, __stpncpy_c);
bca718
+# endif /* SHARED */
bca718
+
bca718
+# include <string/stpncpy.c>
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/stpncpy-vx.S b/sysdeps/s390/multiarch/stpncpy-vx.S
bca718
new file mode 100644
bca718
index 0000000..36f6b93
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/stpncpy-vx.S
bca718
@@ -0,0 +1,200 @@
bca718
+/* Vector optimized 32/64 bit S/390 version of stpncpy.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+
bca718
+# include "sysdep.h"
bca718
+# include "asm-syntax.h"
bca718
+
bca718
+	.text
bca718
+
bca718
+/* char * stpncpy (char *dest, const char *src, size_t n)
bca718
+   Copies at most n characters of string src to dest
bca718
+   returning a pointer to its end or dest+n
bca718
+   if src is smaller than n.
bca718
+
bca718
+   Register usage:
bca718
+   -%r0 = return value
bca718
+   -%r1 = zero byte index
bca718
+   -%r2 = curr dst pointer
bca718
+   -%r3 = curr src pointer
bca718
+   -%r4 = n
bca718
+   -%r5 = current_len
bca718
+   -%r6 = loaded bytes
bca718
+   -%r7 = border, tmp
bca718
+*/
bca718
+ENTRY(__stpncpy_vx)
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+
bca718
+# if !defined __s390x__
bca718
+	llgfr	%r4,%r4
bca718
+# endif /* !defined __s390x__ */
bca718
+
bca718
+	clgfi	%r4,0
bca718
+	ber	%r14		/* Nothing to do, if n == 0.  */
bca718
+
bca718
+	la	%r0,0(%r4,%r2)	/* Save destination pointer + n for return.  */
bca718
+	vlvgp	%v31,%r6,%r7	/* Save registers.  */
bca718
+
bca718
+	vlbb	%v16,0(%r3),6	/* Load s until next 4k-byte boundary.  */
bca718
+	lcbb	%r6,0(%r3),6	/* Get bytes to 4k-byte boundary or 16.  */
bca718
+	llgfr	%r6,%r6		/* Convert 32bit to 64bit.  */
bca718
+
bca718
+	lghi	%r5,0		/* current_len = 0.  */
bca718
+
bca718
+	clgrjle	%r4,%r6,.Lremaining_v16 /* If n <= loaded-bytes
bca718
+					   -> process remaining.  */
bca718
+
bca718
+	/* n > loaded-byte-count */
bca718
+	vfenezb	%v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
bca718
+	clrjl	%r1,%r6,.Lfound_v16_store /* Found zero within loaded bytes,
bca718
+					     copy and return.  */
bca718
+
bca718
+	/* Align s to 16 byte.  */
bca718
+	risbgn	%r7,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
bca718
+	lghi	%r5,15		/* current_len = 15.  */
bca718
+	slr	%r5,%r7		/* Compute highest index to 16byte boundary.  */
bca718
+
bca718
+	/* Zero not found and n > loaded-byte-count.  */
bca718
+	vstl	%v16,%r5,0(%r2)	/* Copy loaded characters - no zero.  */
bca718
+	ahi	%r5,1		/* Start loop at next character.  */
bca718
+
bca718
+	/* Now we are 16byte aligned, so we can load a full vreg
bca718
+	   without page fault.  */
bca718
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
bca718
+	aghi	%r1,64
bca718
+	clgrjl	%r1,%r4,.Lloop64
bca718
+
bca718
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
bca718
+	clgijl	%r4,17,.Lremaining_v16	/* If n <= 16, process remaining
bca718
+					   bytes.  */
bca718
+.Llt64:
bca718
+	lgr	%r7,%r4
bca718
+	slgfi	%r7,16		/* border_len = n - 16.  */
bca718
+
bca718
+	clgrjhe	%r5,%r7,.Lremaining_v16 /* If current_len >= border
bca718
+					   then process remaining bytes.  */
bca718
+	vfenezbs %v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	je	.Lfound_v16	/* Jump away if zero was found.  */
bca718
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
bca718
+	vst	%v16,0(%r5,%r2)	/* Save previous part without zero to dst.  */
bca718
+	aghi	%r5,16
bca718
+
bca718
+	clgrjhe	%r5,%r7,.Lremaining_v18
bca718
+	vfenezbs %v17,%v18,%v18
bca718
+	je	.Lfound_v18
bca718
+	vl	%v16,16(%r5,%r3)
bca718
+	vst	%v18,0(%r5,%r2)
bca718
+	aghi	%r5,16
bca718
+
bca718
+	clgrjhe	%r5,%r7,.Lremaining_v16
bca718
+	vfenezbs %v17,%v16,%v16
bca718
+	je	.Lfound_v16
bca718
+	vl	%v18,16(%r5,%r3)
bca718
+	vst	%v16,0(%r5,%r2)
bca718
+	aghi	%r5,16
bca718
+
bca718
+.Lremaining_v18:
bca718
+	vlr	%v16,%v18
bca718
+.Lremaining_v16:
bca718
+	/* v16 contains the remaining bytes [1...16].
bca718
+	   Store remaining bytes and append string-termination.  */
bca718
+	vfenezb	%v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	slgrk	%r7,%r4,%r5	/* Remaining bytes = maxlen - current_len  */
bca718
+	aghi	%r7,-1		/* vstl needs highest index.  */
bca718
+	la	%r2,0(%r5,%r2)	/* vstl has no index register.  */
bca718
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
bca718
+	/* Zero in remaining bytes? -> jump away (zero-index <= max-index).  */
bca718
+	clrjle	%r1,%r7,.Lfound_v16_store
bca718
+	vstl	%v16,%r7,0(%r2)	/* Store remaining bytes without null
bca718
+				   termination!  */
bca718
+.Lend:
bca718
+	/* Restore saved registers.  */
bca718
+	vlgvg	%r6,%v31,0
bca718
+	vlgvg	%r7,%v31,1
bca718
+	lgr	%r2,%r0		/* Load saved dest-ptr.  */
bca718
+	br	%r14
bca718
+
bca718
+.Lfound_v16_32:
bca718
+	aghi	%r5,32
bca718
+	j	.Lfound_v16
bca718
+.Lfound_v18_48:
bca718
+	aghi	%r5,32
bca718
+.Lfound_v18_16:
bca718
+	aghi	%r5,16
bca718
+.Lfound_v18:
bca718
+	vlr	%v16,%v18
bca718
+.Lfound_v16:
bca718
+	/* v16 contains a zero. Store remaining bytes to zero. current_len
bca718
+	   has not reached border, thus checking for n is not needed!  */
bca718
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
bca718
+	la	%r2,0(%r5,%r2)	/* vstl has no support for index-register.  */
bca718
+.Lfound_v16_store:
bca718
+	vstl	%v16,%r1,0(%r2)	/* Copy characters including zero.  */
bca718
+	/* Fill remaining bytes with zero - remaining count always > 0.  */
bca718
+	algr	%r5,%r1		/* Remaining bytes (=%r4) = ...  */
bca718
+	slgr	%r4,%r5		/* = maxlen - (currlen + zero_index + 1) */
bca718
+	la	%r2,0(%r1,%r2)	/* Pointer to zero. start filling beyond.  */
bca718
+	lgr	%r0,%r2		/* Save return-pointer to found zero.  */
bca718
+	clgije	%r4,1,.Lend	/* Skip zero-filling, if found zero is last
bca718
+				   possible character.
bca718
+				   (1 is substracted from r4 below!).  */
bca718
+	aghi	%r4,-2		/* mvc with exrl needs count - 1.
bca718
+				   (additional -1, see remaining bytes above) */
bca718
+	srlg	%r6,%r4,8	/* Split into 256 byte blocks.  */
bca718
+	ltgr	%r6,%r6
bca718
+	je	.Lzero_lt256
bca718
+.Lzero_loop256:
bca718
+	mvc	1(256,%r2),0(%r2) /* Fill 256 zeros at once.  */
bca718
+	la	%r2,256(%r2)
bca718
+	brctg	%r6,.Lzero_loop256 /* Loop until all blocks are processed.  */
bca718
+.Lzero_lt256:
bca718
+	exrl	%r4,.Lmvc_lt256
bca718
+	j	.Lend
bca718
+.Lmvc_lt256:
bca718
+	mvc	1(1,%r2),0(%r2)
bca718
+
bca718
+.Lloop64:
bca718
+	vl	%v16,0(%r5,%r3)
bca718
+	vfenezbs %v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	je	.Lfound_v16	/* Jump away if zero was found.  */
bca718
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
bca718
+	vst	%v16,0(%r5,%r2)	/* Save previous part without zero to dst.  */
bca718
+	vfenezbs %v17,%v18,%v18
bca718
+	je	.Lfound_v18_16
bca718
+	vl	%v16,32(%r5,%r3)
bca718
+	vst	%v18,16(%r5,%r2)
bca718
+	vfenezbs %v17,%v16,%v16
bca718
+	je	.Lfound_v16_32
bca718
+	vl	%v18,48(%r5,%r3)
bca718
+	vst	%v16,32(%r5,%r2)
bca718
+	vfenezbs %v17,%v18,%v18
bca718
+	je	.Lfound_v18_48
bca718
+	vst	%v18,48(%r5,%r2)
bca718
+
bca718
+	aghi	%r5,64
bca718
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
bca718
+	aghi	%r1,64
bca718
+	clgrjl	%r1,%r4,.Lloop64
bca718
+
bca718
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
bca718
+	j	.Llt64
bca718
+END(__stpncpy_vx)
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/stpncpy.c b/sysdeps/s390/multiarch/stpncpy.c
bca718
new file mode 100644
bca718
index 0000000..894a33b
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/stpncpy.c
bca718
@@ -0,0 +1,28 @@
bca718
+/* Multiple versions of stpncpy.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# include <string.h>
bca718
+# include <ifunc-resolve.h>
bca718
+
bca718
+s390_vx_libc_ifunc (__stpncpy)
bca718
+weak_alias (__stpncpy, stpncpy)
bca718
+
bca718
+#else
bca718
+# include <string/stpncpy.c>
bca718
+#endif  /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
bca718
diff --git a/sysdeps/s390/multiarch/wcpncpy-c.c b/sysdeps/s390/multiarch/wcpncpy-c.c
bca718
new file mode 100644
bca718
index 0000000..e49b2ef
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcpncpy-c.c
bca718
@@ -0,0 +1,25 @@
bca718
+/* Default wcsncpy implementation for S/390.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# define WCPNCPY  __wcpncpy_c
bca718
+
bca718
+# include <wchar.h>
bca718
+extern __typeof (__wcpncpy) __wcpncpy_c;
bca718
+# include <wcsmbs/wcpncpy.c>
bca718
+#endif
bca718
diff --git a/sysdeps/s390/multiarch/wcpncpy-vx.S b/sysdeps/s390/multiarch/wcpncpy-vx.S
bca718
new file mode 100644
bca718
index 0000000..335ea58
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcpncpy-vx.S
bca718
@@ -0,0 +1,222 @@
bca718
+/* Vector optimized 32/64 bit S/390 version of wcpncpy.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+
bca718
+# include "sysdep.h"
bca718
+# include "asm-syntax.h"
bca718
+
bca718
+	.text
bca718
+
bca718
+/* wchar_t * wcpncpy (wchar_t *dest, const wchar_t *src, size_t n)
bca718
+   Copies at most n characters of string src to dest
bca718
+   returning a pointer to its end or dest+n
bca718
+   if src is smaller than n.
bca718
+
bca718
+   Register usage:
bca718
+   -%r0 = return value
bca718
+   -%r1 = zero byte index
bca718
+   -%r2 = curr dst pointer
bca718
+   -%r3 = curr src pointer
bca718
+   -%r4 = n
bca718
+   -%r5 = current_len
bca718
+   -%r6 = loaded bytes
bca718
+   -%r7 = border, tmp
bca718
+*/
bca718
+ENTRY(__wcpncpy_vx)
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+
bca718
+# if !defined __s390x__
bca718
+	llgfr	%r4,%r4
bca718
+# endif /* !defined __s390x__ */
bca718
+
bca718
+	clgfi	%r4,0
bca718
+	ber	%r14		/* Nothing to do, if n == 0.  */
bca718
+
bca718
+	vlbb	%v16,0(%r3),6	/* Load s until next 4k-byte boundary.  */
bca718
+
bca718
+	tmll	%r3,3		/* Test if s is 4-byte aligned?  */
bca718
+	jne	.Lfallback	/* And use common-code variant if not.  */
bca718
+
bca718
+	vlvgp	%v31,%r6,%r7	/* Save registers.  */
bca718
+	lghi	%r5,0		/* current_len = 0.  */
bca718
+
bca718
+	lcbb	%r6,0(%r3),6	/* Get bytes to 4k-byte boundary or 16.  */
bca718
+	llgfr	%r6,%r6		/* Convert 32bit to 64bit.  */
bca718
+
bca718
+	/* Check range of maxlen and convert to byte-count.  */
bca718
+# ifdef __s390x__
bca718
+	tmhh	%r4,49152	/* Test bit 0 or 1 of maxlen.  */
bca718
+	lghi	%r1,-4		/* Max byte-count is 18446744073709551612.  */
bca718
+# else
bca718
+	tmlh	%r4,49152	/* Test bit 0 or 1 of maxlen.  */
bca718
+	llilf	%r1,4294967292	/* Max byte-count is 4294967292.  */
bca718
+# endif /* !__s390x__ */
bca718
+	sllg	%r4,%r4,2	/* Convert character-count to byte-count.  */
bca718
+	locgrne	%r4,%r1		/* Use max byte-count, if bit 0/1 was one.  */
bca718
+
bca718
+	la	%r0,0(%r4,%r2)	/* Save destination pointer + n for return.  */
bca718
+
bca718
+	clgrjle	%r4,%r6,.Lremaining_v16 /* If n <= loaded-bytes
bca718
+					   -> process remaining.  */
bca718
+
bca718
+	/* n > loaded-byte-count */
bca718
+	vfenezf	%v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
bca718
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
bca718
+	clrjl	%r1,%r6,.Lfound_v16_store /* Found zero within loaded bytes,
bca718
+					     copy and return.  */
bca718
+
bca718
+	/* Align s to 16 byte.  */
bca718
+	risbgn	%r7,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
bca718
+	lghi	%r5,15		/* current_len = 15.  */
bca718
+	slr	%r5,%r7		/* Compute highest index to 16byte boundary.  */
bca718
+
bca718
+	/* Zero not found and n > loaded-byte-count.  */
bca718
+	vstl	%v16,%r5,0(%r2)	/* Copy loaded characters - no zero.  */
bca718
+	ahi	%r5,1		/* Start loop at next character.  */
bca718
+
bca718
+	/* Now we are 16byte aligned, so we can load a full vreg
bca718
+	   without page fault.  */
bca718
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
bca718
+	aghi	%r1,64
bca718
+	clgrjl	%r1,%r4,.Lloop64
bca718
+
bca718
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
bca718
+	clgijl	%r4,17,.Lremaining_v16	/* If n <=16,
bca718
+					   process remaining bytes.  */
bca718
+.Llt64:
bca718
+	lgr	%r7,%r4
bca718
+	slgfi	%r7,16		/* border_len = n - 16.  */
bca718
+
bca718
+	clgrjhe	%r5,%r7,.Lremaining_v16 /* If current_len >= border
bca718
+					   then process remaining bytes.  */
bca718
+	vfenezfs %v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	je	.Lfound_v16	/* Jump away if zero was found.  */
bca718
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
bca718
+	vst	%v16,0(%r5,%r2)	/* Store previous part without zero to dst.  */
bca718
+	aghi	%r5,16
bca718
+
bca718
+	clgrjhe	%r5,%r7,.Lremaining_v18
bca718
+	vfenezfs %v17,%v18,%v18
bca718
+	je	.Lfound_v18
bca718
+	vl	%v16,16(%r5,%r3)
bca718
+	vst	%v18,0(%r5,%r2)
bca718
+	aghi	%r5,16
bca718
+
bca718
+	clgrjhe	%r5,%r7,.Lremaining_v16
bca718
+	vfenezfs %v17,%v16,%v16
bca718
+	je	.Lfound_v16
bca718
+	vl	%v18,16(%r5,%r3)
bca718
+	vst	%v16,0(%r5,%r2)
bca718
+	aghi	%r5,16
bca718
+
bca718
+.Lremaining_v18:
bca718
+	vlr	%v16,%v18
bca718
+.Lremaining_v16:
bca718
+	/* v16 contains the remaining bytes [1...16].
bca718
+	   Store remaining bytes and append string-termination.  */
bca718
+	vfenezf	%v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	slgrk	%r7,%r4,%r5	/* Remaining bytes = maxlen - current_len  */
bca718
+	aghi	%r7,-1		/* vstl needs highest index.  */
bca718
+	la	%r2,0(%r5,%r2)	/* vstl has no index register.  */
bca718
+	vlgvb	%r1,%v17,7	/* Load zero index or 16 if not found.  */
bca718
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
bca718
+	/* Zero in remaining bytes? -> jump away (zero-index <= max-index).  */
bca718
+	clrjle	%r1,%r7,.Lfound_v16_store
bca718
+	vstl	%v16,%r7,0(%r2)	/* Store remaining bytes without null
bca718
+				   termination!  */
bca718
+.Lend:
bca718
+	/* Restore saved registers.  */
bca718
+	vlgvg	%r6,%v31,0
bca718
+	vlgvg	%r7,%v31,1
bca718
+	lgr	%r2,%r0		/* Load saved dest-ptr.  */
bca718
+	br	%r14
bca718
+
bca718
+.Lfound_v16_32:
bca718
+	aghi	%r5,32
bca718
+	j	.Lfound_v16
bca718
+.Lfound_v18_48:
bca718
+	aghi	%r5,32
bca718
+.Lfound_v18_16:
bca718
+	aghi	%r5,16
bca718
+.Lfound_v18:
bca718
+	vlr	%v16,%v18
bca718
+.Lfound_v16:
bca718
+	/* v16 contains a zero. Store remaining bytes to zero. current_len
bca718
+	   has not reached border, thus checking for n is not needed!  */
bca718
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
bca718
+	la	%r2,0(%r5,%r2)	/* vstl has no support for index-register.  */
bca718
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
bca718
+.Lfound_v16_store:
bca718
+	vstl	%v16,%r1,0(%r2)	/* Copy characters including zero.  */
bca718
+	/* Fill remaining bytes with zero - remaining byte count always > 0.  */
bca718
+	algr	%r5,%r1		/* Remaining bytes (=%r4) = ...  */
bca718
+	slgr	%r4,%r5		/* = n - (currlen + zero_index + 1) */
bca718
+	la	%r2,0(%r1,%r2)	/* Pointer to zero. start filling beyond.  */
bca718
+	lay	%r0,-3(%r2)	/* Save return-pointer to found zero.  */
bca718
+	clgije	%r4,1,.Lend	/* Skip zero-filling, if found-zero is last
bca718
+				   possible character.
bca718
+				   (1 is substracted from r4 below!).  */
bca718
+	aghi	%r4,-2		/* mvc with exrl needs count - 1.
bca718
+				   (additional -1, see remaining bytes above) */
bca718
+	srlg	%r6,%r4,8	/* Split into 256 byte blocks.  */
bca718
+	ltgr	%r6,%r6
bca718
+	je	.Lzero_lt256
bca718
+.Lzero_loop256:
bca718
+	mvc	1(256,%r2),0(%r2) /* Fill 256 zeros at once.  */
bca718
+	la	%r2,256(%r2)
bca718
+	brctg	%r6,.Lzero_loop256 /* Loop until all blocks are processed.  */
bca718
+.Lzero_lt256:
bca718
+	exrl	%r4,.Lmvc_lt256
bca718
+	j	.Lend
bca718
+.Lmvc_lt256:
bca718
+	mvc	1(1,%r2),0(%r2)
bca718
+
bca718
+	/* Find zero in 16byte aligned loop.  */
bca718
+.Lloop64:
bca718
+	vl	%v16,0(%r5,%r3)
bca718
+	vfenezfs %v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	je	.Lfound_v16	/* Jump away if zero was found.  */
bca718
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
bca718
+	vst	%v16,0(%r5,%r2)	/* Store previous part without zero to dst.  */
bca718
+	vfenezfs %v17,%v18,%v18
bca718
+	je	.Lfound_v18_16
bca718
+	vl	%v16,32(%r5,%r3)
bca718
+	vst	%v18,16(%r5,%r2)
bca718
+	vfenezfs %v17,%v16,%v16
bca718
+	je	.Lfound_v16_32
bca718
+	vl	%v18,48(%r5,%r3)
bca718
+	vst	%v16,32(%r5,%r2)
bca718
+	vfenezfs %v17,%v18,%v18
bca718
+	je	.Lfound_v18_48
bca718
+	vst	%v18,48(%r5,%r2)
bca718
+
bca718
+	aghi	%r5,64
bca718
+	lgr	%r1,%r5		/* If %r5 + 64 < maxlen? -> loop64.  */
bca718
+	aghi	%r1,64
bca718
+	clgrjl	%r1,%r4,.Lloop64
bca718
+
bca718
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
bca718
+	j	.Llt64
bca718
+
bca718
+.Lfallback:
bca718
+	jg	__wcpncpy_c
bca718
+END(__wcpncpy_vx)
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/wcpncpy.c b/sysdeps/s390/multiarch/wcpncpy.c
bca718
new file mode 100644
bca718
index 0000000..3db7b8b
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcpncpy.c
bca718
@@ -0,0 +1,28 @@
bca718
+/* Multiple versions of wcpncpy.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
bca718
+# include <wchar.h>
bca718
+# include <ifunc-resolve.h>
bca718
+
bca718
+s390_vx_libc_ifunc (__wcpncpy)
bca718
+weak_alias (__wcpncpy, wcpncpy)
bca718
+
bca718
+#else
bca718
+# include <wcsmbs/wcpncpy.c>
bca718
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
bca718
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
bca718
index c26ab0c..89b5b3b 100644
bca718
--- a/wcsmbs/Makefile
bca718
+++ b/wcsmbs/Makefile
bca718
@@ -42,7 +42,7 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
bca718
 	    mbrtoc16 c16rtomb
bca718
 
bca718
 strop-tests :=  wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
bca718
-		wcpcpy wcsncpy
bca718
+		wcpcpy wcsncpy wcpncpy
bca718
 tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
bca718
 	 tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \
bca718
 	 tst-c16c32-1 wcsatcliff $(addprefix test-,$(strop-tests))
bca718
diff --git a/wcsmbs/test-wcpncpy-ifunc.c b/wcsmbs/test-wcpncpy-ifunc.c
bca718
new file mode 100644
bca718
index 0000000..0685487
bca718
--- /dev/null
bca718
+++ b/wcsmbs/test-wcpncpy-ifunc.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Test and measure IFUNC implementations of wcpncpy function.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#define TEST_IFUNC 1
bca718
+#include "test-wcpncpy.c"
bca718
diff --git a/wcsmbs/test-wcpncpy.c b/wcsmbs/test-wcpncpy.c
bca718
new file mode 100644
bca718
index 0000000..de302b4
bca718
--- /dev/null
bca718
+++ b/wcsmbs/test-wcpncpy.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Test wcpncpy functions.
bca718
+   Copyright (C) 2015 Free Software Foundation, Inc.
bca718
+   This file is part of the GNU C Library.
bca718
+
bca718
+   The GNU C Library is free software; you can redistribute it and/or
bca718
+   modify it under the terms of the GNU Lesser General Public
bca718
+   License as published by the Free Software Foundation; either
bca718
+   version 2.1 of the License, or (at your option) any later version.
bca718
+
bca718
+   The GNU C Library is distributed in the hope that it will be useful,
bca718
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bca718
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bca718
+   Lesser General Public License for more details.
bca718
+
bca718
+   You should have received a copy of the GNU Lesser General Public
bca718
+   License along with the GNU C Library; if not, see
bca718
+   <http://www.gnu.org/licenses/>.  */
bca718
+
bca718
+#define WIDE 1
bca718
+#include "../string/test-stpncpy.c"
bca718
diff --git a/wcsmbs/wcpncpy.c b/wcsmbs/wcpncpy.c
bca718
index 2fab857..6337a87 100644
bca718
--- a/wcsmbs/wcpncpy.c
bca718
+++ b/wcsmbs/wcpncpy.c
bca718
@@ -18,6 +18,9 @@
bca718
 
bca718
 #include <wchar.h>
bca718
 
bca718
+#ifdef WCPNCPY
bca718
+# define __wcpncpy WCPNCPY
bca718
+#endif
bca718
 
bca718
 /* Copy no more than N wide-characters of SRC to DEST, returning the
bca718
    address of the last character written into DEST.  */
bca718
@@ -82,4 +85,6 @@ __wcpncpy (dest, src, n)
bca718
   return dest - 1;
bca718
 }
bca718
 
bca718
+#ifndef WCPNCPY
bca718
 weak_alias (__wcpncpy, wcpncpy)
bca718
+#endif
bca718
-- 
bca718
2.3.0
bca718