bdc76f
commit 8c25dddd2e32bce47dfe01ca51c8aab535dbe23d
bdc76f
Author: Stefan Liebler <stli@linux.ibm.com>
bdc76f
Date:   Tue Dec 18 13:57:09 2018 +0100
bdc76f
bdc76f
    S390: Add z13 strstr ifunc variant.
bdc76f
    
bdc76f
    The new vector variant of strstr is using the common code
bdc76f
    implementation, but instead of calling the default
bdc76f
    str* / mem* functions, the vector variants are called.
bdc76f
    
bdc76f
    ChangeLog:
bdc76f
    
bdc76f
            * sysdeps/s390/Makefile (sysdep_routines): Add strstr variants.
bdc76f
            * sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
            (__libc_ifunc_impl_list): Add ifunc variants for strstr.
bdc76f
            * sysdeps/s390/ifunc-strstr.h: New file.
bdc76f
            * sysdeps/s390/strstr.c: Likewise.
bdc76f
            * sysdeps/s390/strstr-c.c: Likewise.
bdc76f
            * sysdeps/s390/strstr-vx.c: Likewise.
bdc76f
bdc76f
diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile
bdc76f
index 3a7cccdf8f147398..4441e7a5cf6fa167 100644
bdc76f
--- a/sysdeps/s390/Makefile
bdc76f
+++ b/sysdeps/s390/Makefile
bdc76f
@@ -34,5 +34,6 @@ ifeq ($(subdir),string)
bdc76f
 sysdep_routines += bzero memset memset-z900 \
bdc76f
 		   memcmp memcmp-z900 \
bdc76f
 		   mempcpy memcpy memcpy-z900 \
bdc76f
-		   memmove memmove-c
bdc76f
+		   memmove memmove-c \
bdc76f
+		   strstr strstr-vx strstr-c
bdc76f
 endif
bdc76f
diff --git a/sysdeps/s390/ifunc-strstr.h b/sysdeps/s390/ifunc-strstr.h
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..e6ccfd4e44a1a790
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/ifunc-strstr.h
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* strstr 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_STRSTR_IFUNC	1
bdc76f
+#else
bdc76f
+# define HAVE_STRSTR_IFUNC	0
bdc76f
+#endif
bdc76f
+
bdc76f
+#ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
+# define HAVE_STRSTR_IFUNC_AND_VX_SUPPORT HAVE_STRSTR_IFUNC
bdc76f
+#else
bdc76f
+# define HAVE_STRSTR_IFUNC_AND_VX_SUPPORT 0
bdc76f
+#endif
bdc76f
+
bdc76f
+#if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT
bdc76f
+# define STRSTR_DEFAULT		STRSTR_Z13
bdc76f
+# define HAVE_STRSTR_C		0
bdc76f
+# define HAVE_STRSTR_Z13	1
bdc76f
+#else
bdc76f
+# define STRSTR_DEFAULT		STRSTR_C
bdc76f
+# define HAVE_STRSTR_C		1
bdc76f
+# define HAVE_STRSTR_Z13	HAVE_STRSTR_IFUNC_AND_VX_SUPPORT
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRSTR_C
bdc76f
+# define STRSTR_C		__strstr_c
bdc76f
+#else
bdc76f
+# define STRSTR_C		NULL
bdc76f
+#endif
bdc76f
+
bdc76f
+#if HAVE_STRSTR_Z13
bdc76f
+# define STRSTR_Z13		__strstr_vx
bdc76f
+#else
bdc76f
+# define STRSTR_Z13		NULL
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/multiarch/ifunc-impl-list.c b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
index c05c63e00608dcd7..14727f8fef5431dd 100644
bdc76f
--- a/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
+++ b/sysdeps/s390/multiarch/ifunc-impl-list.c
bdc76f
@@ -24,6 +24,7 @@
bdc76f
 #include <ifunc-memset.h>
bdc76f
 #include <ifunc-memcmp.h>
bdc76f
 #include <ifunc-memcpy.h>
bdc76f
+#include <ifunc-strstr.h>
bdc76f
 
bdc76f
 /* Maximum number of IFUNC implementations.  */
bdc76f
 #define MAX_IFUNC	3
bdc76f
@@ -138,6 +139,18 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
bdc76f
 		)
bdc76f
 #endif /* HAVE_MEMMOVE_IFUNC  */
bdc76f
 
bdc76f
+#if HAVE_STRSTR_IFUNC
bdc76f
+    IFUNC_IMPL (i, name, strstr,
bdc76f
+# if HAVE_STRSTR_Z13
bdc76f
+		IFUNC_IMPL_ADD (array, i, strstr,
bdc76f
+				dl_hwcap & HWCAP_S390_VX, STRSTR_Z13)
bdc76f
+# endif
bdc76f
+# if HAVE_STRSTR_C
bdc76f
+		IFUNC_IMPL_ADD (array, i, strstr, 1, STRSTR_C)
bdc76f
+# endif
bdc76f
+		)
bdc76f
+#endif /* HAVE_STRSTR_IFUNC  */
bdc76f
+
bdc76f
 #ifdef HAVE_S390_VX_ASM_SUPPORT
bdc76f
 
bdc76f
 # define IFUNC_VX_IMPL(FUNC)						\
bdc76f
diff --git a/sysdeps/s390/strstr-c.c b/sysdeps/s390/strstr-c.c
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..53717bfb276fed3d
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/strstr-c.c
bdc76f
@@ -0,0 +1,32 @@
bdc76f
+/* Default strstr 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-strstr.h>
bdc76f
+
bdc76f
+#if HAVE_STRSTR_C
bdc76f
+# if HAVE_STRSTR_IFUNC
bdc76f
+#  define STRSTR STRSTR_C
bdc76f
+#  if defined SHARED && IS_IN (libc)
bdc76f
+#   undef libc_hidden_builtin_def
bdc76f
+#   define libc_hidden_builtin_def(name)		\
bdc76f
+  __hidden_ver1 (__strstr_c, __GI_strstr, __strstr_c);
bdc76f
+#  endif
bdc76f
+# endif
bdc76f
+
bdc76f
+# include <string/strstr.c>
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/strstr-vx.c b/sysdeps/s390/strstr-vx.c
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..effae9d5eb7d2fb1
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/strstr-vx.c
bdc76f
@@ -0,0 +1,52 @@
bdc76f
+/* Default strstr 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-strstr.h>
bdc76f
+
bdc76f
+#if HAVE_STRSTR_Z13
bdc76f
+# if HAVE_STRSTR_IFUNC
bdc76f
+#  define STRSTR STRSTR_Z13
bdc76f
+#  if defined SHARED && IS_IN (libc)
bdc76f
+#   undef libc_hidden_builtin_def
bdc76f
+#   if HAVE_STRSTR_C
bdc76f
+#    define libc_hidden_builtin_def(name)
bdc76f
+#   else
bdc76f
+#    define libc_hidden_builtin_def(name)		\
bdc76f
+  __hidden_ver1 (__strstr_vx, __GI_strstr, __strstr_vx);
bdc76f
+#   endif
bdc76f
+#  endif
bdc76f
+# endif
bdc76f
+
bdc76f
+# include <string.h>
bdc76f
+
bdc76f
+# ifdef USE_MULTIARCH
bdc76f
+extern __typeof (strchr) __strchr_vx attribute_hidden;
bdc76f
+#  define strchr __strchr_vx
bdc76f
+
bdc76f
+extern __typeof (strlen) __strlen_vx attribute_hidden;
bdc76f
+#  define strlen __strlen_vx
bdc76f
+
bdc76f
+extern __typeof (__strnlen) __strnlen_vx attribute_hidden;
bdc76f
+#  define __strnlen __strnlen_vx
bdc76f
+
bdc76f
+extern __typeof (memcmp) __memcmp_z196 attribute_hidden;
bdc76f
+#  define memcmp __memcmp_z196
bdc76f
+# endif
bdc76f
+
bdc76f
+# include <string/strstr.c>
bdc76f
+#endif
bdc76f
diff --git a/sysdeps/s390/strstr.c b/sysdeps/s390/strstr.c
bdc76f
new file mode 100644
bdc76f
index 0000000000000000..f8432349a7254cc6
bdc76f
--- /dev/null
bdc76f
+++ b/sysdeps/s390/strstr.c
bdc76f
@@ -0,0 +1,40 @@
bdc76f
+/* Multiple versions of strstr.
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-strstr.h>
bdc76f
+
bdc76f
+#if HAVE_STRSTR_IFUNC
bdc76f
+# define strstr __redirect_strstr
bdc76f
+# include <string.h>
bdc76f
+# include <ifunc-resolve.h>
bdc76f
+# undef strstr
bdc76f
+
bdc76f
+# if HAVE_STRSTR_C
bdc76f
+extern __typeof (__redirect_strstr) STRSTR_C attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+# if HAVE_STRSTR_Z13
bdc76f
+extern __typeof (__redirect_strstr) STRSTR_Z13 attribute_hidden;
bdc76f
+# endif
bdc76f
+
bdc76f
+s390_libc_ifunc_expr (__redirect_strstr, strstr,
bdc76f
+		      (HAVE_STRSTR_Z13 && (hwcap & HWCAP_S390_VX))
bdc76f
+		      ? STRSTR_Z13
bdc76f
+		      : STRSTR_DEFAULT
bdc76f
+		      )
bdc76f
+#endif