00db10
From 9912e5a176f76caf6db58f9f2e9793b08ce3c957 Mon Sep 17 00:00:00 2001
00db10
From: Stefan Liebler <stli@linux.vnet.ibm.com>
00db10
Date: Thu, 8 Oct 2015 11:04:59 +0200
00db10
Subject: [PATCH 13/30] S390: Optimize stpcpy and wcpcpy.
00db10
00db10
upstream-commit-id: 8ade3db78db17e0112648d302f98eda115949cd5
00db10
https://www.sourceware.org/ml/libc-alpha/2015-07/msg00154.html
00db10
00db10
This patch provides optimized versions of stpcpy and wcpcpy with the z13
00db10
vector instructions.
00db10
00db10
ChangeLog:
00db10
00db10
	* sysdeps/s390/multiarch/stpcpy-c.c: New File.
00db10
	* sysdeps/s390/multiarch/stpcpy-vx.S: Likewise.
00db10
	* sysdeps/s390/multiarch/stpcpy.c: Likewise.
00db10
	* sysdeps/s390/multiarch/wcpcpy-c.c: Likewise.
00db10
	* sysdeps/s390/multiarch/wcpcpy-vx.S: Likewise.
00db10
	* sysdeps/s390/multiarch/wcpcpy.c: Likewise.
00db10
	* sysdeps/s390/multiarch/Makefile (sysdep_routines): Add stpcpy and
00db10
	wcpcpy functions.
00db10
	* string/stpcpy.c: Use STPCPY if defined.
00db10
	* wcsmbs/wcpcpy.c: Use WCPCPY if defined.
00db10
	* sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
	(__libc_ifunc_impl_list): Add ifunc test for stpcpy, wcpcpy.
00db10
	* string/test-stpcpy.c: Add wcpcpy support.
00db10
	* wcsmbs/test-wcpcpy.c: New File.
00db10
	* wcsmbs/Makefile (strop-tests): Add wcpcpy.
00db10
	* benchtests/bench-stpcpy.c: Add wcpcpy support.
00db10
	* benchtests/bench-wcpcpy.c: New File.
00db10
	* benchtests/Makefile (wcsmbs-bench): Add wcpcpy.
00db10
---
00db10
 benchtests/Makefile                      |   2 +-
00db10
 benchtests/bench-stpcpy.c                |  33 ++++++---
00db10
 benchtests/bench-wcpcpy.c                |  20 ++++++
00db10
 string/stpcpy.c                          |   6 ++
00db10
 string/test-stpcpy.c                     |  33 ++++++---
00db10
 sysdeps/s390/multiarch/Makefile          |   6 +-
00db10
 sysdeps/s390/multiarch/ifunc-impl-list.c |   3 +
00db10
 sysdeps/s390/multiarch/stpcpy-c.c        |  34 +++++++++
00db10
 sysdeps/s390/multiarch/stpcpy-vx.S       | 104 ++++++++++++++++++++++++++++
00db10
 sysdeps/s390/multiarch/stpcpy.c          |  29 ++++++++
00db10
 sysdeps/s390/multiarch/wcpcpy-c.c        |  25 +++++++
00db10
 sysdeps/s390/multiarch/wcpcpy-vx.S       | 114 +++++++++++++++++++++++++++++++
00db10
 sysdeps/s390/multiarch/wcpcpy.c          |  28 ++++++++
00db10
 wcsmbs/Makefile                          |   3 +-
00db10
 wcsmbs/test-wcpcpy-ifunc.c               |  20 ++++++
00db10
 wcsmbs/test-wcpcpy.c                     |  20 ++++++
00db10
 wcsmbs/wcpcpy.c                          |   6 +-
00db10
 17 files changed, 463 insertions(+), 23 deletions(-)
00db10
 create mode 100644 benchtests/bench-wcpcpy.c
00db10
 create mode 100644 sysdeps/s390/multiarch/stpcpy-c.c
00db10
 create mode 100644 sysdeps/s390/multiarch/stpcpy-vx.S
00db10
 create mode 100644 sysdeps/s390/multiarch/stpcpy.c
00db10
 create mode 100644 sysdeps/s390/multiarch/wcpcpy-c.c
00db10
 create mode 100644 sysdeps/s390/multiarch/wcpcpy-vx.S
00db10
 create mode 100644 sysdeps/s390/multiarch/wcpcpy.c
00db10
 create mode 100644 wcsmbs/test-wcpcpy-ifunc.c
00db10
 create mode 100644 wcsmbs/test-wcpcpy.c
00db10
00db10
diff --git a/benchtests/Makefile b/benchtests/Makefile
00db10
index 1dda844..1b491c6 100644
00db10
--- a/benchtests/Makefile
00db10
+++ b/benchtests/Makefile
00db10
@@ -38,7 +38,7 @@ string-bench := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \
00db10
 		strcat strchr strchrnul strcmp strcpy strcspn strlen \
00db10
 		strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \
00db10
 		strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok
00db10
-wcsmbs-bench := wcslen wcsnlen wcscpy
00db10
+wcsmbs-bench := wcslen wcsnlen wcscpy wcpcpy
00db10
 string-bench-all := $(string-bench) ${wcsmbs-bench}
00db10
 
00db10
 stdlib-bench := strtod
00db10
diff --git a/benchtests/bench-stpcpy.c b/benchtests/bench-stpcpy.c
00db10
index 0645298..f950c92 100644
00db10
--- a/benchtests/bench-stpcpy.c
00db10
+++ b/benchtests/bench-stpcpy.c
00db10
@@ -18,19 +18,34 @@
00db10
 
00db10
 #define STRCPY_RESULT(dst, len) ((dst) + (len))
00db10
 #define TEST_MAIN
00db10
-#define TEST_NAME "stpcpy"
00db10
+#ifndef WIDE
00db10
+# define TEST_NAME "stpcpy"
00db10
+#else
00db10
+# define TEST_NAME "wcpcpy"
00db10
+#endif /* WIDE */
00db10
 #include "bench-string.h"
00db10
-
00db10
-char *simple_stpcpy (char *, const char *);
00db10
-
00db10
-IMPL (simple_stpcpy, 0)
00db10
-IMPL (stpcpy, 1)
00db10
-
00db10
-char *
00db10
-simple_stpcpy (char *dst, const char *src)
00db10
+#ifndef WIDE
00db10
+# define CHAR char
00db10
+# define SIMPLE_STPCPY simple_stpcpy
00db10
+# define STPCPY stpcpy
00db10
+#else
00db10
+# include <wchar.h>
00db10
+# define CHAR wchar_t
00db10
+# define SIMPLE_STPCPY simple_wcpcpy
00db10
+# define STPCPY wcpcpy
00db10
+#endif /* WIDE */
00db10
+
00db10
+CHAR *SIMPLE_STPCPY (CHAR *, const CHAR *);
00db10
+
00db10
+IMPL (SIMPLE_STPCPY, 0)
00db10
+IMPL (STPCPY, 1)
00db10
+
00db10
+CHAR *
00db10
+SIMPLE_STPCPY (CHAR *dst, const CHAR *src)
00db10
 {
00db10
   while ((*dst++ = *src++) != '\0');
00db10
   return dst - 1;
00db10
 }
00db10
 
00db10
+#undef CHAR
00db10
 #include "bench-strcpy.c"
00db10
diff --git a/benchtests/bench-wcpcpy.c b/benchtests/bench-wcpcpy.c
00db10
new file mode 100644
00db10
index 0000000..cfbfccf
00db10
--- /dev/null
00db10
+++ b/benchtests/bench-wcpcpy.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Measure wcpcpy functions.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#define WIDE 1
00db10
+#include "bench-stpcpy.c"
00db10
diff --git a/string/stpcpy.c b/string/stpcpy.c
00db10
index b0a83ba..69d150f 100644
00db10
--- a/string/stpcpy.c
00db10
+++ b/string/stpcpy.c
00db10
@@ -28,6 +28,12 @@
00db10
 # define __stpcpy stpcpy
00db10
 #endif
00db10
 
00db10
+#ifdef STPCPY
00db10
+extern __typeof (__stpcpy) STPCPY;
00db10
+# undef __stpcpy
00db10
+# define __stpcpy STPCPY
00db10
+#endif
00db10
+
00db10
 /* Copy SRC to DEST, returning the address of the terminating '\0' in DEST.  */
00db10
 char *
00db10
 __stpcpy (dest, src)
00db10
diff --git a/string/test-stpcpy.c b/string/test-stpcpy.c
00db10
index 6a7af0c..962e5d6 100644
00db10
--- a/string/test-stpcpy.c
00db10
+++ b/string/test-stpcpy.c
00db10
@@ -19,19 +19,34 @@
00db10
 
00db10
 #define STRCPY_RESULT(dst, len) ((dst) + (len))
00db10
 #define TEST_MAIN
00db10
-#define TEST_NAME "stpcpy"
00db10
+#ifndef WIDE
00db10
+# define TEST_NAME "stpcpy"
00db10
+#else
00db10
+# define TEST_NAME "wcpcpy"
00db10
+#endif /* !WIDE */
00db10
 #include "test-string.h"
00db10
-
00db10
-char *simple_stpcpy (char *, const char *);
00db10
-
00db10
-IMPL (simple_stpcpy, 0)
00db10
-IMPL (stpcpy, 1)
00db10
-
00db10
-char *
00db10
-simple_stpcpy (char *dst, const char *src)
00db10
+#ifndef WIDE
00db10
+# define CHAR char
00db10
+# define SIMPLE_STPCPY simple_stpcpy
00db10
+# define STPCPY stpcpy
00db10
+#else
00db10
+# include <wchar.h>
00db10
+# define CHAR wchar_t
00db10
+# define SIMPLE_STPCPY simple_wcpcpy
00db10
+# define STPCPY wcpcpy
00db10
+#endif /* !WIDE */
00db10
+
00db10
+CHAR *SIMPLE_STPCPY (CHAR *, const CHAR *);
00db10
+
00db10
+IMPL (SIMPLE_STPCPY, 0)
00db10
+IMPL (STPCPY, 1)
00db10
+
00db10
+CHAR *
00db10
+SIMPLE_STPCPY (CHAR *dst, const CHAR *src)
00db10
 {
00db10
   while ((*dst++ = *src++) != '\0');
00db10
   return dst - 1;
00db10
 }
00db10
 
00db10
+#undef CHAR
00db10
 #include "test-strcpy.c"
00db10
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
00db10
index e2202b7..5b57342 100644
00db10
--- a/sysdeps/s390/multiarch/Makefile
00db10
+++ b/sysdeps/s390/multiarch/Makefile
00db10
@@ -1,11 +1,13 @@
00db10
 ifeq ($(subdir),string)
00db10
 sysdep_routines += strlen strlen-vx strlen-c \
00db10
 		   strnlen strnlen-vx strnlen-c \
00db10
-		   strcpy strcpy-vx
00db10
+		   strcpy strcpy-vx \
00db10
+		   stpcpy stpcpy-vx stpcpy-c
00db10
 endif
00db10
 
00db10
 ifeq ($(subdir),wcsmbs)
00db10
 sysdep_routines += wcslen wcslen-vx wcslen-c \
00db10
 		   wcsnlen wcsnlen-vx wcsnlen-c \
00db10
-		   wcscpy wcscpy-vx wcscpy-c
00db10
+		   wcscpy wcscpy-vx wcscpy-c \
00db10
+		   wcpcpy wcpcpy-vx wcpcpy-c
00db10
 endif
00db10
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
index c9228d6..a402301 100644
00db10
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
00db10
@@ -88,6 +88,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
00db10
   IFUNC_VX_IMPL (strcpy);
00db10
   IFUNC_VX_IMPL (wcscpy);
00db10
 
00db10
+  IFUNC_VX_IMPL (stpcpy);
00db10
+  IFUNC_VX_IMPL (wcpcpy);
00db10
+
00db10
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
00db10
 
00db10
   return i;
00db10
diff --git a/sysdeps/s390/multiarch/stpcpy-c.c b/sysdeps/s390/multiarch/stpcpy-c.c
00db10
new file mode 100644
00db10
index 0000000..4679ec6
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/stpcpy-c.c
00db10
@@ -0,0 +1,34 @@
00db10
+/* Default stpcpy implementation for S/390.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
00db10
+# define STPCPY  __stpcpy_c
00db10
+# undef libc_hidden_def
00db10
+# undef weak_alias
00db10
+# undef libc_hidden_builtin_def
00db10
+# ifdef SHARED
00db10
+#  define libc_hidden_def(name)					\
00db10
+  __hidden_ver1 (__stpcpy_c, __GI___stpcpy, __stpcpy_c);
00db10
+#  define libc_hidden_builtin_def(name)				\
00db10
+  strong_alias (__stpcpy_c, __stpcpy_c_1);			\
00db10
+  __hidden_ver1 (__stpcpy_c_1, __GI_stpcpy, __stpcpy_c_1);
00db10
+# endif /* SHARED */
00db10
+
00db10
+
00db10
+# include <string/stpcpy.c>
00db10
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
00db10
diff --git a/sysdeps/s390/multiarch/stpcpy-vx.S b/sysdeps/s390/multiarch/stpcpy-vx.S
00db10
new file mode 100644
00db10
index 0000000..661ad15
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/stpcpy-vx.S
00db10
@@ -0,0 +1,104 @@
00db10
+/* Vector optimized 32/64 bit S/390 version of stpcpy.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
00db10
+
00db10
+# include "sysdep.h"
00db10
+# include "asm-syntax.h"
00db10
+
00db10
+	.text
00db10
+
00db10
+/* char * stpcpy (const char *dest, const char *src)
00db10
+   Copy string src to dest returning a pointer to its end.
00db10
+
00db10
+   Register usage:
00db10
+   -r1=tmp
00db10
+   -r2=dest and return value
00db10
+   -r3=src
00db10
+   -r4=tmp
00db10
+   -r5=current_len
00db10
+   -v16=part of src
00db10
+   -v17=index of zero
00db10
+   -v18=part of src
00db10
+*/
00db10
+ENTRY(__stpcpy_vx)
00db10
+	.machine "z13"
00db10
+	.machinemode "zarch_nohighgprs"
00db10
+
00db10
+	vlbb	%v16,0(%r3),6	/* Load s until next 4k-byte boundary.  */
00db10
+	lcbb	%r1,0(%r3),6	/* Get bytes to 4k-byte boundary or 16.  */
00db10
+
00db10
+	vfenezb	%v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	vlgvb	%r5,%v17,7	/* Load zero index or 16 if not found.  */
00db10
+	clrjl	%r5,%r1,.Lfound_align /* If found zero within loaded bytes,
00db10
+					 copy bytes before and return.  */
00db10
+
00db10
+	/* Align s to 16 byte.  */
00db10
+	risbgn	%r4,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
00db10
+	lghi	%r5,15		/* current_len = 15.  */
00db10
+	slr	%r5,%r4		/* Compute highest index to 16byte boundary.  */
00db10
+
00db10
+	vstl	%v16,%r5,0(%r2)	/* Copy loaded characters - no zero.  */
00db10
+	ahi	%r5,1		/* Start loop at next character.  */
00db10
+
00db10
+	/* Find zero in 16byte aligned loop.  */
00db10
+.Lloop:
00db10
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
00db10
+	vfenezbs %v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	je	.Lfound_v16_0	/* Jump away if zero was found.  */
00db10
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
00db10
+	vst	%v16,0(%r5,%r2)	/* Store previous part without zero to dst.  */
00db10
+	vfenezbs %v17,%v18,%v18
00db10
+	je	.Lfound_v18_16
00db10
+	vl	%v16,32(%r5,%r3)
00db10
+	vst	%v18,16(%r5,%r2)
00db10
+	vfenezbs %v17,%v16,%v16
00db10
+	je	.Lfound_v16_32
00db10
+	vl	%v18,48(%r5,%r3)
00db10
+	vst	%v16,32(%r5,%r2)
00db10
+	vfenezbs %v17,%v18,%v18
00db10
+	je	.Lfound_v18_48
00db10
+	vst	%v18,48(%r5,%r2)
00db10
+
00db10
+	aghi	%r5,64
00db10
+	j	.Lloop		/* No zero found -> loop.  */
00db10
+
00db10
+.Lfound_v16_32:
00db10
+	aghi	%r5,32
00db10
+.Lfound_v16_0:
00db10
+	la	%r3,0(%r5,%r2)
00db10
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
00db10
+	vstl	%v16,%r1,0(%r3)	/* Copy characters including zero.  */
00db10
+	la	%r2,0(%r1,%r3)	/* Return pointer to zero.  */
00db10
+	br	%r14
00db10
+
00db10
+.Lfound_v18_48:
00db10
+	aghi	%r5,32
00db10
+.Lfound_v18_16:
00db10
+	la	%r3,16(%r5,%r2)
00db10
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
00db10
+	vstl	%v18,%r1,0(%r3)	/* Copy characters including zero.  */
00db10
+	la	%r2,0(%r1,%r3)	/* Return pointer to zero.  */
00db10
+	br	%r14
00db10
+
00db10
+.Lfound_align:
00db10
+	vstl	%v16,%r5,0(%r2)	/* Copy characters including zero.  */
00db10
+	la	%r2,0(%r5,%r2)	/* Return pointer to zero.  */
00db10
+	br	%r14
00db10
+END(__stpcpy_vx)
00db10
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
00db10
diff --git a/sysdeps/s390/multiarch/stpcpy.c b/sysdeps/s390/multiarch/stpcpy.c
00db10
new file mode 100644
00db10
index 0000000..7dc85a0
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/stpcpy.c
00db10
@@ -0,0 +1,29 @@
00db10
+/* Multiple versions of stpcpy.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
00db10
+# include <string.h>
00db10
+# include <ifunc-resolve.h>
00db10
+
00db10
+s390_vx_libc_ifunc (__stpcpy)
00db10
+weak_alias (__stpcpy, stpcpy)
00db10
+libc_hidden_builtin_def (stpcpy)
00db10
+
00db10
+#else
00db10
+# include <string/stpcpy.c>
00db10
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
00db10
diff --git a/sysdeps/s390/multiarch/wcpcpy-c.c b/sysdeps/s390/multiarch/wcpcpy-c.c
00db10
new file mode 100644
00db10
index 0000000..7349f34
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wcpcpy-c.c
00db10
@@ -0,0 +1,25 @@
00db10
+/* Default wcslen implementation for S/390.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
00db10
+# define WCPCPY  __wcpcpy_c
00db10
+
00db10
+# include <wchar.h>
00db10
+extern __typeof (__wcpcpy) __wcpcpy_c;
00db10
+# include <wcsmbs/wcpcpy.c>
00db10
+#endif
00db10
diff --git a/sysdeps/s390/multiarch/wcpcpy-vx.S b/sysdeps/s390/multiarch/wcpcpy-vx.S
00db10
new file mode 100644
00db10
index 0000000..195b836
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wcpcpy-vx.S
00db10
@@ -0,0 +1,114 @@
00db10
+/* Vector optimized 32/64 bit S/390 version of wcpcpy.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
00db10
+
00db10
+# include "sysdep.h"
00db10
+# include "asm-syntax.h"
00db10
+
00db10
+	.text
00db10
+
00db10
+/* wchar_t * wcpcpy (const wchar_t *dest, const wchar_t *src)
00db10
+   Copy string src to dest returning a pointer to its end.
00db10
+
00db10
+   Register usage:
00db10
+   -r0=border-len for switching to vector-instructions
00db10
+   -r1=tmp
00db10
+   -r2=dest and return value
00db10
+   -r3=src
00db10
+   -r4=tmp
00db10
+   -r5=current_len
00db10
+   -v16=part of src
00db10
+   -v17=index of zero
00db10
+   -v18=part of src
00db10
+*/
00db10
+ENTRY(__wcpcpy_vx)
00db10
+	.machine "z13"
00db10
+	.machinemode "zarch_nohighgprs"
00db10
+
00db10
+	vlbb	%v16,0(%r3),6	/* Load s until next 4k-byte boundary.  */
00db10
+	lcbb	%r1,0(%r3),6	/* Get bytes to 4k-byte boundary or 16.  */
00db10
+
00db10
+	tmll	%r3,3		/* Test if s is 4-byte aligned?  */
00db10
+	jne	.Lfallback	/* And use common-code variant if not.  */
00db10
+
00db10
+	vfenezf	%v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	vlgvb	%r5,%v17,7	/* Load zero index or 16 if not found.  */
00db10
+	clrjl	%r5,%r1,.Lfound_align /* If found zero within loaded bytes,
00db10
+					 copy bytes before and return.  */
00db10
+
00db10
+	/* Align s to 16 byte.  */
00db10
+	risbgn	%r4,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
00db10
+	lghi	%r5,15		/* current_len = 15.  */
00db10
+	slr	%r5,%r4		/* Compute highest index to 16byte boundary.  */
00db10
+
00db10
+	vstl	%v16,%r5,0(%r2)	/* Copy loaded characters - no zero.  */
00db10
+	ahi	%r5,1		/* Start loop at next character.  */
00db10
+
00db10
+	/* Find zero in 16byte aligned loop.  */
00db10
+.Lloop:
00db10
+	vl	%v16,0(%r5,%r3)	/* Load s.  */
00db10
+	vfenezfs %v17,%v16,%v16	/* Find element not equal with zero search.  */
00db10
+	je	.Lfound_v16_0	/* Jump away if zero was found.  */
00db10
+	vl	%v18,16(%r5,%r3) /* Load next part of s.  */
00db10
+	vst	%v16,0(%r5,%r2)	/* Store previous part without zero to dst.  */
00db10
+	vfenezfs %v17,%v18,%v18
00db10
+	je	.Lfound_v18_16
00db10
+	vl	%v16,32(%r5,%r3)
00db10
+	vst	%v18,16(%r5,%r2)
00db10
+	vfenezfs %v17,%v16,%v16
00db10
+	je	.Lfound_v16_32
00db10
+	vl	%v18,48(%r5,%r3)
00db10
+	vst	%v16,32(%r5,%r2)
00db10
+	vfenezfs %v17,%v18,%v18
00db10
+	je	.Lfound_v18_48
00db10
+	vst	%v18,48(%r5,%r2)
00db10
+
00db10
+	aghi	%r5,64
00db10
+	j	.Lloop		/* No zero found -> loop.  */
00db10
+
00db10
+.Lfound_v16_32:
00db10
+	aghi	%r5,32
00db10
+.Lfound_v16_0:
00db10
+	la	%r3,0(%r5,%r2)
00db10
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
00db10
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
00db10
+	vstl	%v16,%r1,0(%r3)	/* Copy characters including zero.  */
00db10
+	lay	%r2,-3(%r1,%r3)	/* Return pointer to zero.  */
00db10
+	br	%r14
00db10
+
00db10
+.Lfound_v18_48:
00db10
+	aghi	%r5,32
00db10
+.Lfound_v18_16:
00db10
+	la	%r3,16(%r5,%r2)
00db10
+	vlgvb	%r1,%v17,7	/* Load byte index of zero.  */
00db10
+	aghi	%r1,3		/* Also copy remaining bytes of zero.  */
00db10
+	vstl	%v18,%r1,0(%r3)	/* Copy characters including zero.  */
00db10
+	lay	%r2,-3(%r1,%r3)	/* Return pointer to zero.  */
00db10
+	br	%r14
00db10
+
00db10
+.Lfound_align:
00db10
+	aghi	%r5,3		/* Also copy remaining bytes of zero.  */
00db10
+	vstl	%v16,%r5,0(%r2)	/* Copy characters including zero.  */
00db10
+	lay	%r2,-3(%r5,%r2)	/* Return pointer to zero.  */
00db10
+	br	%r14
00db10
+
00db10
+.Lfallback:
00db10
+	jg	__wcpcpy_c
00db10
+END(__wcpcpy_vx)
00db10
+#endif /* HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc */
00db10
diff --git a/sysdeps/s390/multiarch/wcpcpy.c b/sysdeps/s390/multiarch/wcpcpy.c
00db10
new file mode 100644
00db10
index 0000000..46bf8e8
00db10
--- /dev/null
00db10
+++ b/sysdeps/s390/multiarch/wcpcpy.c
00db10
@@ -0,0 +1,28 @@
00db10
+/* Multiple versions of wcpcpy.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#if defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc
00db10
+# include <wchar.h>
00db10
+# include <ifunc-resolve.h>
00db10
+
00db10
+s390_vx_libc_ifunc (__wcpcpy)
00db10
+weak_alias (__wcpcpy, wcpcpy)
00db10
+
00db10
+#else
00db10
+# include <wcsmbs/wcpcpy.c>
00db10
+#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && !defined NOT_IN_libc) */
00db10
diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile
00db10
index ec0b050..3b91b6d 100644
00db10
--- a/wcsmbs/Makefile
00db10
+++ b/wcsmbs/Makefile
00db10
@@ -41,7 +41,8 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \
00db10
 	    isoc99_swscanf isoc99_vswscanf \
00db10
 	    mbrtoc16 c16rtomb
00db10
 
00db10
-strop-tests :=  wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen
00db10
+strop-tests :=  wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy wcsnlen \
00db10
+		wcpcpy
00db10
 tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
00db10
 	 tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2 \
00db10
 	 tst-c16c32-1 wcsatcliff $(addprefix test-,$(strop-tests))
00db10
diff --git a/wcsmbs/test-wcpcpy-ifunc.c b/wcsmbs/test-wcpcpy-ifunc.c
00db10
new file mode 100644
00db10
index 0000000..aa39062
00db10
--- /dev/null
00db10
+++ b/wcsmbs/test-wcpcpy-ifunc.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Test and measure IFUNC implementations of wcpcpy function.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#define TEST_IFUNC 1
00db10
+#include "test-wcpcpy.c"
00db10
diff --git a/wcsmbs/test-wcpcpy.c b/wcsmbs/test-wcpcpy.c
00db10
new file mode 100644
00db10
index 0000000..2cf91a1
00db10
--- /dev/null
00db10
+++ b/wcsmbs/test-wcpcpy.c
00db10
@@ -0,0 +1,20 @@
00db10
+/* Test wcspcpy functions.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#define WIDE 1
00db10
+#include "../string/test-stpcpy.c"
00db10
diff --git a/wcsmbs/wcpcpy.c b/wcsmbs/wcpcpy.c
00db10
index eaaab2c..f67ba62 100644
00db10
--- a/wcsmbs/wcpcpy.c
00db10
+++ b/wcsmbs/wcpcpy.c
00db10
@@ -21,7 +21,9 @@
00db10
 #define __need_ptrdiff_t
00db10
 #include <stddef.h>
00db10
 
00db10
-
00db10
+#ifdef WCPCPY
00db10
+# define __wcpcpy WCPCPY
00db10
+#endif
00db10
 /* Copy SRC to DEST, returning the address of the terminating L'\0' in
00db10
    DEST.  */
00db10
 wchar_t *
00db10
@@ -43,4 +45,6 @@ __wcpcpy (dest, src)
00db10
   return wcp;
00db10
 }
00db10
 
00db10
+#ifndef WCPCPY
00db10
 weak_alias (__wcpcpy, wcpcpy)
00db10
+#endif
00db10
-- 
00db10
2.3.0
00db10