077c9d
commit d2c4c403feddd6f0b9dbf31ca7541b37f90ee30a
077c9d
Author: Stefan Liebler <stli@linux.ibm.com>
077c9d
Date:   Tue Dec 18 13:57:09 2018 +0100
077c9d
077c9d
    S390: Add z13 memmem ifunc variant.
077c9d
    
077c9d
    The new vector variant of memmem is using the common code
077c9d
    implementation, but instead of calling the default
077c9d
    mem* functions, the vector variants are called.
077c9d
    
077c9d
    ChangeLog:
077c9d
    
077c9d
            * sysdeps/s390/Makefile (sysdep_routines): Add memmem variants.
077c9d
            * sysdeps/s390/multiarch/ifunc-impl-list.c
077c9d
            (__libc_ifunc_impl_list): Add ifunc variants for memmem.
077c9d
            * sysdeps/s390/ifunc-memmem.h: New file.
077c9d
            * sysdeps/s390/memmem.c: Likewise.
077c9d
            * sysdeps/s390/memmem-c.c: Likewise.
077c9d
            * sysdeps/s390/memmem-vx.c: Likewise.
077c9d
077c9d
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
077c9d
index 4441e7a5cf6fa167..47d606d3d5d99274 100644
077c9d
--- a/sysdeps/s390/Makefile
077c9d
+++ b/sysdeps/s390/Makefile
077c9d
@@ -35,5 +35,6 @@ sysdep_routines += bzero memset memset-z900 \
077c9d
 		   memcmp memcmp-z900 \
077c9d
 		   mempcpy memcpy memcpy-z900 \
077c9d
 		   memmove memmove-c \
077c9d
-		   strstr strstr-vx strstr-c
077c9d
+		   strstr strstr-vx strstr-c \
077c9d
+		   memmem memmem-vx memmem-c
077c9d
 endif
077c9d
diff --git a/sysdeps/s390/ifunc-memmem.h b/sysdeps/s390/ifunc-memmem.h
077c9d
new file mode 100644
077c9d
index 0000000000000000..0f860d8d40080acf
077c9d
--- /dev/null
077c9d
+++ b/sysdeps/s390/ifunc-memmem.h
077c9d
@@ -0,0 +1,52 @@
077c9d
+/* memmem variant information on S/390 version.
077c9d
+   Copyright (C) 2018 Free Software Foundation, Inc.
077c9d
+   This file is part of the GNU C Library.
077c9d
+
077c9d
+   The GNU C Library is free software; you can redistribute it and/or
077c9d
+   modify it under the terms of the GNU Lesser General Public
077c9d
+   License as published by the Free Software Foundation; either
077c9d
+   version 2.1 of the License, or (at your option) any later version.
077c9d
+
077c9d
+   The GNU C Library is distributed in the hope that it will be useful,
077c9d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
077c9d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
077c9d
+   Lesser General Public License for more details.
077c9d
+
077c9d
+   You should have received a copy of the GNU Lesser General Public
077c9d
+   License along with the GNU C Library; if not, see
077c9d
+   <http://www.gnu.org/licenses/>.  */
077c9d
+
077c9d
+#if defined USE_MULTIARCH && IS_IN (libc)		\
077c9d
+  && ! defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
077c9d
+# define HAVE_MEMMEM_IFUNC	1
077c9d
+#else
077c9d
+# define HAVE_MEMMEM_IFUNC	0
077c9d
+#endif
077c9d
+
077c9d
+#ifdef HAVE_S390_VX_ASM_SUPPORT
077c9d
+# define HAVE_MEMMEM_IFUNC_AND_VX_SUPPORT HAVE_MEMMEM_IFUNC
077c9d
+#else
077c9d
+# define HAVE_MEMMEM_IFUNC_AND_VX_SUPPORT 0
077c9d
+#endif
077c9d
+
077c9d
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
077c9d
+# define MEMMEM_DEFAULT		MEMMEM_Z13
077c9d
+# define HAVE_MEMMEM_C		0
077c9d
+# define HAVE_MEMMEM_Z13	1
077c9d
+#else
077c9d
+# define MEMMEM_DEFAULT		MEMMEM_C
077c9d
+# define HAVE_MEMMEM_C		1
077c9d
+# define HAVE_MEMMEM_Z13	HAVE_MEMMEM_IFUNC_AND_VX_SUPPORT
077c9d
+#endif
077c9d
+
077c9d
+#if HAVE_MEMMEM_C
077c9d
+# define MEMMEM_C		__memmem_c
077c9d
+#else
077c9d
+# define MEMMEM_C		NULL
077c9d
+#endif
077c9d
+
077c9d
+#if HAVE_MEMMEM_Z13
077c9d
+# define MEMMEM_Z13		__memmem_vx
077c9d
+#else
077c9d
+# define MEMMEM_Z13		NULL
077c9d
+#endif
077c9d
diff --git a/sysdeps/s390/memmem-c.c b/sysdeps/s390/memmem-c.c
077c9d
new file mode 100644
077c9d
index 0000000000000000..1d8ffefcb840b8d2
077c9d
--- /dev/null
077c9d
+++ b/sysdeps/s390/memmem-c.c
077c9d
@@ -0,0 +1,47 @@
077c9d
+/* Default memmem implementation for S/390.
077c9d
+   Copyright (C) 2018 Free Software Foundation, Inc.
077c9d
+   This file is part of the GNU C Library.
077c9d
+
077c9d
+   The GNU C Library is free software; you can redistribute it and/or
077c9d
+   modify it under the terms of the GNU Lesser General Public
077c9d
+   License as published by the Free Software Foundation; either
077c9d
+   version 2.1 of the License, or (at your option) any later version.
077c9d
+
077c9d
+   The GNU C Library is distributed in the hope that it will be useful,
077c9d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
077c9d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
077c9d
+   Lesser General Public License for more details.
077c9d
+
077c9d
+   You should have received a copy of the GNU Lesser General Public
077c9d
+   License along with the GNU C Library; if not, see
077c9d
+   <http://www.gnu.org/licenses/>.  */
077c9d
+
077c9d
+#include <ifunc-memmem.h>
077c9d
+
077c9d
+#if HAVE_MEMMEM_C
077c9d
+# if HAVE_MEMMEM_IFUNC
077c9d
+#  include <string.h>
077c9d
+
077c9d
+#  ifndef _LIBC
077c9d
+#   define memmem MEMMEM_C
077c9d
+#  else
077c9d
+#   define __memmem MEMMEM_C
077c9d
+#  endif
077c9d
+
077c9d
+#  if defined SHARED && IS_IN (libc)
077c9d
+#   undef libc_hidden_def
077c9d
+#   define libc_hidden_def(name)				\
077c9d
+  strong_alias (__memmem_c, __memmem_c_1);			\
077c9d
+  __hidden_ver1 (__memmem_c, __GI___memmem, __memmem_c);
077c9d
+
077c9d
+#   undef libc_hidden_weak
077c9d
+#   define libc_hidden_weak(name)					\
077c9d
+  __hidden_ver1 (__memmem_c_1, __GI_memmem, __memmem_c_1) __attribute__((weak));
077c9d
+#  endif
077c9d
+
077c9d
+#  undef weak_alias
077c9d
+#  define weak_alias(a, b)
077c9d
+# endif
077c9d
+
077c9d
+# include <string/memmem.c>
077c9d
+#endif
077c9d
diff --git a/sysdeps/s390/memmem-vx.c b/sysdeps/s390/memmem-vx.c
077c9d
new file mode 100644
077c9d
index 0000000000000000..af6e200e4e0af1a5
077c9d
--- /dev/null
077c9d
+++ b/sysdeps/s390/memmem-vx.c
077c9d
@@ -0,0 +1,61 @@
077c9d
+/* Default memmem implementation with vector string functions for S/390.
077c9d
+   Copyright (C) 2018 Free Software Foundation, Inc.
077c9d
+   This file is part of the GNU C Library.
077c9d
+
077c9d
+   The GNU C Library is free software; you can redistribute it and/or
077c9d
+   modify it under the terms of the GNU Lesser General Public
077c9d
+   License as published by the Free Software Foundation; either
077c9d
+   version 2.1 of the License, or (at your option) any later version.
077c9d
+
077c9d
+   The GNU C Library is distributed in the hope that it will be useful,
077c9d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
077c9d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
077c9d
+   Lesser General Public License for more details.
077c9d
+
077c9d
+   You should have received a copy of the GNU Lesser General Public
077c9d
+   License along with the GNU C Library; if not, see
077c9d
+   <http://www.gnu.org/licenses/>.  */
077c9d
+
077c9d
+#include <ifunc-memmem.h>
077c9d
+
077c9d
+#if HAVE_MEMMEM_Z13
077c9d
+# include <string.h>
077c9d
+# if HAVE_MEMMEM_IFUNC
077c9d
+
077c9d
+#  ifndef _LIBC
077c9d
+#   define memmem MEMMEM_Z13
077c9d
+#  else
077c9d
+#   define __memmem MEMMEM_Z13
077c9d
+#  endif
077c9d
+
077c9d
+#  if defined SHARED && IS_IN (libc)
077c9d
+#   undef libc_hidden_def
077c9d
+#   undef libc_hidden_weak
077c9d
+
077c9d
+#   if HAVE_MEMMEM_C
077c9d
+#    define libc_hidden_def(name)
077c9d
+#    define libc_hidden_weak(name)
077c9d
+#   else
077c9d
+#    define libc_hidden_def(name)				\
077c9d
+  strong_alias (__memmem_vx, __memmem_vx_1);			\
077c9d
+  __hidden_ver1 (__memmem_vx, __GI___memmem, __memmem_vx);
077c9d
+
077c9d
+#    define libc_hidden_weak(name)					\
077c9d
+  __hidden_ver1 (__memmem_vx_1, __GI_memmem, __memmem_vx_1) __attribute__((weak));
077c9d
+#   endif
077c9d
+#  endif
077c9d
+
077c9d
+#  undef weak_alias
077c9d
+#  define weak_alias(a, b)
077c9d
+# endif
077c9d
+
077c9d
+# ifdef USE_MULTIARCH
077c9d
+extern __typeof (memchr) __memchr_vx attribute_hidden;
077c9d
+# define memchr __memchr_vx
077c9d
+
077c9d
+extern __typeof (memcmp) __memcmp_z196 attribute_hidden;
077c9d
+# define memcmp __memcmp_z196
077c9d
+# endif
077c9d
+
077c9d
+# include <string/memmem.c>
077c9d
+#endif
077c9d
diff --git a/sysdeps/s390/memmem.c b/sysdeps/s390/memmem.c
077c9d
new file mode 100644
077c9d
index 0000000000000000..8c50b3f403eb8d1f
077c9d
--- /dev/null
077c9d
+++ b/sysdeps/s390/memmem.c
077c9d
@@ -0,0 +1,43 @@
077c9d
+/* Multiple versions of memmem.
077c9d
+   Copyright (C) 2018 Free Software Foundation, Inc.
077c9d
+   This file is part of the GNU C Library.
077c9d
+
077c9d
+   The GNU C Library is free software; you can redistribute it and/or
077c9d
+   modify it under the terms of the GNU Lesser General Public
077c9d
+   License as published by the Free Software Foundation; either
077c9d
+   version 2.1 of the License, or (at your option) any later version.
077c9d
+
077c9d
+   The GNU C Library is distributed in the hope that it will be useful,
077c9d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
077c9d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
077c9d
+   Lesser General Public License for more details.
077c9d
+
077c9d
+   You should have received a copy of the GNU Lesser General Public
077c9d
+   License along with the GNU C Library; if not, see
077c9d
+   <http://www.gnu.org/licenses/>.  */
077c9d
+
077c9d
+#include <ifunc-memmem.h>
077c9d
+
077c9d
+#if HAVE_MEMMEM_IFUNC
077c9d
+# define memmem __redirect_memmem
077c9d
+# define __memmem __redirect___memmem
077c9d
+# include <string.h>
077c9d
+# include <ifunc-resolve.h>
077c9d
+# undef memmem
077c9d
+# undef __memmem
077c9d
+
077c9d
+# if HAVE_MEMMEM_C
077c9d
+extern __typeof (__redirect_memmem) MEMMEM_C attribute_hidden;
077c9d
+# endif
077c9d
+
077c9d
+# if HAVE_MEMMEM_Z13
077c9d
+extern __typeof (__redirect_memmem) MEMMEM_Z13 attribute_hidden;
077c9d
+# endif
077c9d
+
077c9d
+s390_libc_ifunc_expr (__redirect_memmem, __memmem,
077c9d
+		      (HAVE_MEMMEM_Z13 && (hwcap & HWCAP_S390_VX))
077c9d
+		      ? MEMMEM_Z13
077c9d
+		      : MEMMEM_DEFAULT
077c9d
+		      )
077c9d
+weak_alias (__memmem, memmem)
077c9d
+#endif
077c9d
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
077c9d
index 14727f8fef5431dd..da8696d917abf51c 100644
077c9d
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
077c9d
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
077c9d
@@ -25,6 +25,7 @@
077c9d
 #include <ifunc-memcmp.h>
077c9d
 #include <ifunc-memcpy.h>
077c9d
 #include <ifunc-strstr.h>
077c9d
+#include <ifunc-memmem.h>
077c9d
 
077c9d
 /* Maximum number of IFUNC implementations.  */
077c9d
 #define MAX_IFUNC	3
077c9d
@@ -151,6 +152,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
077c9d
 		)
077c9d
 #endif /* HAVE_STRSTR_IFUNC  */
077c9d
 
077c9d
+#if HAVE_MEMMEM_IFUNC
077c9d
+    IFUNC_IMPL (i, name, memmem,
077c9d
+# if HAVE_MEMMEM_Z13
077c9d
+		IFUNC_IMPL_ADD (array, i, memmem,
077c9d
+				dl_hwcap & HWCAP_S390_VX, MEMMEM_Z13)
077c9d
+# endif
077c9d
+# if HAVE_MEMMEM_C
077c9d
+		IFUNC_IMPL_ADD (array, i, memmem, 1, MEMMEM_C)
077c9d
+# endif
077c9d
+		)
077c9d
+#endif /* HAVE_MEMMEM_IFUNC  */
077c9d
+
077c9d
 #ifdef HAVE_S390_VX_ASM_SUPPORT
077c9d
 
077c9d
 # define IFUNC_VX_IMPL(FUNC)						\