bca718
From 9912e5a176f76caf6db58f9f2e9793b08ce3c957 Mon Sep 17 00:00:00 2001
bca718
From: Stefan Liebler <stli@linux.vnet.ibm.com>
bca718
Date: Thu, 8 Oct 2015 11:04:59 +0200
bca718
Subject: [PATCH 13/30] S390: Optimize stpcpy and wcpcpy.
bca718
bca718
upstream-commit-id: 8ade3db78db17e0112648d302f98eda115949cd5
bca718
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00154.html
bca718
bca718
This patch provides optimized versions of stpcpy and wcpcpy with the z13
bca718
vector instructions.
bca718
bca718
ChangeLog:
bca718
bca718
	* sysdeps/s390/multiarch/stpcpy-c.c: New File.
bca718
	* sysdeps/s390/multiarch/stpcpy-vx.S: Likewise.
bca718
	* sysdeps/s390/multiarch/stpcpy.c: Likewise.
bca718
	* sysdeps/s390/multiarch/wcpcpy-c.c: Likewise.
bca718
	* sysdeps/s390/multiarch/wcpcpy-vx.S: Likewise.
bca718
	* sysdeps/s390/multiarch/wcpcpy.c: Likewise.
bca718
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add stpcpy and
bca718
	wcpcpy functions.
bca718
	* string/stpcpy.c: Use STPCPY if defined.
bca718
	* wcsmbs/wcpcpy.c: Use WCPCPY if defined.
bca718
	* sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
	(__libc_ifunc_impl_list): Add ifunc test for stpcpy, wcpcpy.
bca718
	* string/test-stpcpy.c: Add wcpcpy support.
bca718
	* wcsmbs/test-wcpcpy.c: New File.
bca718
	* wcsmbs/Makefile (strop-tests): Add wcpcpy.
bca718
	* benchtests/bench-stpcpy.c: Add wcpcpy support.
bca718
	* benchtests/bench-wcpcpy.c: New File.
bca718
	* benchtests/Makefile (wcsmbs-bench): Add wcpcpy.
bca718
---
bca718
 benchtests/Makefile                      |   2 +-
bca718
 benchtests/bench-stpcpy.c                |  33 ++++++---
bca718
 benchtests/bench-wcpcpy.c                |  20 ++++++
bca718
 string/stpcpy.c                          |   6 ++
bca718
 string/test-stpcpy.c                     |  33 ++++++---
bca718
 sysdeps/s390/multiarch/Makefile          |   6 +-
bca718
 sysdeps/s390/multiarch/ifunc-impl-list.c |   3 +
bca718
 sysdeps/s390/multiarch/stpcpy-c.c        |  34 +++++++++
bca718
 sysdeps/s390/multiarch/stpcpy-vx.S       | 104 ++++++++++++++++++++++++++++
bca718
 sysdeps/s390/multiarch/stpcpy.c          |  29 ++++++++
bca718
 sysdeps/s390/multiarch/wcpcpy-c.c        |  25 +++++++
bca718
 sysdeps/s390/multiarch/wcpcpy-vx.S       | 114 +++++++++++++++++++++++++++++++
bca718
 sysdeps/s390/multiarch/wcpcpy.c          |  28 ++++++++
bca718
 wcsmbs/Makefile                          |   3 +-
bca718
 wcsmbs/test-wcpcpy-ifunc.c               |  20 ++++++
bca718
 wcsmbs/test-wcpcpy.c                     |  20 ++++++
bca718
 wcsmbs/wcpcpy.c                          |   6 +-
bca718
 17 files changed, 463 insertions(+), 23 deletions(-)
bca718
 create mode 100644 benchtests/bench-wcpcpy.c
bca718
 create mode 100644 sysdeps/s390/multiarch/stpcpy-c.c
bca718
 create mode 100644 sysdeps/s390/multiarch/stpcpy-vx.S
bca718
 create mode 100644 sysdeps/s390/multiarch/stpcpy.c
bca718
 create mode 100644 sysdeps/s390/multiarch/wcpcpy-c.c
bca718
 create mode 100644 sysdeps/s390/multiarch/wcpcpy-vx.S
bca718
 create mode 100644 sysdeps/s390/multiarch/wcpcpy.c
bca718
 create mode 100644 wcsmbs/test-wcpcpy-ifunc.c
bca718
 create mode 100644 wcsmbs/test-wcpcpy.c
bca718
bca718
diff --git a/benchtests/Makefile b/benchtests/Makefile
bca718
index 1dda844..1b491c6 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
bca718
+wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy
bca718
 string-bench-all := $(string-bench) ${wcsmbs-bench}
bca718
 
bca718
 stdlib-bench := strtod
bca718
diff --git a/benchtests/bench-stpcpy.c b/benchtests/bench-stpcpy.c
bca718
index 0645298..f950c92 100644
bca718
--- a/benchtests/bench-stpcpy.c
bca718
+++ b/benchtests/bench-stpcpy.c
bca718
@@ -18,19 +18,34 @@
bca718
 
bca718
 #define STRCPY_RESULT(dst, len) ((dst) + (len))
bca718
 #define TEST_MAIN
bca718
-#define TEST_NAME "stpcpy"
bca718
+#ifndef WIDE
bca718
+# define TEST_NAME "stpcpy"
bca718
+#else
bca718
+# define TEST_NAME "wcpcpy"
bca718
+#endif /* WIDE */
bca718
 #include "bench-string.h"
bca718
-
bca718
-char *simple_stpcpy (char *, const char *);
bca718
-
bca718
-IMPL (simple_stpcpy, 0)
bca718
-IMPL (stpcpy, 1)
bca718
-
bca718
-char *
bca718
-simple_stpcpy (char *dst, const char *src)
bca718
+#ifndef WIDE
bca718
+# define CHAR char
bca718
+# define SIMPLE_STPCPY simple_stpcpy
bca718
+# define STPCPY stpcpy
bca718
+#else
bca718
+# include <wchar.h>
bca718
+# define CHAR wchar_t
bca718
+# define SIMPLE_STPCPY simple_wcpcpy
bca718
+# define STPCPY wcpcpy
bca718
+#endif /* WIDE */
bca718
+
bca718
+CHAR *SIMPLE_STPCPY (CHAR *, const CHAR *);
bca718
+
bca718
+IMPL (SIMPLE_STPCPY, 0)
bca718
+IMPL (STPCPY, 1)
bca718
+
bca718
+CHAR *
bca718
+SIMPLE_STPCPY (CHAR *dst, const CHAR *src)
bca718
 {
bca718
   while ((*dst++ = *src++) != '\0');
bca718
   return dst - 1;
bca718
 }
bca718
 
bca718
+#undef CHAR
bca718
 #include "bench-strcpy.c"
bca718
diff --git a/benchtests/bench-wcpcpy.c b/benchtests/bench-wcpcpy.c
bca718
new file mode 100644
bca718
index 0000000..cfbfccf
bca718
--- /dev/null
bca718
+++ b/benchtests/bench-wcpcpy.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Measure wcpcpy 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-stpcpy.c"
bca718
diff --git a/string/stpcpy.c b/string/stpcpy.c
bca718
index b0a83ba..69d150f 100644
bca718
--- a/string/stpcpy.c
bca718
+++ b/string/stpcpy.c
bca718
@@ -28,6 +28,12 @@
bca718
 # define __stpcpy stpcpy
bca718
 #endif
bca718
 
bca718
+#ifdef STPCPY
bca718
+extern __typeof (__stpcpy) STPCPY;
bca718
+# undef __stpcpy
bca718
+# define __stpcpy STPCPY
bca718
+#endif
bca718
+
bca718
 /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST.  */
bca718
 char *
bca718
 __stpcpy (dest, src)
bca718
diff --git a/string/test-stpcpy.c b/string/test-stpcpy.c
bca718
index 6a7af0c..962e5d6 100644
bca718
--- a/string/test-stpcpy.c
bca718
+++ b/string/test-stpcpy.c
bca718
@@ -19,19 +19,34 @@
bca718
 
bca718
 #define STRCPY_RESULT(dst, len) ((dst) + (len))
bca718
 #define TEST_MAIN
bca718
-#define TEST_NAME "stpcpy"
bca718
+#ifndef WIDE
bca718
+# define TEST_NAME "stpcpy"
bca718
+#else
bca718
+# define TEST_NAME "wcpcpy"
bca718
+#endif /* !WIDE */
bca718
 #include "test-string.h"
bca718
-
bca718
-char *simple_stpcpy (char *, const char *);
bca718
-
bca718
-IMPL (simple_stpcpy, 0)
bca718
-IMPL (stpcpy, 1)
bca718
-
bca718
-char *
bca718
-simple_stpcpy (char *dst, const char *src)
bca718
+#ifndef WIDE
bca718
+# define CHAR char
bca718
+# define SIMPLE_STPCPY simple_stpcpy
bca718
+# define STPCPY stpcpy
bca718
+#else
bca718
+# include <wchar.h>
bca718
+# define CHAR wchar_t
bca718
+# define SIMPLE_STPCPY simple_wcpcpy
bca718
+# define STPCPY wcpcpy
bca718
+#endif /* !WIDE */
bca718
+
bca718
+CHAR *SIMPLE_STPCPY (CHAR *, const CHAR *);
bca718
+
bca718
+IMPL (SIMPLE_STPCPY, 0)
bca718
+IMPL (STPCPY, 1)
bca718
+
bca718
+CHAR *
bca718
+SIMPLE_STPCPY (CHAR *dst, const CHAR *src)
bca718
 {
bca718
   while ((*dst++ = *src++) != '\0');
bca718
   return dst - 1;
bca718
 }
bca718
 
bca718
+#undef CHAR
bca718
 #include "test-strcpy.c"
bca718
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bca718
index e2202b7..5b57342 100644
bca718
--- a/sysdeps/s390/multiarch/Makefile
bca718
+++ b/sysdeps/s390/multiarch/Makefile
bca718
@@ -1,11 +1,13 @@
bca718
 ifeq ($(subdir),string)
bca718
 sysdep_routines += strlen strlen-vx strlen-c \
bca718
 		   strnlen strnlen-vx strnlen-c \
bca718
-		   strcpy strcpy-vx
bca718
+		   strcpy strcpy-vx \
bca718
+		   stpcpy stpcpy-vx stpcpy-c
bca718
 endif
bca718
 
bca718
 ifeq ($(subdir),wcsmbs)
bca718
 sysdep_routines += wcslen wcslen-vx wcslen-c \
bca718
 		   wcsnlen wcsnlen-vx wcsnlen-c \
bca718
-		   wcscpy wcscpy-vx wcscpy-c
bca718
+		   wcscpy wcscpy-vx wcscpy-c \
bca718
+		   wcpcpy wcpcpy-vx wcpcpy-c
bca718
 endif
bca718
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
index c9228d6..a402301 100644
bca718
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bca718
@@ -88,6 +88,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bca718
   IFUNC_VX_IMPL (strcpy);
bca718
   IFUNC_VX_IMPL (wcscpy);
bca718
 
bca718
+  IFUNC_VX_IMPL (stpcpy);
bca718
+  IFUNC_VX_IMPL (wcpcpy);
bca718
+
bca718
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
bca718
 
bca718
   return i;
bca718
diff --git a/sysdeps/s390/multiarch/stpcpy-c.c b/sysdeps/s390/multiarch/stpcpy-c.c
bca718
new file mode 100644
bca718
index 0000000..4679ec6
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/stpcpy-c.c
bca718
@@ -0,0 +1,34 @@
bca718
+/* Default stpcpy 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 STPCPY  __stpcpy_c
bca718
+# undef libc_hidden_def
bca718
+# undef weak_alias
bca718
+# undef libc_hidden_builtin_def
bca718
+# ifdef SHARED
bca718
+#  define libc_hidden_def(name)					\
bca718
+  __hidden_ver1 (__stpcpy_c, __GI___stpcpy, __stpcpy_c);
bca718
+#  define libc_hidden_builtin_def(name)				\
bca718
+  strong_alias (__stpcpy_c, __stpcpy_c_1);			\
bca718
+  __hidden_ver1 (__stpcpy_c_1, __GI_stpcpy, __stpcpy_c_1);
bca718
+# endif /* SHARED */
bca718
+
bca718
+
bca718
+# include <string/stpcpy.c>
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/stpcpy-vx.S b/sysdeps/s390/multiarch/stpcpy-vx.S
bca718
new file mode 100644
bca718
index 0000000..661ad15
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/stpcpy-vx.S
bca718
@@ -0,0 +1,104 @@
bca718
+/* Vector optimized 32/64 bit S/390 version of stpcpy.
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 * stpcpy (const char *dest, const char *src)
bca718
+   Copy string src to dest returning a pointer to its end.
bca718
+
bca718
+   Register usage:
bca718
+   -r1=tmp
bca718
+   -r2=dest and return value
bca718
+   -r3=src
bca718
+   -r4=tmp
bca718
+   -r5=current_len
bca718
+   -v16=part of src
bca718
+   -v17=index of zero
bca718
+   -v18=part of src
bca718
+*/
bca718
+ENTRY(__stpcpy_vx)
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+
bca718
+	vlbb	%v16,0(%r3),6	/* Load s until next 4k-byte boundary.  */
bca718
+	lcbb	%r1,0(%r3),6	/* Get bytes to 4k-byte boundary or 16.  */
bca718
+
bca718
+	vfenezb	%v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	vlgvb	%r5,%v17,7	/* Load zero index or 16 if not found.  */
bca718
+	clrjl	%r5,%r1,.Lfound_align /* If found zero within loaded bytes,
bca718
+					 copy bytes before and return.  */
bca718
+
bca718
+	/* Align s to 16 byte.  */
bca718
+	risbgn	%r4,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
bca718
+	lghi	%r5,15		/* current_len = 15.  */
bca718
+	slr	%r5,%r4		/* Compute highest index to 16byte boundary.  */
bca718
+
bca718
+	vstl	%v16,%r5,0(%r2)	/* Copy loaded characters - no zero.  */
bca718
+	ahi	%r5,1		/* Start loop at next character.  */
bca718
+
bca718
+	/* Find zero in 16byte aligned loop.  */
bca718
+.Lloop:
bca718
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
bca718
+	vfenezbs %v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	je	.Lfound_v16_0	/* 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
+	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
+	j	.Lloop		/* No zero found -> loop.  */
bca718
+
bca718
+.Lfound_v16_32:
bca718
+	aghi	%r5,32
bca718
+.Lfound_v16_0:
bca718
+	la	%r3,0(%r5,%r2)
bca718
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
bca718
+	vstl	%v16,%r1,0(%r3)	/* Copy characters including zero.  */
bca718
+	la	%r2,0(%r1,%r3)	/* Return pointer to zero.  */
bca718
+	br	%r14
bca718
+
bca718
+.Lfound_v18_48:
bca718
+	aghi	%r5,32
bca718
+.Lfound_v18_16:
bca718
+	la	%r3,16(%r5,%r2)
bca718
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
bca718
+	vstl	%v18,%r1,0(%r3)	/* Copy characters including zero.  */
bca718
+	la	%r2,0(%r1,%r3)	/* Return pointer to zero.  */
bca718
+	br	%r14
bca718
+
bca718
+.Lfound_align:
bca718
+	vstl	%v16,%r5,0(%r2)	/* Copy characters including zero.  */
bca718
+	la	%r2,0(%r5,%r2)	/* Return pointer to zero.  */
bca718
+	br	%r14
bca718
+END(__stpcpy_vx)
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/stpcpy.c b/sysdeps/s390/multiarch/stpcpy.c
bca718
new file mode 100644
bca718
index 0000000..7dc85a0
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/stpcpy.c
bca718
@@ -0,0 +1,29 @@
bca718
+/* Multiple versions of stpcpy.
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 (__stpcpy)
bca718
+weak_alias (__stpcpy, stpcpy)
bca718
+libc_hidden_builtin_def (stpcpy)
bca718
+
bca718
+#else
bca718
+# include <string/stpcpy.c>
bca718
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
bca718
diff --git a/sysdeps/s390/multiarch/wcpcpy-c.c b/sysdeps/s390/multiarch/wcpcpy-c.c
bca718
new file mode 100644
bca718
index 0000000..7349f34
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcpcpy-c.c
bca718
@@ -0,0 +1,25 @@
bca718
+/* Default wcslen 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 WCPCPY  __wcpcpy_c
bca718
+
bca718
+# include <wchar.h>
bca718
+extern __typeof (__wcpcpy) __wcpcpy_c;
bca718
+# include <wcsmbs/wcpcpy.c>
bca718
+#endif
bca718
diff --git a/sysdeps/s390/multiarch/wcpcpy-vx.S b/sysdeps/s390/multiarch/wcpcpy-vx.S
bca718
new file mode 100644
bca718
index 0000000..195b836
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcpcpy-vx.S
bca718
@@ -0,0 +1,114 @@
bca718
+/* Vector optimized 32/64 bit S/390 version of wcpcpy.
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 * wcpcpy (const wchar_t *dest, const wchar_t *src)
bca718
+   Copy string src to dest returning a pointer to its end.
bca718
+
bca718
+   Register usage:
bca718
+   -r0=border-len for switching to vector-instructions
bca718
+   -r1=tmp
bca718
+   -r2=dest and return value
bca718
+   -r3=src
bca718
+   -r4=tmp
bca718
+   -r5=current_len
bca718
+   -v16=part of src
bca718
+   -v17=index of zero
bca718
+   -v18=part of src
bca718
+*/
bca718
+ENTRY(__wcpcpy_vx)
bca718
+	.machine "z13"
bca718
+	.machinemode "zarch_nohighgprs"
bca718
+
bca718
+	vlbb	%v16,0(%r3),6	/* Load s until next 4k-byte boundary.  */
bca718
+	lcbb	%r1,0(%r3),6	/* Get bytes to 4k-byte boundary or 16.  */
bca718
+
bca718
+	tmll	%r3,3		/* Test if s is 4-byte aligned?  */
bca718
+	jne	.Lfallback	/* And use common-code variant if not.  */
bca718
+
bca718
+	vfenezf	%v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	vlgvb	%r5,%v17,7	/* Load zero index or 16 if not found.  */
bca718
+	clrjl	%r5,%r1,.Lfound_align /* If found zero within loaded bytes,
bca718
+					 copy bytes before and return.  */
bca718
+
bca718
+	/* Align s to 16 byte.  */
bca718
+	risbgn	%r4,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
bca718
+	lghi	%r5,15		/* current_len = 15.  */
bca718
+	slr	%r5,%r4		/* Compute highest index to 16byte boundary.  */
bca718
+
bca718
+	vstl	%v16,%r5,0(%r2)	/* Copy loaded characters - no zero.  */
bca718
+	ahi	%r5,1		/* Start loop at next character.  */
bca718
+
bca718
+	/* Find zero in 16byte aligned loop.  */
bca718
+.Lloop:
bca718
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
bca718
+	vfenezfs %v17,%v16,%v16	/* Find element not equal with zero search.  */
bca718
+	je	.Lfound_v16_0	/* 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
+	j	.Lloop		/* No zero found -> loop.  */
bca718
+
bca718
+.Lfound_v16_32:
bca718
+	aghi	%r5,32
bca718
+.Lfound_v16_0:
bca718
+	la	%r3,0(%r5,%r2)
bca718
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
bca718
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
bca718
+	vstl	%v16,%r1,0(%r3)	/* Copy characters including zero.  */
bca718
+	lay	%r2,-3(%r1,%r3)	/* Return pointer to zero.  */
bca718
+	br	%r14
bca718
+
bca718
+.Lfound_v18_48:
bca718
+	aghi	%r5,32
bca718
+.Lfound_v18_16:
bca718
+	la	%r3,16(%r5,%r2)
bca718
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
bca718
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
bca718
+	vstl	%v18,%r1,0(%r3)	/* Copy characters including zero.  */
bca718
+	lay	%r2,-3(%r1,%r3)	/* Return pointer to zero.  */
bca718
+	br	%r14
bca718
+
bca718
+.Lfound_align:
bca718
+	aghi	%r5,3		/* Also copy remaining bytes of zero.  */
bca718
+	vstl	%v16,%r5,0(%r2)	/* Copy characters including zero.  */
bca718
+	lay	%r2,-3(%r5,%r2)	/* Return pointer to zero.  */
bca718
+	br	%r14
bca718
+
bca718
+.Lfallback:
bca718
+	jg	__wcpcpy_c
bca718
+END(__wcpcpy_vx)
bca718
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
bca718
diff --git a/sysdeps/s390/multiarch/wcpcpy.c b/sysdeps/s390/multiarch/wcpcpy.c
bca718
new file mode 100644
bca718
index 0000000..46bf8e8
bca718
--- /dev/null
bca718
+++ b/sysdeps/s390/multiarch/wcpcpy.c
bca718
@@ -0,0 +1,28 @@
bca718
+/* Multiple versions of wcpcpy.
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 (__wcpcpy)
bca718
+weak_alias (__wcpcpy, wcpcpy)
bca718
+
bca718
+#else
bca718
+# include <wcsmbs/wcpcpy.c>
bca718
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
bca718
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
bca718
index ec0b050..3b91b6d 100644
bca718
--- a/wcsmbs/Makefile
bca718
+++ b/wcsmbs/Makefile
bca718
@@ -41,7 +41,8 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
bca718
 	    isoc99_swscanf isoc99_vswscanf \
bca718
 	    mbrtoc16 c16rtomb
bca718
 
bca718
-strop-tests :=  wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen
bca718
+strop-tests :=  wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
bca718
+		wcpcpy
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-wcpcpy-ifunc.c b/wcsmbs/test-wcpcpy-ifunc.c
bca718
new file mode 100644
bca718
index 0000000..aa39062
bca718
--- /dev/null
bca718
+++ b/wcsmbs/test-wcpcpy-ifunc.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Test and measure IFUNC implementations of wcpcpy 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-wcpcpy.c"
bca718
diff --git a/wcsmbs/test-wcpcpy.c b/wcsmbs/test-wcpcpy.c
bca718
new file mode 100644
bca718
index 0000000..2cf91a1
bca718
--- /dev/null
bca718
+++ b/wcsmbs/test-wcpcpy.c
bca718
@@ -0,0 +1,20 @@
bca718
+/* Test wcspcpy 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-stpcpy.c"
bca718
diff --git a/wcsmbs/wcpcpy.c b/wcsmbs/wcpcpy.c
bca718
index eaaab2c..f67ba62 100644
bca718
--- a/wcsmbs/wcpcpy.c
bca718
+++ b/wcsmbs/wcpcpy.c
bca718
@@ -21,7 +21,9 @@
bca718
 #define __need_ptrdiff_t
bca718
 #include <stddef.h>
bca718
 
bca718
-
bca718
+#ifdef WCPCPY
bca718
+# define __wcpcpy WCPCPY
bca718
+#endif
bca718
 /* Copy SRC to DEST, returning the address of the terminating L'\0' in
bca718
    DEST.  */
bca718
 wchar_t *
bca718
@@ -43,4 +45,6 @@ __wcpcpy (dest, src)
bca718
   return wcp;
bca718
 }
bca718
 
bca718
+#ifndef WCPCPY
bca718
 weak_alias (__wcpcpy, wcpcpy)
bca718
+#endif
bca718
-- 
bca718
2.3.0
bca718