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