bdc76f
commit 196655ba54ebdcdcc0468bcb6e136757b013d350
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:16 2018 +0100
bdc76f
bdc76f
    S390: Refactor memccpy ifunc handling.
bdc76f
    
bdc76f
    The ifunc handling for memccpy is adjusted in order to omit ifunc
bdc76f
    variants if those will never be used as the minimum architecture level
bdc76f
    already supports newer CPUs by default.
bdc76f
    
bdc76f
    ChangeLog:
bdc76f
    
bdc76f
            * sysdeps/s390/multiarch/Makefile
bdc76f
            (sysdep_routines): Remove memccpy variants.
bdc76f
            * sysdeps/s390/Makefile (sysdep_routines): Add memccpy variants.
bdc76f
            * sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
            (__libc_ifunc_impl_list): Refactor ifunc handling for memccpy.
bdc76f
            * sysdeps/s390/multiarch/memccpy-c.c: Move to ...
bdc76f
            * sysdeps/s390/memccpy-c.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/memccpy-vx.S: Move to ...
bdc76f
            * sysdeps/s390/memccpy-vx.S: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/memccpy.c: Move to ...
bdc76f
            * sysdeps/s390/memccpy.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/ifunc-memccpy.h: New file.
bdc76f
bdc76f
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
bdc76f
index 9b38b461b34176b0..239426dbc1ce9d09 100644
bdc76f
--- a/sysdeps/s390/Makefile
bdc76f
+++ b/sysdeps/s390/Makefile
bdc76f
@@ -54,5 +54,6 @@ sysdep_routines += bzero memset memset-z900 \
bdc76f
 		   strpbrk strpbrk-vx strpbrk-c \
bdc76f
 		   strcspn strcspn-vx strcspn-c \
bdc76f
 		   memchr memchr-vx memchr-z900 \
bdc76f
-		   rawmemchr rawmemchr-vx rawmemchr-c
bdc76f
+		   rawmemchr rawmemchr-vx rawmemchr-c \
bdc76f
+		   memccpy memccpy-vx memccpy-c
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/ifunc-memccpy.h b/sysdeps/s390/ifunc-memccpy.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..8f7a1d0f9fffe106
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/ifunc-memccpy.h
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* memccpy variant information on S/390 version.
bdc76f
+   Copyright (C) 2018 Free Software Foundation, Inc.
bdc76f
+   This file is part of the GNU C Library.
bdc76f
+
bdc76f
+   The GNU C Library is free software; you can redistribute it and/or
bdc76f
+   modify it under the terms of the GNU Lesser General Public
bdc76f
+   License as published by the Free Software Foundation; either
bdc76f
+   version 2.1 of the License, or (at your option) any later version.
bdc76f
+
bdc76f
+   The GNU C Library is distributed in the hope that it will be useful,
bdc76f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
bdc76f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
bdc76f
+   Lesser General Public License for more details.
bdc76f
+
bdc76f
+   You should have received a copy of the GNU Lesser General Public
bdc76f
+   License along with the GNU C Library; if not, see
bdc76f
+   <http://www.gnu.org/licenses/>.  */
bdc76f
+
bdc76f
+#if defined USE_MULTIARCH && IS_IN (libc)		\
bdc76f
+  && ! defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define HAVE_MEMCCPY_IFUNC	1
bdc76f
+#else
bdc76f
+# define HAVE_MEMCCPY_IFUNC	0
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
+# define HAVE_MEMCCPY_IFUNC_AND_VX_SUPPORT HAVE_MEMCCPY_IFUNC
bdc76f
+#else
bdc76f
+# define HAVE_MEMCCPY_IFUNC_AND_VX_SUPPORT 0
bdc76f
+#endif
bdc76f
+
bdc76f
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define MEMCCPY_DEFAULT	MEMCCPY_Z13
bdc76f
+# define HAVE_MEMCCPY_C		0
bdc76f
+# define HAVE_MEMCCPY_Z13	1
bdc76f
+#else
bdc76f
+# define MEMCCPY_DEFAULT	MEMCCPY_C
bdc76f
+# define HAVE_MEMCCPY_C		1
bdc76f
+# define HAVE_MEMCCPY_Z13	HAVE_MEMCCPY_IFUNC_AND_VX_SUPPORT
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_MEMCCPY_C
bdc76f
+# define MEMCCPY_C		__memccpy_c
bdc76f
+#else
bdc76f
+# define MEMCCPY_C		NULL
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_MEMCCPY_Z13
bdc76f
+# define MEMCCPY_Z13		__memccpy_vx
bdc76f
+#else
bdc76f
+# define MEMCCPY_Z13		NULL
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/memccpy-c.c b/sysdeps/s390/memccpy-c.c
bdc76f
similarity index 85%
bdc76f
rename from sysdeps/s390/multiarch/memccpy-c.c
bdc76f
rename to sysdeps/s390/memccpy-c.c
bdc76f
index 1f4c5481991fcb70..2b2f81eb9cfe9369 100644
bdc76f
--- a/sysdeps/s390/multiarch/memccpy-c.c
bdc76f
+++ b/sysdeps/s390/memccpy-c.c
bdc76f
@@ -16,10 +16,14 @@
bdc76f
    License along with the GNU C Library; if not, see
bdc76f
    <http://www.gnu.org/licenses/>.  */
bdc76f
 
bdc76f
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
bdc76f
-# define MEMCCPY  __memccpy_c
bdc76f
+#include <ifunc-memccpy.h>
bdc76f
+
bdc76f
+#if HAVE_MEMCCPY_C
bdc76f
+# if HAVE_MEMCCPY_IFUNC
bdc76f
+#  define MEMCCPY MEMCCPY_C
bdc76f
+#  undef weak_alias
bdc76f
+#  define weak_alias(a, b)
bdc76f
+#endif
bdc76f
 
bdc76f
-# include <string.h>
bdc76f
-extern __typeof (__memccpy) __memccpy_c;
bdc76f
 # include <string/memccpy.c>
bdc76f
 #endif
bdc76f
diff --git a/sysdeps/s390/multiarch/memccpy-vx.S b/sysdeps/s390/memccpy-vx.S
bdc76f
similarity index 95%
bdc76f
rename from sysdeps/s390/multiarch/memccpy-vx.S
bdc76f
rename to sysdeps/s390/memccpy-vx.S
bdc76f
index 150aa0e4a48ca181..44f7bc582410ba22 100644
bdc76f
--- a/sysdeps/s390/multiarch/memccpy-vx.S
bdc76f
+++ b/sysdeps/s390/memccpy-vx.S
bdc76f
@@ -16,7 +16,9 @@
bdc76f
    License along with the GNU C Library; if not, see
bdc76f
    <http://www.gnu.org/licenses/>.  */
bdc76f
 
bdc76f
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
bdc76f
+#include <ifunc-memccpy.h>
bdc76f
+
bdc76f
+#if HAVE_MEMCCPY_Z13
bdc76f
 
bdc76f
 # include "sysdep.h"
bdc76f
 # include "asm-syntax.h"
bdc76f
@@ -42,7 +44,7 @@
bdc76f
    -v19=part #2 of s
bdc76f
    -v31=save area for r6
bdc76f
 */
bdc76f
-ENTRY(__memccpy_vx)
bdc76f
+ENTRY(MEMCCPY_Z13)
bdc76f
 	.machine "z13"
bdc76f
 	.machinemode "zarch_nohighgprs"
bdc76f
 
bdc76f
@@ -152,5 +154,11 @@ ENTRY(__memccpy_vx)
bdc76f
 	vlgvg	%r7,%v31,1
bdc76f
 	lghi	%r2,0		/* Return null.  */
bdc76f
 	br	%r14
bdc76f
-END(__memccpy_vx)
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+END(MEMCCPY_Z13)
bdc76f
+
bdc76f
+# if ! HAVE_MEMCCPY_IFUNC
bdc76f
+strong_alias (MEMCCPY_Z13, __memccpy)
bdc76f
+weak_alias (__memccpy, memccpy)
bdc76f
+# endif
bdc76f
+
bdc76f
+#endif /* HAVE_MEMCCPY_Z13  */
bdc76f
diff --git a/sysdeps/s390/multiarch/memccpy.c b/sysdeps/s390/memccpy.c
bdc76f
similarity index 68%
bdc76f
rename from sysdeps/s390/multiarch/memccpy.c
bdc76f
rename to sysdeps/s390/memccpy.c
bdc76f
index 30aae82321048b7d..bcfeb31e86c56115 100644
bdc76f
--- a/sysdeps/s390/multiarch/memccpy.c
bdc76f
+++ b/sysdeps/s390/memccpy.c
bdc76f
@@ -16,13 +16,24 @@
bdc76f
    License along with the GNU C Library; if not, see
bdc76f
    <http://www.gnu.org/licenses/>.  */
bdc76f
 
bdc76f
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
bdc76f
+#include <ifunc-memccpy.h>
bdc76f
+
bdc76f
+#if HAVE_MEMCCPY_IFUNC
bdc76f
 # include <string.h>
bdc76f
 # include <ifunc-resolve.h>
bdc76f
 
bdc76f
-s390_vx_libc_ifunc (__memccpy)
bdc76f
-weak_alias (__memccpy, memccpy)
bdc76f
+# if HAVE_MEMCCPY_C
bdc76f
+extern __typeof (__memccpy) MEMCCPY_C attribute_hidden;
bdc76f
+# endif
bdc76f
 
bdc76f
-#else
bdc76f
-# include <string/memccpy.c>
bdc76f
-#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */
bdc76f
+# if HAVE_MEMCCPY_Z13
bdc76f
+extern __typeof (__memccpy) MEMCCPY_Z13 attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+s390_libc_ifunc_expr (__memccpy, __memccpy,
bdc76f
+		      (HAVE_MEMCCPY_Z13 && (hwcap & HWCAP_S390_VX))
bdc76f
+		      ? MEMCCPY_Z13
bdc76f
+		      : MEMCCPY_DEFAULT
bdc76f
+		      )
bdc76f
+weak_alias (__memccpy, memccpy)
bdc76f
+#endif /* HAVE_MEMCCPY_IFUNC  */
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index ac6cfcf9c7dbbc3a..d5a32fc309ba4b3c 100644
bdc76f
--- a/sysdeps/s390/multiarch/Makefile
bdc76f
+++ b/sysdeps/s390/multiarch/Makefile
bdc76f
@@ -1,6 +1,5 @@
bdc76f
 ifeq ($(subdir),string)
bdc76f
-sysdep_routines += memccpy memccpy-vx memccpy-c \
bdc76f
-		   memrchr memrchr-vx memrchr-c
bdc76f
+sysdep_routines += memrchr memrchr-vx memrchr-c
bdc76f
 endif
bdc76f
 
bdc76f
 ifeq ($(subdir),wcsmbs)
bdc76f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
index bf3b40e111a6bd31..b8917747f0f23cd9 100644
bdc76f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
@@ -44,6 +44,7 @@
bdc76f
 #include <ifunc-strcspn.h>
bdc76f
 #include <ifunc-memchr.h>
bdc76f
 #include <ifunc-rawmemchr.h>
bdc76f
+#include <ifunc-memccpy.h>
bdc76f
 
bdc76f
 /* Maximum number of IFUNC implementations.  */
bdc76f
 #define MAX_IFUNC	3
bdc76f
@@ -398,6 +399,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 		)
bdc76f
 #endif /* HAVE_RAWMEMCHR_IFUNC  */
bdc76f
 
bdc76f
+#if HAVE_MEMCCPY_IFUNC
bdc76f
+    IFUNC_IMPL (i, name, memccpy,
bdc76f
+# if HAVE_MEMCCPY_Z13
bdc76f
+		IFUNC_IMPL_ADD (array, i, memccpy,
bdc76f
+				dl_hwcap & HWCAP_S390_VX, MEMCCPY_Z13)
bdc76f
+# endif
bdc76f
+# if HAVE_MEMCCPY_C
bdc76f
+		IFUNC_IMPL_ADD (array, i, memccpy, 1, MEMCCPY_C)
bdc76f
+# endif
bdc76f
+		)
bdc76f
+#endif /* HAVE_MEMCCPY_IFUNC  */
bdc76f
+
bdc76f
 #ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
 
bdc76f
 # define IFUNC_VX_IMPL(FUNC)						\
bdc76f
@@ -440,8 +453,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (wmemchr);
bdc76f
 
bdc76f
-  IFUNC_VX_IMPL (memccpy);
bdc76f
-
bdc76f
   IFUNC_VX_IMPL (wmemset);
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (wmemcmp);