bdc76f
commit 572cca93fafa59d641c11372a9556722d95b038c
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:15 2018 +0100
bdc76f
bdc76f
    S390: Refactor strpbrk ifunc handling.
bdc76f
    
bdc76f
    The ifunc handling for strpbrk 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
    Glibc internal calls will then also use the "newer" ifunc variant.
bdc76f
    
bdc76f
    ChangeLog:
bdc76f
    
bdc76f
            * sysdeps/s390/multiarch/Makefile
bdc76f
            (sysdep_routines): Remove strpbrk variants.
bdc76f
            * sysdeps/s390/Makefile (sysdep_routines): Add strpbrk variants.
bdc76f
            * sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
            (__libc_ifunc_impl_list): Refactor ifunc handling for strpbrk.
bdc76f
            * sysdeps/s390/multiarch/strpbrk-c.c: Move to ...
bdc76f
            * sysdeps/s390/strpbrk-c.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strpbrk-vx.S: Move to ...
bdc76f
            * sysdeps/s390/strpbrk-vx.S: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strpbrk.c: Move to ...
bdc76f
            * sysdeps/s390/strpbrk.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/ifunc-strpbrk.h: New file.
bdc76f
bdc76f
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
bdc76f
index c0a402117197b87f..a21fa7507b1d64a1 100644
bdc76f
--- a/sysdeps/s390/Makefile
bdc76f
+++ b/sysdeps/s390/Makefile
bdc76f
@@ -50,5 +50,6 @@ sysdep_routines += bzero memset memset-z900 \
bdc76f
 		   strchr strchr-vx strchr-c \
bdc76f
 		   strchrnul strchrnul-vx strchrnul-c \
bdc76f
 		   strrchr strrchr-vx strrchr-c \
bdc76f
-		   strspn strspn-vx strspn-c
bdc76f
+		   strspn strspn-vx strspn-c \
bdc76f
+		   strpbrk strpbrk-vx strpbrk-c
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/ifunc-strpbrk.h b/sysdeps/s390/ifunc-strpbrk.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..4a3138c6bf377286
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/ifunc-strpbrk.h
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* strpbrk 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_STRPBRK_IFUNC	1
bdc76f
+#else
bdc76f
+# define HAVE_STRPBRK_IFUNC	0
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
+# define HAVE_STRPBRK_IFUNC_AND_VX_SUPPORT HAVE_STRPBRK_IFUNC
bdc76f
+#else
bdc76f
+# define HAVE_STRPBRK_IFUNC_AND_VX_SUPPORT 0
bdc76f
+#endif
bdc76f
+
bdc76f
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define STRPBRK_DEFAULT	STRPBRK_Z13
bdc76f
+# define HAVE_STRPBRK_C		0
bdc76f
+# define HAVE_STRPBRK_Z13	1
bdc76f
+#else
bdc76f
+# define STRPBRK_DEFAULT	STRPBRK_C
bdc76f
+# define HAVE_STRPBRK_C		1
bdc76f
+# define HAVE_STRPBRK_Z13	HAVE_STRPBRK_IFUNC_AND_VX_SUPPORT
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRPBRK_C
bdc76f
+# define STRPBRK_C		__strpbrk_c
bdc76f
+#else
bdc76f
+# define STRPBRK_C		NULL
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRPBRK_Z13
bdc76f
+# define STRPBRK_Z13		__strpbrk_vx
bdc76f
+#else
bdc76f
+# define STRPBRK_Z13		NULL
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index 9b141e338ca551ec..1a3fed9fc88012d1 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 += strpbrk strpbrk-vx strpbrk-c \
bdc76f
-		   strcspn strcspn-vx strcspn-c \
bdc76f
+sysdep_routines += strcspn strcspn-vx strcspn-c \
bdc76f
 		   memchr memchr-vx \
bdc76f
 		   rawmemchr rawmemchr-vx rawmemchr-c \
bdc76f
 		   memccpy memccpy-vx memccpy-c \
bdc76f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
index c39e1f793aad530c..8e23416730f8a8d5 100644
bdc76f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
@@ -40,6 +40,7 @@
bdc76f
 #include <ifunc-strchrnul.h>
bdc76f
 #include <ifunc-strrchr.h>
bdc76f
 #include <ifunc-strspn.h>
bdc76f
+#include <ifunc-strpbrk.h>
bdc76f
 
bdc76f
 /* Maximum number of IFUNC implementations.  */
bdc76f
 #define MAX_IFUNC	3
bdc76f
@@ -346,6 +347,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 		)
bdc76f
 #endif /* HAVE_STRSPN_IFUNC  */
bdc76f
 
bdc76f
+#if HAVE_STRPBRK_IFUNC
bdc76f
+    IFUNC_IMPL (i, name, strpbrk,
bdc76f
+# if HAVE_STRPBRK_Z13
bdc76f
+		IFUNC_IMPL_ADD (array, i, strpbrk,
bdc76f
+				dl_hwcap & HWCAP_S390_VX, STRPBRK_Z13)
bdc76f
+# endif
bdc76f
+# if HAVE_STRPBRK_C
bdc76f
+		IFUNC_IMPL_ADD (array, i, strpbrk, 1, STRPBRK_C)
bdc76f
+# endif
bdc76f
+		)
bdc76f
+#endif /* HAVE_STRPBRK_IFUNC  */
bdc76f
+
bdc76f
 #ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
 
bdc76f
 # define IFUNC_VX_IMPL(FUNC)						\
bdc76f
@@ -382,7 +395,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (wcsspn);
bdc76f
 
bdc76f
-  IFUNC_VX_IMPL (strpbrk);
bdc76f
   IFUNC_VX_IMPL (wcspbrk);
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (strcspn);
bdc76f
diff --git a/sysdeps/s390/multiarch/strpbrk-c.c b/sysdeps/s390/strpbrk-c.c
bdc76f
similarity index 73%
bdc76f
rename from sysdeps/s390/multiarch/strpbrk-c.c
bdc76f
rename to sysdeps/s390/strpbrk-c.c
bdc76f
index 2c0517aeb52985b3..70cc5db672adb6c9 100644
bdc76f
--- a/sysdeps/s390/multiarch/strpbrk-c.c
bdc76f
+++ b/sysdeps/s390/strpbrk-c.c
bdc76f
@@ -16,13 +16,17 @@
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 STRPBRK  __strpbrk_c
bdc76f
-# ifdef SHARED
bdc76f
-#  undef libc_hidden_builtin_def
bdc76f
-#  define libc_hidden_builtin_def(name)				\
bdc76f
-     __hidden_ver1 (__strpbrk_c, __GI_strpbrk, __strpbrk_c);
bdc76f
-# endif /* SHARED */
bdc76f
+#include <ifunc-strpbrk.h>
bdc76f
+
bdc76f
+#if HAVE_STRPBRK_C
bdc76f
+# if HAVE_STRPBRK_IFUNC
bdc76f
+#  define STRPBRK STRPBRK_C
bdc76f
+#  if defined SHARED && IS_IN (libc)
bdc76f
+#   undef libc_hidden_builtin_def
bdc76f
+#   define libc_hidden_builtin_def(name)			\
bdc76f
+  __hidden_ver1 (__strpbrk_c, __GI_strpbrk, __strpbrk_c);
bdc76f
+#  endif
bdc76f
+# endif
bdc76f
 
bdc76f
 # include <string/strpbrk.c>
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/strpbrk-vx.S b/sysdeps/s390/strpbrk-vx.S
bdc76f
similarity index 97%
bdc76f
rename from sysdeps/s390/multiarch/strpbrk-vx.S
bdc76f
rename to sysdeps/s390/strpbrk-vx.S
bdc76f
index e19c550ed404a9a8..0fc7dc143337779f 100644
bdc76f
--- a/sysdeps/s390/multiarch/strpbrk-vx.S
bdc76f
+++ b/sysdeps/s390/strpbrk-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-strpbrk.h>
bdc76f
+
bdc76f
+#if HAVE_STRPBRK_Z13
bdc76f
 
bdc76f
 # include "sysdep.h"
bdc76f
 # include "asm-syntax.h"
bdc76f
@@ -59,7 +61,7 @@
bdc76f
 	otherwise =0;
bdc76f
    r9:  loaded byte count of vlbb accept-string
bdc76f
 */
bdc76f
-ENTRY(__strpbrk_vx)
bdc76f
+ENTRY(STRPBRK_Z13)
bdc76f
 	.machine "z13"
bdc76f
 	.machinemode "zarch_nohighgprs"
bdc76f
 
bdc76f
@@ -298,5 +300,14 @@ ENTRY(__strpbrk_vx)
bdc76f
 	vlgvg	%r9,%v31,1
bdc76f
 	lgr	%r2,%r1
bdc76f
 	br	%r14
bdc76f
-END(__strpbrk_vx)
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+END(STRPBRK_Z13)
bdc76f
+
bdc76f
+# if ! HAVE_STRPBRK_IFUNC
bdc76f
+strong_alias (STRPBRK_Z13, strpbrk)
bdc76f
+# endif
bdc76f
+
bdc76f
+# if ! HAVE_STRPBRK_C && defined SHARED && IS_IN (libc)
bdc76f
+strong_alias (STRPBRK_Z13, __GI_strpbrk)
bdc76f
+# endif
bdc76f
+
bdc76f
+#endif /* HAVE_STRPBRK_Z13  */
bdc76f
diff --git a/sysdeps/s390/multiarch/strpbrk.c b/sysdeps/s390/strpbrk.c
bdc76f
similarity index 70%
bdc76f
rename from sysdeps/s390/multiarch/strpbrk.c
bdc76f
rename to sysdeps/s390/strpbrk.c
bdc76f
index 11afc268f702ce09..41ce00a1aedf0020 100644
bdc76f
--- a/sysdeps/s390/multiarch/strpbrk.c
bdc76f
+++ b/sysdeps/s390/strpbrk.c
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-strpbrk.h>
bdc76f
+
bdc76f
+#if HAVE_STRPBRK_IFUNC
bdc76f
 # define strpbrk __redirect_strpbrk
bdc76f
 /* Omit the strpbrk inline definitions because it would redefine strpbrk.  */
bdc76f
 # define __NO_STRING_INLINES
bdc76f
@@ -24,8 +26,17 @@
bdc76f
 # undef strpbrk
bdc76f
 # include <ifunc-resolve.h>
bdc76f
 
bdc76f
-s390_vx_libc_ifunc2_redirected (__redirect_strpbrk, __strpbrk, strpbrk)
bdc76f
+# if HAVE_STRPBRK_C
bdc76f
+extern __typeof (__redirect_strpbrk) STRPBRK_C attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+# if HAVE_STRPBRK_Z13
bdc76f
+extern __typeof (__redirect_strpbrk) STRPBRK_Z13 attribute_hidden;
bdc76f
+# endif
bdc76f
 
bdc76f
-#else
bdc76f
-# include <string/strpbrk.c>
bdc76f
-#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */
bdc76f
+s390_libc_ifunc_expr (__redirect_strpbrk, strpbrk,
bdc76f
+		      (HAVE_STRPBRK_Z13 && (hwcap & HWCAP_S390_VX))
bdc76f
+		      ? STRPBRK_Z13
bdc76f
+		      : STRPBRK_DEFAULT
bdc76f
+		      )
bdc76f
+#endif /* HAVE_STRPBRK_IFUNC  */