bdc76f
commit cdab85fe33b0443a645509cbb5b929a0d3307f18
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:13 2018 +0100
bdc76f
bdc76f
    S390: Refactor strcmp ifunc handling.
bdc76f
    
bdc76f
    The ifunc handling for strcmp 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
    Note: The fallback s390-32/s390-64 ifunc variants with clst instruction
bdc76f
    are now moved to the unified strcmp-z900.S file which can be used for
bdc76f
    31/64bit. The s390-32/s390-64 files multiarch/strcmp.c and strcmp.S
bdc76f
    are deleted.
bdc76f
    
bdc76f
    ChangeLog:
bdc76f
    
bdc76f
            * sysdeps/s390/multiarch/Makefile
bdc76f
            (sysdep_routines): Remove strcmp variants.
bdc76f
            * sysdeps/s390/Makefile (sysdep_routines): Add strcmp variants.
bdc76f
            * sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
            (__libc_ifunc_impl_list): Refactor ifunc handling for strcmp.
bdc76f
            * sysdeps/s390/multiarch/strcmp-vx.S: Move to ...
bdc76f
            * sysdeps/s390/strcmp-vx.S: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/strcmp.c: Move to ...
bdc76f
            * sysdeps/s390/strcmp.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/ifunc-strcmp.h: New file.
bdc76f
            * sysdeps/s390/s390-64/strcmp.S: Move to ...
bdc76f
            * sysdeps/s390/strcmp-z900.S: ... here and adjust to be usable
bdc76f
            for 31/64bit and ifunc handling.
bdc76f
            * sysdeps/s390/s390-32/multiarch/strcmp.c: Delete file.
bdc76f
            * sysdeps/s390/s390-64/multiarch/strcmp.c: Likewise.
bdc76f
            * sysdeps/s390/s390-32/strcmp.S: Likewise.
bdc76f
bdc76f
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
bdc76f
index cb5dc1d4f95fd11c..71a4658b43aeb745 100644
bdc76f
--- a/sysdeps/s390/Makefile
bdc76f
+++ b/sysdeps/s390/Makefile
bdc76f
@@ -44,5 +44,6 @@ sysdep_routines += bzero memset memset-z900 \
bdc76f
 		   strncpy strncpy-vx strncpy-z900 \
bdc76f
 		   stpncpy stpncpy-vx stpncpy-c \
bdc76f
 		   strcat strcat-vx strcat-c \
bdc76f
-		   strncat strncat-vx strncat-c
bdc76f
+		   strncat strncat-vx strncat-c \
bdc76f
+		   strcmp strcmp-vx strcmp-z900
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/ifunc-strcmp.h b/sysdeps/s390/ifunc-strcmp.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..86ffe686ade52b64
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/ifunc-strcmp.h
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* strcmp 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_STRCMP_IFUNC	1
bdc76f
+#else
bdc76f
+# define HAVE_STRCMP_IFUNC	0
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
+# define HAVE_STRCMP_IFUNC_AND_VX_SUPPORT HAVE_STRCMP_IFUNC
bdc76f
+#else
bdc76f
+# define HAVE_STRCMP_IFUNC_AND_VX_SUPPORT 0
bdc76f
+#endif
bdc76f
+
bdc76f
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define STRCMP_DEFAULT		STRCMP_Z13
bdc76f
+# define HAVE_STRCMP_Z900_G5	0
bdc76f
+# define HAVE_STRCMP_Z13	1
bdc76f
+#else
bdc76f
+# define STRCMP_DEFAULT		STRCMP_Z900_G5
bdc76f
+# define HAVE_STRCMP_Z900_G5	1
bdc76f
+# define HAVE_STRCMP_Z13	HAVE_STRCMP_IFUNC_AND_VX_SUPPORT
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRCMP_Z900_G5
bdc76f
+# define STRCMP_Z900_G5		__strcmp_default
bdc76f
+#else
bdc76f
+# define STRCMP_Z900_G5		NULL
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRCMP_Z13
bdc76f
+# define STRCMP_Z13		__strcmp_vx
bdc76f
+#else
bdc76f
+# define STRCMP_Z13		NULL
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index 24be3eac5131fd4a..97421a499625c7f2 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 += strcmp strcmp-vx \
bdc76f
-		   strncmp strncmp-vx strncmp-c \
bdc76f
+sysdep_routines += strncmp strncmp-vx strncmp-c \
bdc76f
 		   strchr strchr-vx strchr-c \
bdc76f
 		   strchrnul strchrnul-vx strchrnul-c \
bdc76f
 		   strrchr strrchr-vx strrchr-c \
bdc76f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
index 3abcaf08e0ccd385..44637c431b144c66 100644
bdc76f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
@@ -34,6 +34,7 @@
bdc76f
 #include <ifunc-stpncpy.h>
bdc76f
 #include <ifunc-strcat.h>
bdc76f
 #include <ifunc-strncat.h>
bdc76f
+#include <ifunc-strcmp.h>
bdc76f
 
bdc76f
 /* Maximum number of IFUNC implementations.  */
bdc76f
 #define MAX_IFUNC	3
bdc76f
@@ -268,6 +269,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 		)
bdc76f
 #endif /* HAVE_STRNCAT_IFUNC  */
bdc76f
 
bdc76f
+#if HAVE_STRCMP_IFUNC
bdc76f
+    IFUNC_IMPL (i, name, strcmp,
bdc76f
+# if HAVE_STRCMP_Z13
bdc76f
+		IFUNC_IMPL_ADD (array, i, strcmp,
bdc76f
+				dl_hwcap & HWCAP_S390_VX, STRCMP_Z13)
bdc76f
+# endif
bdc76f
+# if HAVE_STRCMP_Z900_G5
bdc76f
+		IFUNC_IMPL_ADD (array, i, strcmp, 1, STRCMP_Z900_G5)
bdc76f
+# endif
bdc76f
+		)
bdc76f
+#endif /* HAVE_STRCMP_IFUNC  */
bdc76f
+
bdc76f
 #ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
 
bdc76f
 # define IFUNC_VX_IMPL(FUNC)						\
bdc76f
@@ -292,7 +305,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (wcsncat);
bdc76f
 
bdc76f
-  IFUNC_VX_IMPL (strcmp);
bdc76f
   IFUNC_VX_IMPL (wcscmp);
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (strncmp);
bdc76f
diff --git a/sysdeps/s390/s390-32/multiarch/strcmp.c b/sysdeps/s390/s390-32/multiarch/strcmp.c
bdc76f
deleted file mode 100644
bdc76f
index d06b0f3436b2abfd..0000000000000000
bdc76f
--- a/sysdeps/s390/s390-32/multiarch/strcmp.c
bdc76f
+++ /dev/null
bdc76f
@@ -1,21 +0,0 @@
bdc76f
-/* Multiple versions of strcmp.
bdc76f
-   Copyright (C) 2015-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
-/* This wrapper-file is needed, because otherwise file
bdc76f
-   sysdeps/s390/s390-[32|64]/strcmp.S will be used.  */
bdc76f
-#include <sysdeps/s390/multiarch/strcmp.c>
bdc76f
diff --git a/sysdeps/s390/s390-32/strcmp.S b/sysdeps/s390/s390-32/strcmp.S
bdc76f
deleted file mode 100644
bdc76f
index 3cf3f239fddccce8..0000000000000000
bdc76f
--- a/sysdeps/s390/s390-32/strcmp.S
bdc76f
+++ /dev/null
bdc76f
@@ -1,41 +0,0 @@
bdc76f
-/* strcmp - compare two string.  S/390 version.
bdc76f
-   This file is part of the GNU C Library.
bdc76f
-   Copyright (C) 2001-2018 Free Software Foundation, Inc.
bdc76f
-   Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
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
-/* INPUT PARAMETERS
bdc76f
-     %r2 = address of string 1
bdc76f
-     %r3 = address of string 2.  */
bdc76f
-
bdc76f
-#include "sysdep.h"
bdc76f
-#include "asm-syntax.h"
bdc76f
-
bdc76f
-	.text
bdc76f
-ENTRY(strcmp)
bdc76f
-        slr   %r0,%r0
bdc76f
-0:	clst  %r2,%r3
bdc76f
-	jo    0b
bdc76f
-	jp    1f
bdc76f
-	jm    2f
bdc76f
-	slr   %r2,%r2
bdc76f
-	br    %r14
bdc76f
-1:	lhi   %r2,1
bdc76f
-	br    %r14
bdc76f
-2:	lhi   %r2,-1
bdc76f
-	br    %r14
bdc76f
-END(strcmp)
bdc76f
-libc_hidden_builtin_def (strcmp)
bdc76f
diff --git a/sysdeps/s390/s390-64/multiarch/strcmp.c b/sysdeps/s390/s390-64/multiarch/strcmp.c
bdc76f
deleted file mode 100644
bdc76f
index d06b0f3436b2abfd..0000000000000000
bdc76f
--- a/sysdeps/s390/s390-64/multiarch/strcmp.c
bdc76f
+++ /dev/null
bdc76f
@@ -1,21 +0,0 @@
bdc76f
-/* Multiple versions of strcmp.
bdc76f
-   Copyright (C) 2015-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
-/* This wrapper-file is needed, because otherwise file
bdc76f
-   sysdeps/s390/s390-[32|64]/strcmp.S will be used.  */
bdc76f
-#include <sysdeps/s390/multiarch/strcmp.c>
bdc76f
diff --git a/sysdeps/s390/multiarch/strcmp-vx.S b/sysdeps/s390/strcmp-vx.S
bdc76f
similarity index 90%
bdc76f
rename from sysdeps/s390/multiarch/strcmp-vx.S
bdc76f
rename to sysdeps/s390/strcmp-vx.S
bdc76f
index bcaeb564d47c58ff..801ad9d32bbd76c0 100644
bdc76f
--- a/sysdeps/s390/multiarch/strcmp-vx.S
bdc76f
+++ b/sysdeps/s390/strcmp-vx.S
bdc76f
@@ -16,7 +16,8 @@
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-strcmp.h>
bdc76f
+#if HAVE_STRCMP_Z13
bdc76f
 
bdc76f
 # include "sysdep.h"
bdc76f
 # include "asm-syntax.h"
bdc76f
@@ -36,7 +37,7 @@
bdc76f
    -v17=part of s2
bdc76f
    -v18=index of unequal
bdc76f
 */
bdc76f
-ENTRY(__strcmp_vx)
bdc76f
+ENTRY(STRCMP_Z13)
bdc76f
 	.machine "z13"
bdc76f
 	.machinemode "zarch_nohighgprs"
bdc76f
 
bdc76f
@@ -106,11 +107,13 @@ ENTRY(__strcmp_vx)
bdc76f
 .Lend_equal:
bdc76f
 	lghi	%r2,0
bdc76f
 	br	%r14
bdc76f
-END(__strcmp_vx)
bdc76f
+END(STRCMP_Z13)
bdc76f
 
bdc76f
-# define strcmp __strcmp_c
bdc76f
-# undef libc_hidden_builtin_def
bdc76f
-# define libc_hidden_builtin_def(name) strong_alias(__strcmp_c, __GI_strcmp)
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+# if ! HAVE_STRCMP_IFUNC
bdc76f
+strong_alias (STRCMP_Z13, strcmp)
bdc76f
+# endif
bdc76f
 
bdc76f
-#include <strcmp.S>
bdc76f
+# if ! HAVE_STRCMP_Z900_G5 && defined SHARED && IS_IN (libc)
bdc76f
+strong_alias (STRCMP_Z13, __GI_strcmp)
bdc76f
+# endif
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/s390-64/strcmp.S b/sysdeps/s390/strcmp-z900.S
bdc76f
similarity index 70%
bdc76f
rename from sysdeps/s390/s390-64/strcmp.S
bdc76f
rename to sysdeps/s390/strcmp-z900.S
bdc76f
index 6cf1addd8bdf1a19..67b3c8b2e5989cd2 100644
bdc76f
--- a/sysdeps/s390/s390-64/strcmp.S
bdc76f
+++ b/sysdeps/s390/strcmp-z900.S
bdc76f
@@ -21,21 +21,39 @@
bdc76f
      %r2 = address of string 1
bdc76f
      %r3 = address of string 2.  */
bdc76f
 
bdc76f
+#include <ifunc-strcmp.h>
bdc76f
 #include "sysdep.h"
bdc76f
 #include "asm-syntax.h"
bdc76f
 
bdc76f
+#if HAVE_STRCMP_Z900_G5
bdc76f
+# if defined __s390x__
bdc76f
+#  define SLGR	slgr
bdc76f
+#  define LGHI	lghi
bdc76f
+# else
bdc76f
+#  define SLGR	slr
bdc76f
+#  define LGHI	lhi
bdc76f
+# endif /* ! defined __s390x__  */
bdc76f
+
bdc76f
 	.text
bdc76f
-ENTRY(strcmp)
bdc76f
-        slr   %r0,%r0
bdc76f
+ENTRY(STRCMP_Z900_G5)
bdc76f
+	SLGR   %r0,%r0
bdc76f
 0:	clst  %r2,%r3
bdc76f
 	jo    0b
bdc76f
 	jp    1f
bdc76f
 	jm    2f
bdc76f
-	slgr  %r2,%r2
bdc76f
+	SLGR  %r2,%r2
bdc76f
 	br    %r14
bdc76f
-1:	lghi  %r2,1
bdc76f
+1:	LGHI  %r2,1
bdc76f
 	br    %r14
bdc76f
-2:	lghi  %r2,-1
bdc76f
+2:	LGHI  %r2,-1
bdc76f
 	br    %r14
bdc76f
-END(strcmp)
bdc76f
-libc_hidden_builtin_def (strcmp)
bdc76f
+END(STRCMP_Z900_G5)
bdc76f
+
bdc76f
+# if ! HAVE_STRCMP_IFUNC
bdc76f
+strong_alias (STRCMP_Z900_G5, strcmp)
bdc76f
+# endif
bdc76f
+
bdc76f
+# if defined SHARED && IS_IN (libc)
bdc76f
+strong_alias (STRCMP_Z900_G5, __GI_strcmp)
bdc76f
+# endif
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/strcmp.c b/sysdeps/s390/strcmp.c
bdc76f
similarity index 71%
bdc76f
rename from sysdeps/s390/multiarch/strcmp.c
bdc76f
rename to sysdeps/s390/strcmp.c
bdc76f
index 7c8b17b3041dd549..9efa30acaf21f4e8 100644
bdc76f
--- a/sysdeps/s390/multiarch/strcmp.c
bdc76f
+++ b/sysdeps/s390/strcmp.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-strcmp.h>
bdc76f
+
bdc76f
+#if HAVE_STRCMP_IFUNC
bdc76f
 # define strcmp __redirect_strcmp
bdc76f
 /* Omit the strcmp inline definitions because it would redefine strcmp.  */
bdc76f
 # define __NO_STRING_INLINES
bdc76f
@@ -24,6 +26,17 @@
bdc76f
 # include <ifunc-resolve.h>
bdc76f
 # undef strcmp
bdc76f
 
bdc76f
-s390_vx_libc_ifunc2_redirected (__redirect_strcmp, __strcmp, strcmp)
bdc76f
+# if HAVE_STRCMP_Z900_G5
bdc76f
+extern __typeof (__redirect_strcmp) STRCMP_Z900_G5 attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+# if HAVE_STRCMP_Z13
bdc76f
+extern __typeof (__redirect_strcmp) STRCMP_Z13 attribute_hidden;
bdc76f
+# endif
bdc76f
 
bdc76f
+s390_libc_ifunc_expr (__redirect_strcmp, strcmp,
bdc76f
+		      (HAVE_STRCMP_Z13 && (hwcap & HWCAP_S390_VX))
bdc76f
+		      ? STRCMP_Z13
bdc76f
+		      : STRCMP_DEFAULT
bdc76f
+		      )
bdc76f
 #endif