d8307d
commit 581a051c2e09a847332d4750f6132de0f0ad15b6
d8307d
Author: Stefan Liebler <stli@linux.ibm.com>
d8307d
Date:   Tue Dec 18 13:57:16 2018 +0100
d8307d
d8307d
    S390: Refactor memchr ifunc handling.
d8307d
    
d8307d
    The ifunc handling for memchr is adjusted in order to omit ifunc
d8307d
    variants if those will never be used as the minimum architecture level
d8307d
    already supports newer CPUs by default.
d8307d
    Glibc internal calls will then also use the "newer" ifunc variant.
d8307d
    
d8307d
    Note: The fallback s390-32/s390-64 ifunc variants with srst instruction
d8307d
    are now moved to the unified memchr-z900.S file which can be used for
d8307d
    31/64bit. The s390-32/s390-64 files multiarch/memchr.c and memchr.S
d8307d
    are deleted.
d8307d
    
d8307d
    ChangeLog:
d8307d
    
d8307d
            * sysdeps/s390/multiarch/Makefile
d8307d
            (sysdep_routines): Remove memchr variants.
d8307d
            * sysdeps/s390/Makefile (sysdep_routines): Add memchr variants.
d8307d
            * sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
            (__libc_ifunc_impl_list): Refactor ifunc handling for memchr.
d8307d
            * sysdeps/s390/multiarch/memchr-vx.S: Move to ...
d8307d
            * sysdeps/s390/memchr-vx.S: ... here and adjust ifunc handling.
d8307d
            * sysdeps/s390/multiarch/memchr.c: Move to ...
d8307d
            * sysdeps/s390/memchr.c: ... here and adjust ifunc handling.
d8307d
            * sysdeps/s390/ifunc-memchr.h: New file.
d8307d
            * sysdeps/s390/s390-64/memchr.S: Move to ...
d8307d
            * sysdeps/s390/memchr-z900.S: ... here and adjust to be usable
d8307d
            for 31/64bit and ifunc handling.
d8307d
            * sysdeps/s390/s390-32/multiarch/memchr.c: Delete file.
d8307d
            * sysdeps/s390/s390-64/multiarch/memchr.c: Likewise.
d8307d
            * sysdeps/s390/s390-32/memchr.S: Likewise.
d8307d
d8307d
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
d8307d
index 092d55826fbd15a5..816b2fccdc75e4cf 100644
d8307d
--- a/sysdeps/s390/Makefile
d8307d
+++ b/sysdeps/s390/Makefile
d8307d
@@ -52,5 +52,6 @@ sysdep_routines += bzero memset memset-z900 \
d8307d
 		   strrchr strrchr-vx strrchr-c \
d8307d
 		   strspn strspn-vx strspn-c \
d8307d
 		   strpbrk strpbrk-vx strpbrk-c \
d8307d
-		   strcspn strcspn-vx strcspn-c
d8307d
+		   strcspn strcspn-vx strcspn-c \
d8307d
+		   memchr memchr-vx memchr-z900
d8307d
 endif
d8307d
diff --git a/sysdeps/s390/ifunc-memchr.h b/sysdeps/s390/ifunc-memchr.h
d8307d
new file mode 100644
d8307d
index 0000000000000000..5d1327b45353322b
d8307d
--- /dev/null
d8307d
+++ b/sysdeps/s390/ifunc-memchr.h
d8307d
@@ -0,0 +1,52 @@
d8307d
+/* memchr variant information on S/390 version.
d8307d
+   Copyright (C) 2018 Free Software Foundation, Inc.
d8307d
+   This file is part of the GNU C Library.
d8307d
+
d8307d
+   The GNU C Library is free software; you can redistribute it and/or
d8307d
+   modify it under the terms of the GNU Lesser General Public
d8307d
+   License as published by the Free Software Foundation; either
d8307d
+   version 2.1 of the License, or (at your option) any later version.
d8307d
+
d8307d
+   The GNU C Library is distributed in the hope that it will be useful,
d8307d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
d8307d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d8307d
+   Lesser General Public License for more details.
d8307d
+
d8307d
+   You should have received a copy of the GNU Lesser General Public
d8307d
+   License along with the GNU C Library; if not, see
d8307d
+   <http://www.gnu.org/licenses/>.  */
d8307d
+
d8307d
+#if defined USE_MULTIARCH && IS_IN (libc)		\
d8307d
+  && ! defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
d8307d
+# define HAVE_MEMCHR_IFUNC	1
d8307d
+#else
d8307d
+# define HAVE_MEMCHR_IFUNC	0
d8307d
+#endif
d8307d
+
d8307d
+#ifdef HAVE_S390_VX_ASM_SUPPORT
d8307d
+# define HAVE_MEMCHR_IFUNC_AND_VX_SUPPORT HAVE_MEMCHR_IFUNC
d8307d
+#else
d8307d
+# define HAVE_MEMCHR_IFUNC_AND_VX_SUPPORT 0
d8307d
+#endif
d8307d
+
d8307d
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
d8307d
+# define MEMCHR_DEFAULT		MEMCHR_Z13
d8307d
+# define HAVE_MEMCHR_Z900_G5	0
d8307d
+# define HAVE_MEMCHR_Z13	1
d8307d
+#else
d8307d
+# define MEMCHR_DEFAULT		MEMCHR_Z900_G5
d8307d
+# define HAVE_MEMCHR_Z900_G5	1
d8307d
+# define HAVE_MEMCHR_Z13	HAVE_MEMCHR_IFUNC_AND_VX_SUPPORT
d8307d
+#endif
d8307d
+
d8307d
+#if HAVE_MEMCHR_Z900_G5
d8307d
+# define MEMCHR_Z900_G5		__memchr_default
d8307d
+#else
d8307d
+# define MEMCHR_Z900_G5		NULL
d8307d
+#endif
d8307d
+
d8307d
+#if HAVE_MEMCHR_Z13
d8307d
+# define MEMCHR_Z13		__memchr_vx
d8307d
+#else
d8307d
+# define MEMCHR_Z13		NULL
d8307d
+#endif
d8307d
diff --git a/sysdeps/s390/multiarch/memchr-vx.S b/sysdeps/s390/memchr-vx.S
d8307d
similarity index 92%
d8307d
rename from sysdeps/s390/multiarch/memchr-vx.S
d8307d
rename to sysdeps/s390/memchr-vx.S
d8307d
index 77d31e0036915665..274e7971ca7e9413 100644
d8307d
--- a/sysdeps/s390/multiarch/memchr-vx.S
d8307d
+++ b/sysdeps/s390/memchr-vx.S
d8307d
@@ -16,7 +16,8 @@
d8307d
    License along with the GNU C Library; if not, see
d8307d
    <http://www.gnu.org/licenses/>.  */
d8307d
 
d8307d
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
d8307d
+#include <ifunc-memchr.h>
d8307d
+#if HAVE_MEMCHR_Z13
d8307d
 
d8307d
 # include "sysdep.h"
d8307d
 # include "asm-syntax.h"
d8307d
@@ -38,7 +39,7 @@
d8307d
    -v17=index of found c
d8307d
    -v18=c replicated
d8307d
 */
d8307d
-ENTRY(__memchr_vx)
d8307d
+ENTRY(MEMCHR_Z13)
d8307d
 
d8307d
 	.machine "z13"
d8307d
 	.machinemode "zarch_nohighgprs"
d8307d
@@ -149,11 +150,14 @@ ENTRY(__memchr_vx)
d8307d
 	clgrjl	%r0,%r4,.Lloop64
d8307d
 
d8307d
 	j	.Llt64
d8307d
-END(__memchr_vx)
d8307d
+END(MEMCHR_Z13)
d8307d
 
d8307d
-# define memchr __memchr_c
d8307d
-# undef libc_hidden_builtin_def
d8307d
-# define libc_hidden_builtin_def(name) strong_alias(__memchr_c, __GI_memchr)
d8307d
-#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
d8307d
+# if ! HAVE_MEMCHR_IFUNC
d8307d
+strong_alias (MEMCHR_Z13, __memchr)
d8307d
+weak_alias (__memchr, memchr)
d8307d
+# endif
d8307d
 
d8307d
-#include <memchr.S>
d8307d
+# if ! HAVE_MEMCHR_Z900_G5 && defined SHARED && IS_IN (libc)
d8307d
+strong_alias (MEMCHR_Z13, __GI_memchr)
d8307d
+# endif
d8307d
+#endif
d8307d
diff --git a/sysdeps/s390/s390-64/memchr.S b/sysdeps/s390/memchr-z900.S
d8307d
similarity index 63%
d8307d
rename from sysdeps/s390/s390-64/memchr.S
d8307d
rename to sysdeps/s390/memchr-z900.S
d8307d
index a19fcafa147dc338..c016bc41c61be2dc 100644
d8307d
--- a/sysdeps/s390/s390-64/memchr.S
d8307d
+++ b/sysdeps/s390/memchr-z900.S
d8307d
@@ -1,4 +1,4 @@
d8307d
-/* Search a character in a block of memory.  64 bit S/390 version.
d8307d
+/* Search a character in a block of memory.  31/64 bit S/390 version.
d8307d
    Copyright (C) 2001-2018 Free Software Foundation, Inc.
d8307d
    Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
d8307d
    This file is part of the GNU C Library.
d8307d
@@ -22,19 +22,42 @@
d8307d
      %r3 = character to find
d8307d
      %r4 = number of bytes to search.  */
d8307d
 
d8307d
+#include <ifunc-memchr.h>
d8307d
 #include "sysdep.h"
d8307d
 #include "asm-syntax.h"
d8307d
 
d8307d
+#if HAVE_MEMCHR_Z900_G5
d8307d
+# if defined __s390x__
d8307d
+#  define SLGR	slgr
d8307d
+#  define LGHI	lghi
d8307d
+#  define NGR	ngr
d8307d
+#  define LGR	lgr
d8307d
+# else
d8307d
+#  define SLGR	slr
d8307d
+#  define LGHI	lhi
d8307d
+#  define NGR	nr
d8307d
+#  define LGR	lr
d8307d
+# endif /* ! defined __s390x__  */
d8307d
+
d8307d
 	.text
d8307d
-ENTRY(memchr)
d8307d
-	lghi  %r0,0xff
d8307d
-	ngr   %r0,%r3
d8307d
-	lgr   %r1,%r2
d8307d
+ENTRY(MEMCHR_Z900_G5)
d8307d
+	LGHI  %r0,0xff
d8307d
+	NGR   %r0,%r3
d8307d
+	LGR   %r1,%r2
d8307d
 	la    %r2,0(%r4,%r1)
d8307d
 0:	srst  %r2,%r1
d8307d
 	jo    0b
d8307d
 	brc   13,1f
d8307d
-	slgr  %r2,%r2
d8307d
+	SLGR  %r2,%r2
d8307d
 1:	br    %r14
d8307d
-END(memchr)
d8307d
-libc_hidden_builtin_def (memchr)
d8307d
+END(MEMCHR_Z900_G5)
d8307d
+
d8307d
+# if ! HAVE_MEMCHR_IFUNC
d8307d
+strong_alias (MEMCHR_Z900_G5, __memchr)
d8307d
+weak_alias (__memchr, memchr)
d8307d
+# endif
d8307d
+
d8307d
+# if defined SHARED && IS_IN (libc)
d8307d
+strong_alias (MEMCHR_Z900_G5, __GI_memchr)
d8307d
+# endif
d8307d
+#endif
d8307d
diff --git a/sysdeps/s390/multiarch/memchr.c b/sysdeps/s390/memchr.c
d8307d
similarity index 68%
d8307d
rename from sysdeps/s390/multiarch/memchr.c
d8307d
rename to sysdeps/s390/memchr.c
d8307d
index 3885ebaa4d90ed1a..490f1b66002aae05 100644
d8307d
--- a/sysdeps/s390/multiarch/memchr.c
d8307d
+++ b/sysdeps/s390/memchr.c
d8307d
@@ -16,12 +16,26 @@
d8307d
    License along with the GNU C Library; if not, see
d8307d
    <http://www.gnu.org/licenses/>.  */
d8307d
 
d8307d
-#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
d8307d
+#include <ifunc-memchr.h>
d8307d
+
d8307d
+#if HAVE_MEMCHR_IFUNC
d8307d
 # define memchr __redirect_memchr
d8307d
 # include <string.h>
d8307d
 # undef memchr
d8307d
 # include <ifunc-resolve.h>
d8307d
 
d8307d
-s390_vx_libc_ifunc2_redirected (__redirect_memchr, __memchr, memchr)
d8307d
+# if HAVE_MEMCHR_Z900_G5
d8307d
+extern __typeof (__redirect_memchr) MEMCHR_Z900_G5 attribute_hidden;
d8307d
+# endif
d8307d
+
d8307d
+# if HAVE_MEMCHR_Z13
d8307d
+extern __typeof (__redirect_memchr) MEMCHR_Z13 attribute_hidden;
d8307d
+# endif
d8307d
 
d8307d
+s390_libc_ifunc_expr (__redirect_memchr, __memchr,
d8307d
+		      (HAVE_MEMCHR_Z13 && (hwcap & HWCAP_S390_VX))
d8307d
+		      ? MEMCHR_Z13
d8307d
+		      : MEMCHR_DEFAULT
d8307d
+		      )
d8307d
+weak_alias (__memchr, memchr)
d8307d
 #endif
d8307d
diff --git a/sysdeps/s390/multiarch/Makefile b/sysdeps/s390/multiarch/Makefile
d8307d
index 1578f21af4a1bd06..fa1f7b81db912be0 100644
d8307d
--- a/sysdeps/s390/multiarch/Makefile
d8307d
+++ b/sysdeps/s390/multiarch/Makefile
d8307d
@@ -1,6 +1,5 @@
d8307d
 ifeq ($(subdir),string)
d8307d
-sysdep_routines += memchr memchr-vx \
d8307d
-		   rawmemchr rawmemchr-vx rawmemchr-c \
d8307d
+sysdep_routines += rawmemchr rawmemchr-vx rawmemchr-c \
d8307d
 		   memccpy memccpy-vx memccpy-c \
d8307d
 		   memrchr memrchr-vx memrchr-c
d8307d
 endif
d8307d
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
index 2d48c99c8d5663fe..b4be0140424aed69 100644
d8307d
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
@@ -42,6 +42,7 @@
d8307d
 #include <ifunc-strspn.h>
d8307d
 #include <ifunc-strpbrk.h>
d8307d
 #include <ifunc-strcspn.h>
d8307d
+#include <ifunc-memchr.h>
d8307d
 
d8307d
 /* Maximum number of IFUNC implementations.  */
d8307d
 #define MAX_IFUNC	3
d8307d
@@ -372,6 +373,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
d8307d
 		)
d8307d
 #endif /* HAVE_STRCSPN_IFUNC  */
d8307d
 
d8307d
+#if HAVE_MEMCHR_IFUNC
d8307d
+    IFUNC_IMPL (i, name, memchr,
d8307d
+# if HAVE_MEMCHR_Z13
d8307d
+		IFUNC_IMPL_ADD (array, i, memchr,
d8307d
+				dl_hwcap & HWCAP_S390_VX, MEMCHR_Z13)
d8307d
+# endif
d8307d
+# if HAVE_MEMCHR_Z900_G5
d8307d
+		IFUNC_IMPL_ADD (array, i, memchr, 1, MEMCHR_Z900_G5)
d8307d
+# endif
d8307d
+		)
d8307d
+#endif /* HAVE_MEMCHR_IFUNC  */
d8307d
+
d8307d
 #ifdef HAVE_S390_VX_ASM_SUPPORT
d8307d
 
d8307d
 # define IFUNC_VX_IMPL(FUNC)						\
d8307d
@@ -412,7 +425,6 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
d8307d
 
d8307d
   IFUNC_VX_IMPL (wcscspn);
d8307d
 
d8307d
-  IFUNC_VX_IMPL (memchr);
d8307d
   IFUNC_VX_IMPL (wmemchr);
d8307d
   IFUNC_VX_IMPL (rawmemchr);
d8307d
 
d8307d
diff --git a/sysdeps/s390/s390-32/memchr.S b/sysdeps/s390/s390-32/memchr.S
d8307d
deleted file mode 100644
d8307d
index 54f9b85f578fa1c7..0000000000000000
d8307d
--- a/sysdeps/s390/s390-32/memchr.S
d8307d
+++ /dev/null
d8307d
@@ -1,41 +0,0 @@
d8307d
-/* Search a character in a block of memory.  For IBM S390
d8307d
-   Copyright (C) 2000-2018 Free Software Foundation, Inc.
d8307d
-   This file is part of the GNU C Library.
d8307d
-   Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com).
d8307d
-
d8307d
-   The GNU C Library is free software; you can redistribute it and/or
d8307d
-   modify it under the terms of the GNU Lesser General Public
d8307d
-   License as published by the Free Software Foundation; either
d8307d
-   version 2.1 of the License, or (at your option) any later version.
d8307d
-
d8307d
-   The GNU C Library is distributed in the hope that it will be useful,
d8307d
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
d8307d
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d8307d
-   Lesser General Public License for more details.
d8307d
-
d8307d
-   You should have received a copy of the GNU Lesser General Public
d8307d
-   License along with the GNU C Library; if not, see
d8307d
-   <http://www.gnu.org/licenses/>.  */
d8307d
-
d8307d
-/*
d8307d
- * R2 = address to memory area
d8307d
- * R3 = character to find
d8307d
- * R4 = number of bytes to search
d8307d
- */
d8307d
-
d8307d
-#include "sysdep.h"
d8307d
-#include "asm-syntax.h"
d8307d
-
d8307d
-	.text
d8307d
-ENTRY(memchr)
d8307d
-	lhi   %r0,0xff
d8307d
-	nr    %r0,%r3
d8307d
-	lr    %r1,%r2
d8307d
-	la    %r2,0(%r4,%r1)
d8307d
-0:      srst  %r2,%r1
d8307d
-	jo    0b
d8307d
-	brc   13,1f
d8307d
-	slr   %r2,%r2
d8307d
-1:      br    %r14
d8307d
-END(memchr)
d8307d
-libc_hidden_builtin_def (memchr)
d8307d
diff --git a/sysdeps/s390/s390-32/multiarch/memchr.c b/sysdeps/s390/s390-32/multiarch/memchr.c
d8307d
deleted file mode 100644
d8307d
index 5e1610afa43ee549..0000000000000000
d8307d
--- a/sysdeps/s390/s390-32/multiarch/memchr.c
d8307d
+++ /dev/null
d8307d
@@ -1,21 +0,0 @@
d8307d
-/* Multiple versions of memchr.
d8307d
-   Copyright (C) 2015-2018 Free Software Foundation, Inc.
d8307d
-   This file is part of the GNU C Library.
d8307d
-
d8307d
-   The GNU C Library is free software; you can redistribute it and/or
d8307d
-   modify it under the terms of the GNU Lesser General Public
d8307d
-   License as published by the Free Software Foundation; either
d8307d
-   version 2.1 of the License, or (at your option) any later version.
d8307d
-
d8307d
-   The GNU C Library is distributed in the hope that it will be useful,
d8307d
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
d8307d
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d8307d
-   Lesser General Public License for more details.
d8307d
-
d8307d
-   You should have received a copy of the GNU Lesser General Public
d8307d
-   License along with the GNU C Library; if not, see
d8307d
-   <http://www.gnu.org/licenses/>.  */
d8307d
-
d8307d
-/* This wrapper-file is needed, because otherwise file
d8307d
-   sysdeps/s390/s390-[32|64]/memchr.S will be used.  */
d8307d
-#include <sysdeps/s390/multiarch/memchr.c>
d8307d
diff --git a/sysdeps/s390/s390-64/multiarch/memchr.c b/sysdeps/s390/s390-64/multiarch/memchr.c
d8307d
deleted file mode 100644
d8307d
index 5e1610afa43ee549..0000000000000000
d8307d
--- a/sysdeps/s390/s390-64/multiarch/memchr.c
d8307d
+++ /dev/null
d8307d
@@ -1,21 +0,0 @@
d8307d
-/* Multiple versions of memchr.
d8307d
-   Copyright (C) 2015-2018 Free Software Foundation, Inc.
d8307d
-   This file is part of the GNU C Library.
d8307d
-
d8307d
-   The GNU C Library is free software; you can redistribute it and/or
d8307d
-   modify it under the terms of the GNU Lesser General Public
d8307d
-   License as published by the Free Software Foundation; either
d8307d
-   version 2.1 of the License, or (at your option) any later version.
d8307d
-
d8307d
-   The GNU C Library is distributed in the hope that it will be useful,
d8307d
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
d8307d
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
d8307d
-   Lesser General Public License for more details.
d8307d
-
d8307d
-   You should have received a copy of the GNU Lesser General Public
d8307d
-   License along with the GNU C Library; if not, see
d8307d
-   <http://www.gnu.org/licenses/>.  */
d8307d
-
d8307d
-/* This wrapper-file is needed, because otherwise file
d8307d
-   sysdeps/s390/s390-[32|64]/memchr.S will be used.  */
d8307d
-#include <sysdeps/s390/multiarch/memchr.c>