bdc76f
commit 25654a8c74dce51e162c29749c6bd6d2a67490e6
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:25 2018 +0100
bdc76f
bdc76f
    S390: Refactor wmemcmp ifunc handling.
bdc76f
    
bdc76f
    The ifunc handling for wmemcmp 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 wmemcmp variants.
bdc76f
            * sysdeps/s390/Makefile (sysdep_routines): Add wmemcmp variants.
bdc76f
            * sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
            (__libc_ifunc_impl_list): Refactor ifunc handling for wmemcmp.
bdc76f
            * sysdeps/s390/multiarch/wmemcmp-c.c: Move to ...
bdc76f
            * sysdeps/s390/wmemcmp-c.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/wmemcmp-vx.S: Move to ...
bdc76f
            * sysdeps/s390/wmemcmp-vx.S: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/wmemcmp.c: Move to ...
bdc76f
            * sysdeps/s390/wmemcmp.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/ifunc-wmemcmp.h: New file.
bdc76f
bdc76f
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
bdc76f
index f9a71276331b396a..3f7de6613c343819 100644
bdc76f
--- a/sysdeps/s390/Makefile
bdc76f
+++ b/sysdeps/s390/Makefile
bdc76f
@@ -77,5 +77,6 @@ sysdep_routines += wcslen wcslen-vx wcslen-c \
bdc76f
 		   wcspbrk wcspbrk-vx wcspbrk-c \
bdc76f
 		   wcscspn wcscspn-vx wcscspn-c \
bdc76f
 		   wmemchr wmemchr-vx wmemchr-c \
bdc76f
-		   wmemset wmemset-vx wmemset-c
bdc76f
+		   wmemset wmemset-vx wmemset-c \
bdc76f
+		   wmemcmp wmemcmp-vx wmemcmp-c
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/ifunc-wmemcmp.h b/sysdeps/s390/ifunc-wmemcmp.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..1b38a014590ec060
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/ifunc-wmemcmp.h
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* wmemcmp 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_WMEMCMP_IFUNC	1
bdc76f
+#else
bdc76f
+# define HAVE_WMEMCMP_IFUNC	0
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
+# define HAVE_WMEMCMP_IFUNC_AND_VX_SUPPORT HAVE_WMEMCMP_IFUNC
bdc76f
+#else
bdc76f
+# define HAVE_WMEMCMP_IFUNC_AND_VX_SUPPORT 0
bdc76f
+#endif
bdc76f
+
bdc76f
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define WMEMCMP_DEFAULT	WMEMCMP_Z13
bdc76f
+# define HAVE_WMEMCMP_C		0
bdc76f
+# define HAVE_WMEMCMP_Z13	1
bdc76f
+#else
bdc76f
+# define WMEMCMP_DEFAULT	WMEMCMP_C
bdc76f
+# define HAVE_WMEMCMP_C		1
bdc76f
+# define HAVE_WMEMCMP_Z13	HAVE_WMEMCMP_IFUNC_AND_VX_SUPPORT
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_WMEMCMP_C
bdc76f
+# define WMEMCMP_C		__wmemcmp_c
bdc76f
+#else
bdc76f
+# define WMEMCMP_C		NULL
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_WMEMCMP_Z13
bdc76f
+# define WMEMCMP_Z13		__wmemcmp_vx
bdc76f
+#else
bdc76f
+# define WMEMCMP_Z13		NULL
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index cc6dd7adb10ee8ad..fec36153047e4585 100644
bdc76f
--- a/sysdeps/s390/multiarch/Makefile
bdc76f
+++ b/sysdeps/s390/multiarch/Makefile
bdc76f
@@ -1,7 +1,3 @@
bdc76f
-ifeq ($(subdir),wcsmbs)
bdc76f
-sysdep_routines += wmemcmp wmemcmp-vx wmemcmp-c
bdc76f
-endif
bdc76f
-
bdc76f
 ifeq ($(subdir),iconvdata)
bdc76f
 override define generate-8bit-table
bdc76f
 $(make-target-directory)
bdc76f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
index 7040959269c1612b..177c5fd6fe269d9b 100644
bdc76f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
@@ -64,6 +64,7 @@
bdc76f
 #include <ifunc-wcscspn.h>
bdc76f
 #include <ifunc-wmemchr.h>
bdc76f
 #include <ifunc-wmemset.h>
bdc76f
+#include <ifunc-wmemcmp.h>
bdc76f
 
bdc76f
 /* Maximum number of IFUNC implementations.  */
bdc76f
 #define MAX_IFUNC	3
bdc76f
@@ -658,17 +659,17 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 		)
bdc76f
 #endif /* HAVE_WMEMSET_IFUNC  */
bdc76f
 
bdc76f
-#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
-
bdc76f
-# define IFUNC_VX_IMPL(FUNC)						\
bdc76f
-  IFUNC_IMPL (i, name, FUNC,						\
bdc76f
-	      IFUNC_IMPL_ADD (array, i, FUNC, dl_hwcap & HWCAP_S390_VX, \
bdc76f
-			      __##FUNC##_vx)				\
bdc76f
-	      IFUNC_IMPL_ADD (array, i, FUNC, 1, __##FUNC##_c))
bdc76f
-
bdc76f
-  IFUNC_VX_IMPL (wmemcmp);
bdc76f
-
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT */
bdc76f
+#if HAVE_WMEMCMP_IFUNC
bdc76f
+    IFUNC_IMPL (i, name, wmemcmp,
bdc76f
+# if HAVE_WMEMCMP_Z13
bdc76f
+		IFUNC_IMPL_ADD (array, i, wmemcmp,
bdc76f
+				dl_hwcap & HWCAP_S390_VX, WMEMCMP_Z13)
bdc76f
+# endif
bdc76f
+# if HAVE_WMEMCMP_C
bdc76f
+		IFUNC_IMPL_ADD (array, i, wmemcmp, 1, WMEMCMP_C)
bdc76f
+# endif
bdc76f
+		)
bdc76f
+#endif /* HAVE_WMEMCMP_IFUNC  */
bdc76f
 
bdc76f
   return i;
bdc76f
 }
bdc76f
diff --git a/sysdeps/s390/multiarch/wmemcmp-c.c b/sysdeps/s390/wmemcmp-c.c
bdc76f
similarity index 85%
bdc76f
rename from sysdeps/s390/multiarch/wmemcmp-c.c
bdc76f
rename to sysdeps/s390/wmemcmp-c.c
bdc76f
index 2fd39d501360e6f8..0c73636adda82f8b 100644
bdc76f
--- a/sysdeps/s390/multiarch/wmemcmp-c.c
bdc76f
+++ b/sysdeps/s390/wmemcmp-c.c
bdc76f
@@ -16,11 +16,12 @@
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 WMEMCMP  __wmemcmp_c
bdc76f
+#include <ifunc-wmemcmp.h>
bdc76f
 
bdc76f
-# include <wchar.h>
bdc76f
-extern __typeof (wmemcmp) __wmemcmp_c;
bdc76f
+#if HAVE_WMEMCMP_C
bdc76f
+# if HAVE_WMEMCMP_IFUNC
bdc76f
+#  define WMEMCMP WMEMCMP_C
bdc76f
+# endif
bdc76f
 
bdc76f
 # include <wcsmbs/wmemcmp.c>
bdc76f
 #endif
bdc76f
diff --git a/sysdeps/s390/multiarch/wmemcmp-vx.S b/sysdeps/s390/wmemcmp-vx.S
bdc76f
similarity index 95%
bdc76f
rename from sysdeps/s390/multiarch/wmemcmp-vx.S
bdc76f
rename to sysdeps/s390/wmemcmp-vx.S
bdc76f
index e2fc21e4192b0dd8..87ae21b4f13c5d69 100644
bdc76f
--- a/sysdeps/s390/multiarch/wmemcmp-vx.S
bdc76f
+++ b/sysdeps/s390/wmemcmp-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-wmemcmp.h>
bdc76f
+#if HAVE_WMEMCMP_Z13
bdc76f
 
bdc76f
 # include "sysdep.h"
bdc76f
 # include "asm-syntax.h"
bdc76f
@@ -37,7 +38,7 @@
bdc76f
    -v17=part of s2
bdc76f
    -v18=index of unequal
bdc76f
 */
bdc76f
-ENTRY(__wmemcmp_vx)
bdc76f
+ENTRY(WMEMCMP_Z13)
bdc76f
 	.machine "z13"
bdc76f
 	.machinemode "zarch_nohighgprs"
bdc76f
 
bdc76f
@@ -145,5 +146,9 @@ ENTRY(__wmemcmp_vx)
bdc76f
 	la	%r2,0(%r5,%r2)
bdc76f
 	la	%r3,0(%r5,%r3)
bdc76f
 	j	.Lremaining
bdc76f
-END(__wmemcmp_vx)
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+END(WMEMCMP_Z13)
bdc76f
+
bdc76f
+# if ! HAVE_WMEMCMP_IFUNC
bdc76f
+strong_alias (WMEMCMP_Z13, wmemcmp)
bdc76f
+# endif
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/wmemcmp.c b/sysdeps/s390/wmemcmp.c
bdc76f
similarity index 69%
bdc76f
rename from sysdeps/s390/multiarch/wmemcmp.c
bdc76f
rename to sysdeps/s390/wmemcmp.c
bdc76f
index a4cb440c452fd6a9..6c8ca5f0e8ffdb50 100644
bdc76f
--- a/sysdeps/s390/multiarch/wmemcmp.c
bdc76f
+++ b/sysdeps/s390/wmemcmp.c
bdc76f
@@ -16,12 +16,23 @@
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-wmemcmp.h>
bdc76f
+
bdc76f
+#if HAVE_WMEMCMP_IFUNC
bdc76f
 # include <wchar.h>
bdc76f
 # include <ifunc-resolve.h>
bdc76f
 
bdc76f
-s390_vx_libc_ifunc2 (__wmemcmp, wmemcmp)
bdc76f
+# if HAVE_WMEMCMP_C
bdc76f
+extern __typeof (wmemcmp) WMEMCMP_C attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+# if HAVE_WMEMCMP_Z13
bdc76f
+extern __typeof (wmemcmp) WMEMCMP_Z13 attribute_hidden;
bdc76f
+# endif
bdc76f
 
bdc76f
-#else
bdc76f
-# include <wcsmbs/wmemcmp.c>
bdc76f
-#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */
bdc76f
+s390_libc_ifunc_expr (wmemcmp, wmemcmp,
bdc76f
+		      (HAVE_WMEMCMP_Z13 && (hwcap & HWCAP_S390_VX))
bdc76f
+		      ? WMEMCMP_Z13
bdc76f
+		      : WMEMCMP_DEFAULT
bdc76f
+		      )
bdc76f
+#endif