d8307d
commit d2c4c403feddd6f0b9dbf31ca7541b37f90ee30a
d8307d
Author: Stefan Liebler <stli@linux.ibm.com>
d8307d
Date:   Tue Dec 18 13:57:09 2018 +0100
d8307d
d8307d
    S390: Add z13 memmem ifunc variant.
d8307d
    
d8307d
    The new vector variant of memmem is using the common code
d8307d
    implementation, but instead of calling the default
d8307d
    mem* functions, the vector variants are called.
d8307d
    
d8307d
    ChangeLog:
d8307d
    
d8307d
            * sysdeps/s390/Makefile (sysdep_routines): Add memmem variants.
d8307d
            * sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
            (__libc_ifunc_impl_list): Add ifunc variants for memmem.
d8307d
            * sysdeps/s390/ifunc-memmem.h: New file.
d8307d
            * sysdeps/s390/memmem.c: Likewise.
d8307d
            * sysdeps/s390/memmem-c.c: Likewise.
d8307d
            * sysdeps/s390/memmem-vx.c: Likewise.
d8307d
d8307d
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
d8307d
index 4441e7a5cf6fa167..47d606d3d5d99274 100644
d8307d
--- a/sysdeps/s390/Makefile
d8307d
+++ b/sysdeps/s390/Makefile
d8307d
@@ -35,5 +35,6 @@ sysdep_routines += bzero memset memset-z900 \
d8307d
 		   memcmp memcmp-z900 \
d8307d
 		   mempcpy memcpy memcpy-z900 \
d8307d
 		   memmove memmove-c \
d8307d
-		   strstr strstr-vx strstr-c
d8307d
+		   strstr strstr-vx strstr-c \
d8307d
+		   memmem memmem-vx memmem-c
d8307d
 endif
d8307d
diff --git a/sysdeps/s390/ifunc-memmem.h b/sysdeps/s390/ifunc-memmem.h
d8307d
new file mode 100644
d8307d
index 0000000000000000..0f860d8d40080acf
d8307d
--- /dev/null
d8307d
+++ b/sysdeps/s390/ifunc-memmem.h
d8307d
@@ -0,0 +1,52 @@
d8307d
+/* memmem 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_MEMMEM_IFUNC	1
d8307d
+#else
d8307d
+# define HAVE_MEMMEM_IFUNC	0
d8307d
+#endif
d8307d
+
d8307d
+#ifdef HAVE_S390_VX_ASM_SUPPORT
d8307d
+# define HAVE_MEMMEM_IFUNC_AND_VX_SUPPORT HAVE_MEMMEM_IFUNC
d8307d
+#else
d8307d
+# define HAVE_MEMMEM_IFUNC_AND_VX_SUPPORT 0
d8307d
+#endif
d8307d
+
d8307d
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
d8307d
+# define MEMMEM_DEFAULT		MEMMEM_Z13
d8307d
+# define HAVE_MEMMEM_C		0
d8307d
+# define HAVE_MEMMEM_Z13	1
d8307d
+#else
d8307d
+# define MEMMEM_DEFAULT		MEMMEM_C
d8307d
+# define HAVE_MEMMEM_C		1
d8307d
+# define HAVE_MEMMEM_Z13	HAVE_MEMMEM_IFUNC_AND_VX_SUPPORT
d8307d
+#endif
d8307d
+
d8307d
+#if HAVE_MEMMEM_C
d8307d
+# define MEMMEM_C		__memmem_c
d8307d
+#else
d8307d
+# define MEMMEM_C		NULL
d8307d
+#endif
d8307d
+
d8307d
+#if HAVE_MEMMEM_Z13
d8307d
+# define MEMMEM_Z13		__memmem_vx
d8307d
+#else
d8307d
+# define MEMMEM_Z13		NULL
d8307d
+#endif
d8307d
diff --git a/sysdeps/s390/memmem-c.c b/sysdeps/s390/memmem-c.c
d8307d
new file mode 100644
d8307d
index 0000000000000000..1d8ffefcb840b8d2
d8307d
--- /dev/null
d8307d
+++ b/sysdeps/s390/memmem-c.c
d8307d
@@ -0,0 +1,47 @@
d8307d
+/* Default memmem implementation for S/390.
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
+#include <ifunc-memmem.h>
d8307d
+
d8307d
+#if HAVE_MEMMEM_C
d8307d
+# if HAVE_MEMMEM_IFUNC
d8307d
+#  include <string.h>
d8307d
+
d8307d
+#  ifndef _LIBC
d8307d
+#   define memmem MEMMEM_C
d8307d
+#  else
d8307d
+#   define __memmem MEMMEM_C
d8307d
+#  endif
d8307d
+
d8307d
+#  if defined SHARED && IS_IN (libc)
d8307d
+#   undef libc_hidden_def
d8307d
+#   define libc_hidden_def(name)				\
d8307d
+  strong_alias (__memmem_c, __memmem_c_1);			\
d8307d
+  __hidden_ver1 (__memmem_c, __GI___memmem, __memmem_c);
d8307d
+
d8307d
+#   undef libc_hidden_weak
d8307d
+#   define libc_hidden_weak(name)					\
d8307d
+  __hidden_ver1 (__memmem_c_1, __GI_memmem, __memmem_c_1) __attribute__((weak));
d8307d
+#  endif
d8307d
+
d8307d
+#  undef weak_alias
d8307d
+#  define weak_alias(a, b)
d8307d
+# endif
d8307d
+
d8307d
+# include <string/memmem.c>
d8307d
+#endif
d8307d
diff --git a/sysdeps/s390/memmem-vx.c b/sysdeps/s390/memmem-vx.c
d8307d
new file mode 100644
d8307d
index 0000000000000000..af6e200e4e0af1a5
d8307d
--- /dev/null
d8307d
+++ b/sysdeps/s390/memmem-vx.c
d8307d
@@ -0,0 +1,61 @@
d8307d
+/* Default memmem implementation with vector string functions for S/390.
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
+#include <ifunc-memmem.h>
d8307d
+
d8307d
+#if HAVE_MEMMEM_Z13
d8307d
+# include <string.h>
d8307d
+# if HAVE_MEMMEM_IFUNC
d8307d
+
d8307d
+#  ifndef _LIBC
d8307d
+#   define memmem MEMMEM_Z13
d8307d
+#  else
d8307d
+#   define __memmem MEMMEM_Z13
d8307d
+#  endif
d8307d
+
d8307d
+#  if defined SHARED && IS_IN (libc)
d8307d
+#   undef libc_hidden_def
d8307d
+#   undef libc_hidden_weak
d8307d
+
d8307d
+#   if HAVE_MEMMEM_C
d8307d
+#    define libc_hidden_def(name)
d8307d
+#    define libc_hidden_weak(name)
d8307d
+#   else
d8307d
+#    define libc_hidden_def(name)				\
d8307d
+  strong_alias (__memmem_vx, __memmem_vx_1);			\
d8307d
+  __hidden_ver1 (__memmem_vx, __GI___memmem, __memmem_vx);
d8307d
+
d8307d
+#    define libc_hidden_weak(name)					\
d8307d
+  __hidden_ver1 (__memmem_vx_1, __GI_memmem, __memmem_vx_1) __attribute__((weak));
d8307d
+#   endif
d8307d
+#  endif
d8307d
+
d8307d
+#  undef weak_alias
d8307d
+#  define weak_alias(a, b)
d8307d
+# endif
d8307d
+
d8307d
+# ifdef USE_MULTIARCH
d8307d
+extern __typeof (memchr) __memchr_vx attribute_hidden;
d8307d
+# define memchr __memchr_vx
d8307d
+
d8307d
+extern __typeof (memcmp) __memcmp_z196 attribute_hidden;
d8307d
+# define memcmp __memcmp_z196
d8307d
+# endif
d8307d
+
d8307d
+# include <string/memmem.c>
d8307d
+#endif
d8307d
diff --git a/sysdeps/s390/memmem.c b/sysdeps/s390/memmem.c
d8307d
new file mode 100644
d8307d
index 0000000000000000..8c50b3f403eb8d1f
d8307d
--- /dev/null
d8307d
+++ b/sysdeps/s390/memmem.c
d8307d
@@ -0,0 +1,43 @@
d8307d
+/* Multiple versions of memmem.
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
+#include <ifunc-memmem.h>
d8307d
+
d8307d
+#if HAVE_MEMMEM_IFUNC
d8307d
+# define memmem __redirect_memmem
d8307d
+# define __memmem __redirect___memmem
d8307d
+# include <string.h>
d8307d
+# include <ifunc-resolve.h>
d8307d
+# undef memmem
d8307d
+# undef __memmem
d8307d
+
d8307d
+# if HAVE_MEMMEM_C
d8307d
+extern __typeof (__redirect_memmem) MEMMEM_C attribute_hidden;
d8307d
+# endif
d8307d
+
d8307d
+# if HAVE_MEMMEM_Z13
d8307d
+extern __typeof (__redirect_memmem) MEMMEM_Z13 attribute_hidden;
d8307d
+# endif
d8307d
+
d8307d
+s390_libc_ifunc_expr (__redirect_memmem, __memmem,
d8307d
+		      (HAVE_MEMMEM_Z13 && (hwcap & HWCAP_S390_VX))
d8307d
+		      ? MEMMEM_Z13
d8307d
+		      : MEMMEM_DEFAULT
d8307d
+		      )
d8307d
+weak_alias (__memmem, memmem)
d8307d
+#endif
d8307d
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
index 14727f8fef5431dd..da8696d917abf51c 100644
d8307d
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
d8307d
@@ -25,6 +25,7 @@
d8307d
 #include <ifunc-memcmp.h>
d8307d
 #include <ifunc-memcpy.h>
d8307d
 #include <ifunc-strstr.h>
d8307d
+#include <ifunc-memmem.h>
d8307d
 
d8307d
 /* Maximum number of IFUNC implementations.  */
d8307d
 #define MAX_IFUNC	3
d8307d
@@ -151,6 +152,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
d8307d
 		)
d8307d
 #endif /* HAVE_STRSTR_IFUNC  */
d8307d
 
d8307d
+#if HAVE_MEMMEM_IFUNC
d8307d
+    IFUNC_IMPL (i, name, memmem,
d8307d
+# if HAVE_MEMMEM_Z13
d8307d
+		IFUNC_IMPL_ADD (array, i, memmem,
d8307d
+				dl_hwcap & HWCAP_S390_VX, MEMMEM_Z13)
d8307d
+# endif
d8307d
+# if HAVE_MEMMEM_C
d8307d
+		IFUNC_IMPL_ADD (array, i, memmem, 1, MEMMEM_C)
d8307d
+# endif
d8307d
+		)
d8307d
+#endif /* HAVE_MEMMEM_IFUNC  */
d8307d
+
d8307d
 #ifdef HAVE_S390_VX_ASM_SUPPORT
d8307d
 
d8307d
 # define IFUNC_VX_IMPL(FUNC)						\