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