bdc76f
commit 89bfcbdf9d3d36eff0d544f655991149a7ae680b
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:17 2018 +0100
bdc76f
bdc76f
    S390: Refactor memrchr ifunc handling.
bdc76f
    
bdc76f
    The ifunc handling for memrchr 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 memrchr variants.
bdc76f
            * sysdeps/s390/Makefile (sysdep_routines): Add memrchr variants.
bdc76f
            * sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
            (__libc_ifunc_impl_list): Refactor ifunc handling for memrchr.
bdc76f
            * sysdeps/s390/multiarch/memrchr-c.c: Move to ...
bdc76f
            * sysdeps/s390/memrchr-c.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/memrchr-vx.S: Move to ...
bdc76f
            * sysdeps/s390/memrchr-vx.S: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/multiarch/memrchr.c: Move to ...
bdc76f
            * sysdeps/s390/memrchr.c: ... here and adjust ifunc handling.
bdc76f
            * sysdeps/s390/ifunc-memrchr.h: New file.
bdc76f
bdc76f
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
bdc76f
index 239426dbc1ce9d09..9a16ce1692e51607 100644
bdc76f
--- a/sysdeps/s390/Makefile
bdc76f
+++ b/sysdeps/s390/Makefile
bdc76f
@@ -55,5 +55,6 @@ sysdep_routines += bzero memset memset-z900 \
bdc76f
 		   strcspn strcspn-vx strcspn-c \
bdc76f
 		   memchr memchr-vx memchr-z900 \
bdc76f
 		   rawmemchr rawmemchr-vx rawmemchr-c \
bdc76f
-		   memccpy memccpy-vx memccpy-c
bdc76f
+		   memccpy memccpy-vx memccpy-c \
bdc76f
+		   memrchr memrchr-vx memrchr-c
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/ifunc-memrchr.h b/sysdeps/s390/ifunc-memrchr.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..9d80d5528dc92dab
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/ifunc-memrchr.h
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* memrchr 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_MEMRCHR_IFUNC	1
bdc76f
+#else
bdc76f
+# define HAVE_MEMRCHR_IFUNC	0
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
+# define HAVE_MEMRCHR_IFUNC_AND_VX_SUPPORT HAVE_MEMRCHR_IFUNC
bdc76f
+#else
bdc76f
+# define HAVE_MEMRCHR_IFUNC_AND_VX_SUPPORT 0
bdc76f
+#endif
bdc76f
+
bdc76f
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define MEMRCHR_DEFAULT	MEMRCHR_Z13
bdc76f
+# define HAVE_MEMRCHR_C		0
bdc76f
+# define HAVE_MEMRCHR_Z13	1
bdc76f
+#else
bdc76f
+# define MEMRCHR_DEFAULT	MEMRCHR_C
bdc76f
+# define HAVE_MEMRCHR_C		1
bdc76f
+# define HAVE_MEMRCHR_Z13	HAVE_MEMRCHR_IFUNC_AND_VX_SUPPORT
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_MEMRCHR_C
bdc76f
+# define MEMRCHR_C		__memrchr_c
bdc76f
+#else
bdc76f
+# define MEMRCHR_C		NULL
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_MEMRCHR_Z13
bdc76f
+# define MEMRCHR_Z13		__memrchr_vx
bdc76f
+#else
bdc76f
+# define MEMRCHR_Z13		NULL
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/memrchr-c.c b/sysdeps/s390/memrchr-c.c
bdc76f
similarity index 85%
bdc76f
rename from sysdeps/s390/multiarch/memrchr-c.c
bdc76f
rename to sysdeps/s390/memrchr-c.c
bdc76f
index 1e3c914a5d61dbc5..333c0fc8d1855323 100644
bdc76f
--- a/sysdeps/s390/multiarch/memrchr-c.c
bdc76f
+++ b/sysdeps/s390/memrchr-c.c
bdc76f
@@ -16,10 +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 MEMRCHR  __memrchr_c
bdc76f
+#include <ifunc-memrchr.h>
bdc76f
+
bdc76f
+#if HAVE_MEMRCHR_C
bdc76f
+# if HAVE_MEMRCHR_IFUNC
bdc76f
+#  define MEMRCHR MEMRCHR_C
bdc76f
+# endif
bdc76f
 
bdc76f
-# include <string.h>
bdc76f
-extern __typeof (__memrchr) __memrchr_c;
bdc76f
 # include <string/memrchr.c>
bdc76f
 #endif
bdc76f
diff --git a/sysdeps/s390/multiarch/memrchr-vx.S b/sysdeps/s390/memrchr-vx.S
bdc76f
similarity index 94%
bdc76f
rename from sysdeps/s390/multiarch/memrchr-vx.S
bdc76f
rename to sysdeps/s390/memrchr-vx.S
bdc76f
index 8e81f5ed7519c2cc..ba832f1b21ad5a4c 100644
bdc76f
--- a/sysdeps/s390/multiarch/memrchr-vx.S
bdc76f
+++ b/sysdeps/s390/memrchr-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-memrchr.h>
bdc76f
+
bdc76f
+#if HAVE_MEMRCHR_Z13
bdc76f
 
bdc76f
 # include "sysdep.h"
bdc76f
 # include "asm-syntax.h"
bdc76f
@@ -40,7 +42,7 @@
bdc76f
    -v18=c replicated
bdc76f
    -v20=permute pattern
bdc76f
 */
bdc76f
-ENTRY(__memrchr_vx)
bdc76f
+ENTRY(MEMRCHR_Z13)
bdc76f
 	.machine "z13"
bdc76f
 	.machinemode "zarch_nohighgprs"
bdc76f
 
bdc76f
@@ -156,5 +158,11 @@ ENTRY(__memrchr_vx)
bdc76f
 
bdc76f
 	clgijhe	%r4,64,.Lloop64	/* If n >= 64 -> loop64.  */
bdc76f
 	j	.Llt64
bdc76f
-END(__memrchr_vx)
bdc76f
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
bdc76f
+END(MEMRCHR_Z13)
bdc76f
+
bdc76f
+# if ! HAVE_MEMRCHR_IFUNC
bdc76f
+strong_alias (MEMRCHR_Z13, __memrchr)
bdc76f
+weak_alias (__memrchr, memrchr)
bdc76f
+# endif
bdc76f
+
bdc76f
+#endif /* HAVE_MEMRCHR_Z13  */
bdc76f
diff --git a/sysdeps/s390/multiarch/memrchr.c b/sysdeps/s390/memrchr.c
bdc76f
similarity index 68%
bdc76f
rename from sysdeps/s390/multiarch/memrchr.c
bdc76f
rename to sysdeps/s390/memrchr.c
bdc76f
index 43a44abcf6cc3bdc..d995e9961c1cc9eb 100644
bdc76f
--- a/sysdeps/s390/multiarch/memrchr.c
bdc76f
+++ b/sysdeps/s390/memrchr.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-memrchr.h>
bdc76f
+
bdc76f
+#if HAVE_MEMRCHR_IFUNC
bdc76f
 # include <string.h>
bdc76f
 # include <ifunc-resolve.h>
bdc76f
 
bdc76f
-s390_vx_libc_ifunc (__memrchr)
bdc76f
-weak_alias (__memrchr, memrchr)
bdc76f
+# if HAVE_MEMRCHR_C
bdc76f
+extern __typeof (__memrchr) MEMRCHR_C attribute_hidden;
bdc76f
+# endif
bdc76f
 
bdc76f
-#else
bdc76f
-# include <string/memrchr.c>
bdc76f
-#endif /* !(defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)) */
bdc76f
+# if HAVE_MEMRCHR_Z13
bdc76f
+extern __typeof (__memrchr) MEMRCHR_Z13 attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+s390_libc_ifunc_expr (__memrchr, __memrchr,
bdc76f
+		      (HAVE_MEMRCHR_Z13 && (hwcap & HWCAP_S390_VX))
bdc76f
+		      ? MEMRCHR_Z13
bdc76f
+		      : MEMRCHR_DEFAULT
bdc76f
+		      )
bdc76f
+weak_alias (__memrchr, memrchr)
bdc76f
+#endif /* HAVE_MEMRCHR_IFUNC  */
bdc76f
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
bdc76f
index d5a32fc309ba4b3c..260b514936b93306 100644
bdc76f
--- a/sysdeps/s390/multiarch/Makefile
bdc76f
+++ b/sysdeps/s390/multiarch/Makefile
bdc76f
@@ -1,7 +1,3 @@
bdc76f
-ifeq ($(subdir),string)
bdc76f
-sysdep_routines += memrchr memrchr-vx memrchr-c
bdc76f
-endif
bdc76f
-
bdc76f
 ifeq ($(subdir),wcsmbs)
bdc76f
 sysdep_routines += wcslen wcslen-vx wcslen-c \
bdc76f
 		   wcsnlen wcsnlen-vx wcsnlen-c \
bdc76f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
index b8917747f0f23cd9..0f01b99691002be0 100644
bdc76f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
@@ -45,6 +45,7 @@
bdc76f
 #include <ifunc-memchr.h>
bdc76f
 #include <ifunc-rawmemchr.h>
bdc76f
 #include <ifunc-memccpy.h>
bdc76f
+#include <ifunc-memrchr.h>
bdc76f
 
bdc76f
 /* Maximum number of IFUNC implementations.  */
bdc76f
 #define MAX_IFUNC	3
bdc76f
@@ -411,6 +412,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 		)
bdc76f
 #endif /* HAVE_MEMCCPY_IFUNC  */
bdc76f
 
bdc76f
+#if HAVE_MEMRCHR_IFUNC
bdc76f
+    IFUNC_IMPL (i, name, memrchr,
bdc76f
+# if HAVE_MEMRCHR_Z13
bdc76f
+		IFUNC_IMPL_ADD (array, i, memrchr,
bdc76f
+				dl_hwcap & HWCAP_S390_VX, MEMRCHR_Z13)
bdc76f
+# endif
bdc76f
+# if HAVE_MEMRCHR_C
bdc76f
+		IFUNC_IMPL_ADD (array, i, memrchr, 1, MEMRCHR_C)
bdc76f
+# endif
bdc76f
+		)
bdc76f
+#endif /* HAVE_MEMRCHR_IFUNC  */
bdc76f
+
bdc76f
 #ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
 
bdc76f
 # define IFUNC_VX_IMPL(FUNC)						\
bdc76f
@@ -457,8 +470,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 
bdc76f
   IFUNC_VX_IMPL (wmemcmp);
bdc76f
 
bdc76f
-  IFUNC_VX_IMPL (memrchr);
bdc76f
-
bdc76f
 #endif /* HAVE_S390_VX_ASM_SUPPORT */
bdc76f
 
bdc76f
   return i;