x86: Add support to build st{p|r}{n}{cpy|cat} with explicit ISA level
authorNoah Goldstein <goldstein.w.n@gmail.com>
Wed, 13 Jul 2022 23:33:01 +0000 (16:33 -0700)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Sat, 16 Jul 2022 10:07:59 +0000 (03:07 -0700)
1. Add default ISA level selection in non-multiarch/rtld
   implementations.

2. Add ISA level build guards to different implementations.
    - I.e strcpy-avx2.S which is ISA level 3 will only build if
      compiled ISA level <= 3. Otherwise there is no reason to
      include it as we will always use one of the ISA level 4
      implementations (strcpy-evex.S).

3. Refactor the ifunc selector and ifunc implementation list to use
   the ISA level aware wrapper macros that allow functions below the
   compiled ISA level (with a guranteed replacement) to be skipped.

Tested with and without multiarch on x86_64 for ISA levels:
{generic, x86-64-v2, x86-64-v3, x86-64-v4}

And m32 with and without multiarch.

30 files changed:
sysdeps/x86_64/multiarch/ifunc-impl-list.c
sysdeps/x86_64/multiarch/ifunc-strcpy.h
sysdeps/x86_64/multiarch/ifunc-strncpy.h
sysdeps/x86_64/multiarch/stpcpy-avx2.S
sysdeps/x86_64/multiarch/stpcpy-evex.S
sysdeps/x86_64/multiarch/stpcpy-sse2-unaligned.S
sysdeps/x86_64/multiarch/stpcpy-sse2.S
sysdeps/x86_64/multiarch/stpncpy-avx2.S
sysdeps/x86_64/multiarch/stpncpy-evex.S
sysdeps/x86_64/multiarch/stpncpy-sse2-unaligned.S
sysdeps/x86_64/multiarch/strcat-avx2.S
sysdeps/x86_64/multiarch/strcat-evex.S
sysdeps/x86_64/multiarch/strcat-sse2-unaligned.S
sysdeps/x86_64/multiarch/strcat-sse2.S
sysdeps/x86_64/multiarch/strcpy-avx2.S
sysdeps/x86_64/multiarch/strcpy-evex.S
sysdeps/x86_64/multiarch/strcpy-sse2-unaligned.S
sysdeps/x86_64/multiarch/strcpy-sse2.S
sysdeps/x86_64/multiarch/strncat-avx2.S
sysdeps/x86_64/multiarch/strncat-evex.S
sysdeps/x86_64/multiarch/strncat-sse2-unaligned.S
sysdeps/x86_64/multiarch/strncpy-avx2.S
sysdeps/x86_64/multiarch/strncpy-evex.S
sysdeps/x86_64/multiarch/strncpy-sse2-unaligned.S
sysdeps/x86_64/stpcpy.S
sysdeps/x86_64/stpncpy.S [new file with mode: 0644]
sysdeps/x86_64/strcat.S
sysdeps/x86_64/strcpy.S
sysdeps/x86_64/strncat.S [new file with mode: 0644]
sysdeps/x86_64/strncpy.S [new file with mode: 0644]

index 9318e98..a71444e 100644 (file)
@@ -403,33 +403,46 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 
   /* Support sysdeps/x86_64/multiarch/stpncpy.c.  */
   IFUNC_IMPL (i, name, stpncpy,
-             IFUNC_IMPL_ADD (array, i, stpncpy, CPU_FEATURE_USABLE (AVX2),
-                             __stpncpy_avx2)
-             IFUNC_IMPL_ADD (array, i, stpncpy,
-                             (CPU_FEATURE_USABLE (AVX2)
-                              && CPU_FEATURE_USABLE (RTM)),
-                             __stpncpy_avx2_rtm)
-             IFUNC_IMPL_ADD (array, i, stpncpy,
-                             (CPU_FEATURE_USABLE (AVX512VL)
-                              && CPU_FEATURE_USABLE (AVX512BW)),
-                             __stpncpy_evex)
-             IFUNC_IMPL_ADD (array, i, stpncpy, 1,
-                             __stpncpy_sse2_unaligned))
+             X86_IFUNC_IMPL_ADD_V4 (array, i, stpncpy,
+                                    (CPU_FEATURE_USABLE (AVX512VL)
+                                     && CPU_FEATURE_USABLE (AVX512BW)),
+                                    __stpncpy_evex)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, stpncpy,
+                                    CPU_FEATURE_USABLE (AVX2),
+                                    __stpncpy_avx2)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, stpncpy,
+                                    (CPU_FEATURE_USABLE (AVX2)
+                                     && CPU_FEATURE_USABLE (RTM)),
+                                    __stpncpy_avx2_rtm)
+             /* ISA V2 wrapper for sse2_unaligned implementation because
+                the sse2_unaligned implementation is also used at ISA
+                level 2.  */
+             X86_IFUNC_IMPL_ADD_V2 (array, i, stpncpy,
+                                    1,
+                                    __stpncpy_sse2_unaligned))
 
   /* Support sysdeps/x86_64/multiarch/stpcpy.c.  */
   IFUNC_IMPL (i, name, stpcpy,
-             IFUNC_IMPL_ADD (array, i, stpcpy, CPU_FEATURE_USABLE (AVX2),
-                             __stpcpy_avx2)
-             IFUNC_IMPL_ADD (array, i, stpcpy,
-                             (CPU_FEATURE_USABLE (AVX2)
-                              && CPU_FEATURE_USABLE (RTM)),
-                             __stpcpy_avx2_rtm)
-             IFUNC_IMPL_ADD (array, i, stpcpy,
-                             (CPU_FEATURE_USABLE (AVX512VL)
-                              && CPU_FEATURE_USABLE (AVX512BW)),
-                             __stpcpy_evex)
-             IFUNC_IMPL_ADD (array, i, stpcpy, 1, __stpcpy_sse2_unaligned)
-             IFUNC_IMPL_ADD (array, i, stpcpy, 1, __stpcpy_sse2))
+             X86_IFUNC_IMPL_ADD_V4 (array, i, stpcpy,
+                                    (CPU_FEATURE_USABLE (AVX512VL)
+                                     && CPU_FEATURE_USABLE (AVX512BW)),
+                                    __stpcpy_evex)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, stpcpy,
+                                    CPU_FEATURE_USABLE (AVX2),
+                                    __stpcpy_avx2)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, stpcpy,
+                                    (CPU_FEATURE_USABLE (AVX2)
+                                     && CPU_FEATURE_USABLE (RTM)),
+                                    __stpcpy_avx2_rtm)
+             /* ISA V2 wrapper for sse2_unaligned implementation because
+                the sse2_unaligned implementation is also used at ISA
+                level 2.  */
+             X86_IFUNC_IMPL_ADD_V2 (array, i, stpcpy,
+                                    1,
+                                    __stpcpy_sse2_unaligned)
+             X86_IFUNC_IMPL_ADD_V1 (array, i, stpcpy,
+                                    1,
+                                    __stpcpy_sse2))
 
   /* Support sysdeps/x86_64/multiarch/strcasecmp_l.c.  */
   IFUNC_IMPL (i, name, strcasecmp,
@@ -477,18 +490,26 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 
   /* Support sysdeps/x86_64/multiarch/strcat.c.  */
   IFUNC_IMPL (i, name, strcat,
-             IFUNC_IMPL_ADD (array, i, strcat, CPU_FEATURE_USABLE (AVX2),
-                             __strcat_avx2)
-             IFUNC_IMPL_ADD (array, i, strcat,
-                             (CPU_FEATURE_USABLE (AVX2)
-                              && CPU_FEATURE_USABLE (RTM)),
-                             __strcat_avx2_rtm)
-             IFUNC_IMPL_ADD (array, i, strcat,
-                             (CPU_FEATURE_USABLE (AVX512VL)
-                              && CPU_FEATURE_USABLE (AVX512BW)),
-                             __strcat_evex)
-             IFUNC_IMPL_ADD (array, i, strcat, 1, __strcat_sse2_unaligned)
-             IFUNC_IMPL_ADD (array, i, strcat, 1, __strcat_sse2))
+             X86_IFUNC_IMPL_ADD_V4 (array, i, strcat,
+                                    (CPU_FEATURE_USABLE (AVX512VL)
+                                     && CPU_FEATURE_USABLE (AVX512BW)),
+                                    __strcat_evex)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, strcat,
+                                    CPU_FEATURE_USABLE (AVX2),
+                                    __strcat_avx2)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, strcat,
+                                    (CPU_FEATURE_USABLE (AVX2)
+                                     && CPU_FEATURE_USABLE (RTM)),
+                                    __strcat_avx2_rtm)
+             /* ISA V2 wrapper for sse2_unaligned implementation because
+                the sse2_unaligned implementation is also used at ISA
+                level 2.  */
+             X86_IFUNC_IMPL_ADD_V2 (array, i, strcat,
+                                    1,
+                                    __strcat_sse2_unaligned)
+             X86_IFUNC_IMPL_ADD_V1 (array, i, strcat,
+                                    1,
+                                    __strcat_sse2))
 
   /* Support sysdeps/x86_64/multiarch/strchr.c.  */
   IFUNC_IMPL (i, name, strchr,
@@ -584,18 +605,26 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 
   /* Support sysdeps/x86_64/multiarch/strcpy.c.  */
   IFUNC_IMPL (i, name, strcpy,
-             IFUNC_IMPL_ADD (array, i, strcpy, CPU_FEATURE_USABLE (AVX2),
-                             __strcpy_avx2)
-             IFUNC_IMPL_ADD (array, i, strcpy,
-                             (CPU_FEATURE_USABLE (AVX2)
-                              && CPU_FEATURE_USABLE (RTM)),
-                             __strcpy_avx2_rtm)
-             IFUNC_IMPL_ADD (array, i, strcpy,
-                             (CPU_FEATURE_USABLE (AVX512VL)
-                              && CPU_FEATURE_USABLE (AVX512BW)),
-                             __strcpy_evex)
-             IFUNC_IMPL_ADD (array, i, strcpy, 1, __strcpy_sse2_unaligned)
-             IFUNC_IMPL_ADD (array, i, strcpy, 1, __strcpy_sse2))
+             X86_IFUNC_IMPL_ADD_V4 (array, i, strcpy,
+                                    (CPU_FEATURE_USABLE (AVX512VL)
+                                     && CPU_FEATURE_USABLE (AVX512BW)),
+                                    __strcpy_evex)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, strcpy,
+                                    CPU_FEATURE_USABLE (AVX2),
+                                    __strcpy_avx2)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, strcpy,
+                                    (CPU_FEATURE_USABLE (AVX2)
+                                     && CPU_FEATURE_USABLE (RTM)),
+                                    __strcpy_avx2_rtm)
+             /* ISA V2 wrapper for sse2_unaligned implementation because
+                the sse2_unaligned implementation is also used at ISA
+                level 2.  */
+             X86_IFUNC_IMPL_ADD_V2 (array, i, strcpy,
+                                    1,
+                                    __strcpy_sse2_unaligned)
+             X86_IFUNC_IMPL_ADD_V1 (array, i, strcpy,
+                                    1,
+                                    __strcpy_sse2))
 
   /* Support sysdeps/x86_64/multiarch/strcspn.c.  */
   IFUNC_IMPL (i, name, strcspn,
@@ -651,33 +680,43 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 
   /* Support sysdeps/x86_64/multiarch/strncat.c.  */
   IFUNC_IMPL (i, name, strncat,
-             IFUNC_IMPL_ADD (array, i, strncat, CPU_FEATURE_USABLE (AVX2),
-                             __strncat_avx2)
-             IFUNC_IMPL_ADD (array, i, strncat,
-                             (CPU_FEATURE_USABLE (AVX2)
-                              && CPU_FEATURE_USABLE (RTM)),
-                             __strncat_avx2_rtm)
-             IFUNC_IMPL_ADD (array, i, strncat,
-                             (CPU_FEATURE_USABLE (AVX512VL)
-                              && CPU_FEATURE_USABLE (AVX512BW)),
-                             __strncat_evex)
-             IFUNC_IMPL_ADD (array, i, strncat, 1,
-                             __strncat_sse2_unaligned))
+             X86_IFUNC_IMPL_ADD_V4 (array, i, strncat,
+                                    (CPU_FEATURE_USABLE (AVX512VL)
+                                     && CPU_FEATURE_USABLE (AVX512BW)),
+                                    __strncat_evex)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, strncat,
+                                    CPU_FEATURE_USABLE (AVX2),
+                                    __strncat_avx2)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, strncat,
+                                    (CPU_FEATURE_USABLE (AVX2)
+                                     && CPU_FEATURE_USABLE (RTM)),
+                                    __strncat_avx2_rtm)
+             /* ISA V2 wrapper for sse2_unaligned implementation because
+                the sse2_unaligned implementation is also used at ISA
+                level 2.  */
+             X86_IFUNC_IMPL_ADD_V2 (array, i, strncat,
+                                    1,
+                                    __strncat_sse2_unaligned))
 
   /* Support sysdeps/x86_64/multiarch/strncpy.c.  */
   IFUNC_IMPL (i, name, strncpy,
-             IFUNC_IMPL_ADD (array, i, strncpy, CPU_FEATURE_USABLE (AVX2),
-                             __strncpy_avx2)
-             IFUNC_IMPL_ADD (array, i, strncpy,
-                             (CPU_FEATURE_USABLE (AVX2)
-                              && CPU_FEATURE_USABLE (RTM)),
-                             __strncpy_avx2_rtm)
-             IFUNC_IMPL_ADD (array, i, strncpy,
-                             (CPU_FEATURE_USABLE (AVX512VL)
-                              && CPU_FEATURE_USABLE (AVX512BW)),
-                             __strncpy_evex)
-             IFUNC_IMPL_ADD (array, i, strncpy, 1,
-                             __strncpy_sse2_unaligned))
+             X86_IFUNC_IMPL_ADD_V4 (array, i, strncpy,
+                                    (CPU_FEATURE_USABLE (AVX512VL)
+                                     && CPU_FEATURE_USABLE (AVX512BW)),
+                                    __strncpy_evex)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, strncpy,
+                                    CPU_FEATURE_USABLE (AVX2),
+                                    __strncpy_avx2)
+             X86_IFUNC_IMPL_ADD_V3 (array, i, strncpy,
+                                    (CPU_FEATURE_USABLE (AVX2)
+                                     && CPU_FEATURE_USABLE (RTM)),
+                                    __strncpy_avx2_rtm)
+             /* ISA V2 wrapper for sse2_unaligned implementation because
+                the sse2_unaligned implementation is also used at ISA
+                level 2.  */
+             X86_IFUNC_IMPL_ADD_V2 (array, i, strncpy,
+                                    1,
+                                    __strncpy_sse2_unaligned))
 
   /* Support sysdeps/x86_64/multiarch/strpbrk.c.  */
   IFUNC_IMPL (i, name, strpbrk,
index a15afa4..e083f71 100644 (file)
 
 #include <init-arch.h>
 
-extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden;
-extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2_unaligned)
-  attribute_hidden;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (evex) attribute_hidden;
+
 extern __typeof (REDIRECT_NAME) OPTIMIZE (avx2) attribute_hidden;
 extern __typeof (REDIRECT_NAME) OPTIMIZE (avx2_rtm) attribute_hidden;
-extern __typeof (REDIRECT_NAME) OPTIMIZE (evex) attribute_hidden;
+
+extern __typeof (REDIRECT_NAME)
+    OPTIMIZE (sse2_unaligned) attribute_hidden;
+
+extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden;
 
 static inline void *
 IFUNC_SELECTOR (void)
 {
-  const struct cpu_featurescpu_features = __get_cpu_features ();
+  const struct cpu_features *cpu_features = __get_cpu_features ();
 
-  if (CPU_FEATURE_USABLE_P (cpu_features, AVX2)
-      && CPU_FEATURES_ARCH_P (cpu_features, AVX_Fast_Unaligned_Load))
+  if (X86_ISA_CPU_FEATURE_USABLE_P (cpu_features, AVX2)
+      && X86_ISA_CPU_FEATURES_ARCH_P (cpu_features,
+                                     AVX_Fast_Unaligned_Load, ))
     {
-      if (CPU_FEATURE_USABLE_P (cpu_features, AVX512VL)
-         && CPU_FEATURE_USABLE_P (cpu_features, AVX512BW))
+      if (X86_ISA_CPU_FEATURE_USABLE_P (cpu_features, AVX512VL)
+         && X86_ISA_CPU_FEATURE_USABLE_P (cpu_features, AVX512BW))
        return OPTIMIZE (evex);
 
       if (CPU_FEATURE_USABLE_P (cpu_features, RTM))
        return OPTIMIZE (avx2_rtm);
 
-      if (!CPU_FEATURES_ARCH_P (cpu_features, Prefer_No_VZEROUPPER))
+      if (X86_ISA_CPU_FEATURES_ARCH_P (cpu_features,
+                                      Prefer_No_VZEROUPPER, !))
        return OPTIMIZE (avx2);
     }
 
-  if (CPU_FEATURES_ARCH_P (cpu_features, Fast_Unaligned_Load))
+  if (X86_ISA_CPU_FEATURES_ARCH_P (cpu_features, Fast_Unaligned_Load, ))
     return OPTIMIZE (sse2_unaligned);
 
   return OPTIMIZE (sse2);
index 323225a..5c1c46b 100644 (file)
 
 #include <init-arch.h>
 
-extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2_unaligned)
-  attribute_hidden;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (evex) attribute_hidden;
+
 extern __typeof (REDIRECT_NAME) OPTIMIZE (avx2) attribute_hidden;
 extern __typeof (REDIRECT_NAME) OPTIMIZE (avx2_rtm) attribute_hidden;
-extern __typeof (REDIRECT_NAME) OPTIMIZE (evex) attribute_hidden;
+
+extern __typeof (REDIRECT_NAME)
+    OPTIMIZE (sse2_unaligned) attribute_hidden;
 
 static inline void *
 IFUNC_SELECTOR (void)
 {
-  const struct cpu_featurescpu_features = __get_cpu_features ();
+  const struct cpu_features *cpu_features = __get_cpu_features ();
 
-  if (CPU_FEATURE_USABLE_P (cpu_features, AVX2)
-      && CPU_FEATURES_ARCH_P (cpu_features, AVX_Fast_Unaligned_Load))
+  if (X86_ISA_CPU_FEATURE_USABLE_P (cpu_features, AVX2)
+      && X86_ISA_CPU_FEATURES_ARCH_P (cpu_features,
+                                     AVX_Fast_Unaligned_Load, ))
     {
-      if (CPU_FEATURE_USABLE_P (cpu_features, AVX512VL)
-         && CPU_FEATURE_USABLE_P (cpu_features, AVX512BW))
+      if (X86_ISA_CPU_FEATURE_USABLE_P (cpu_features, AVX512VL)
+         && X86_ISA_CPU_FEATURE_USABLE_P (cpu_features, AVX512BW))
        return OPTIMIZE (evex);
 
       if (CPU_FEATURE_USABLE_P (cpu_features, RTM))
        return OPTIMIZE (avx2_rtm);
 
-      if (!CPU_FEATURES_ARCH_P (cpu_features, Prefer_No_VZEROUPPER))
+      if (X86_ISA_CPU_FEATURES_ARCH_P (cpu_features,
+                                      Prefer_No_VZEROUPPER, !))
        return OPTIMIZE (avx2);
     }
 
index f0bd302..277f9e7 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef STPCPY
+# define STPCPY        __stpcpy_avx2
+#endif
+
 #define USE_AS_STPCPY
-#define STRCPY __stpcpy_avx2
+#define STRCPY STPCPY
 #include "strcpy-avx2.S"
index 7c6f26c..4f1c015 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef STPCPY
+# define STPCPY        __stpcpy_evex
+#endif
+
 #define USE_AS_STPCPY
-#define STRCPY __stpcpy_evex
+#define STRCPY STPCPY
 #include "strcpy-evex.S"
index 34231f8..4c77e5b 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef STPCPY
+# define STPCPY        __stpcpy_sse2_unaligned
+#endif
+
 #define USE_AS_STPCPY
-#define STRCPY __stpcpy_sse2_unaligned
+#define STRCPY STPCPY
 #include "strcpy-sse2-unaligned.S"
index ea9f973..fcd67ca 100644 (file)
@@ -1,26 +1,7 @@
-/* stpcpy optimized with SSE2.
-   Copyright (C) 2017-2022 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#if IS_IN (libc)
-# ifndef STRCPY
-#  define STRCPY       __stpcpy_sse2
-# endif
+#ifndef STPCPY
+# define STPCPY        __stpcpy_sse2
 #endif
 
 #define USE_AS_STPCPY
+#define STRCPY STPCPY
 #include "strcpy-sse2.S"
index 032b040..b2f8c19 100644 (file)
@@ -1,4 +1,8 @@
+#ifndef STPNCPY
+# define STPNCPY       __stpncpy_avx2
+#endif
+
 #define USE_AS_STPCPY
 #define USE_AS_STRNCPY
-#define STRCPY __stpncpy_avx2
+#define STRCPY STPNCPY
 #include "strcpy-avx2.S"
index 1570014..99ea76a 100644 (file)
@@ -1,4 +1,8 @@
+#ifndef STPNCPY
+# define STPNCPY       __stpncpy_evex
+#endif
+
 #define USE_AS_STPCPY
 #define USE_AS_STRNCPY
-#define STRCPY __stpncpy_evex
+#define STRCPY STPNCPY
 #include "strcpy-evex.S"
index 658520f..c837060 100644 (file)
@@ -1,4 +1,8 @@
+#ifndef STPNCPY
+# define STPNCPY       __stpncpy_sse2_unaligned
+#endif
+
 #define USE_AS_STPCPY
 #define USE_AS_STRNCPY
-#define STRCPY __stpncpy_sse2_unaligned
+#define STRCPY STPNCPY
 #include "strcpy-sse2-unaligned.S"
index 51d42f8..d9b7fb2 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#if IS_IN (libc)
+#include <isa-level.h>
+
+#if ISA_SHOULD_BUILD (3)
+
 
 # include <sysdep.h>
 
index 110505c..0e2df94 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#if IS_IN (libc)
+#include <isa-level.h>
+
+#if ISA_SHOULD_BUILD (4)
+
 
 # include <sysdep.h>
 
index a0e051d..9d2ca1d 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#if IS_IN (libc)
+#include <isa-level.h>
+
+/* MINIMUM_X86_ISA_LEVEL <= 2 because there is no V2 implementation
+   so we need this to build for ISA V2 builds. */
+#if ISA_SHOULD_BUILD (2)
+
 
 # include <sysdep.h>
 
index 244c4a6..d1d0a33 100644 (file)
@@ -1,5 +1,6 @@
-/* strcat optimized with SSE2.
-   Copyright (C) 2017-2022 Free Software Foundation, Inc.
+/* strcat(dest, src) -- Append SRC on the end of DEST.
+   Optimized for x86-64.
+   Copyright (C) 2002-2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#if IS_IN (libc)
+#include <isa-level.h>
+
+#if ISA_SHOULD_BUILD (1)
+
+# include <sysdep.h>
+
 # ifndef STRCAT
-#  define STRCAT __strcat_sse2
+#  define STRCAT       __strcat_sse2
 # endif
-#endif
 
-#include <sysdep.h>
+/* Will be removed when new strcpy implementation gets merged.  */
 
        .text
 ENTRY (STRCAT)
@@ -256,3 +261,4 @@ ENTRY (STRCAT)
        movq    %rdi, %rax      /* Source is return value.  */
        retq
 END (STRCAT)
+#endif
index 064eafc..c725834 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#if IS_IN (libc)
+#include <isa-level.h>
+
+#if ISA_SHOULD_BUILD (3)
+
 
 # ifndef USE_AS_STRCAT
 #  include <sysdep.h>
index 32229e0..82e45ac 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#if IS_IN (libc)
+#include <isa-level.h>
+
+#if ISA_SHOULD_BUILD (4)
+
 
 # ifndef USE_AS_STRCAT
 #  include <sysdep.h>
index d5fbd95..a889cd9 100644 (file)
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#if IS_IN (libc)
+#include <isa-level.h>
+
+/* MINIMUM_X86_ISA_LEVEL <= 2 because there is no V2 implementation
+   so we need this to build for ISA V2 builds. */
+#if ISA_SHOULD_BUILD (2)
+
 
 # ifndef USE_AS_STRCAT
 #  include <sysdep.h>
index 8b5db8b..e29b411 100644 (file)
@@ -1,5 +1,5 @@
-/* strcpy optimized with SSE2.
-   Copyright (C) 2017-2022 Free Software Foundation, Inc.
+/* strcpy/stpcpy implementation for x86-64.
+   Copyright (C) 2002-2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#if IS_IN (libc)
-# ifndef STRCPY
+#include <isa-level.h>
+
+#if ISA_SHOULD_BUILD (1)
+
+# include <sysdep.h>
+
+# ifndef STPCPY
 #  define STRCPY __strcpy_sse2
 # endif
-#endif
-
-#include <sysdep.h>
 
        .text
 ENTRY (STRCPY)
@@ -144,10 +146,11 @@ ENTRY (STRCPY)
        jmp     3b              /* and look at next two bytes in %rax.  */
 
 4:
-#ifdef USE_AS_STPCPY
+# ifdef USE_AS_STPCPY
        movq    %rdx, %rax      /* Destination is return value.  */
-#else
+# else
        movq    %rdi, %rax      /* Source is return value.  */
-#endif
+# endif
        retq
 END (STRCPY)
+#endif
index bfefa65..52ecbca 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef STRNCAT
+# define STRNCAT       __strncat_avx2
+#endif
+
 #define USE_AS_STRNCAT
-#define STRCAT __strncat_avx2
+#define STRCAT STRNCAT
 #include "strcat-avx2.S"
index 8884f02..203a19b 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef STRNCAT
+# define STRNCAT       __strncat_evex
+#endif
+
 #define USE_AS_STRNCAT
-#define STRCAT __strncat_evex
+#define STRCAT STRNCAT
 #include "strcat-evex.S"
index 133e1d2..5982e22 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef STRNCAT
+# define STRNCAT       __strncat_sse2_unaligned
+#endif
+
 #define USE_AS_STRNCAT
-#define STRCAT __strncat_sse2_unaligned
+#define STRCAT STRNCAT
 #include "strcat-sse2-unaligned.S"
index 9ef8c87..ce634e9 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef STRNCPY
+# define STRNCPY       __strncpy_avx2
+#endif
+
 #define USE_AS_STRNCPY
-#define STRCPY __strncpy_avx2
+#define STRCPY STRNCPY
 #include "strcpy-avx2.S"
index 40e391f..1b3426d 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef STRNCPY
+# define STRNCPY       __strncpy_evex
+#endif
+
 #define USE_AS_STRNCPY
-#define STRCPY __strncpy_evex
+#define STRCPY STRNCPY
 #include "strcpy-evex.S"
index fcc23a7..e3eb15d 100644 (file)
@@ -1,3 +1,7 @@
+#ifndef STRNCPY
+# define STRNCPY       __strncpy_sse2_unaligned
+#endif
+
 #define USE_AS_STRNCPY
-#define STRCPY __strncpy_sse2_unaligned
+#define STRCPY STRNCPY
 #include "strcpy-sse2-unaligned.S"
index b097c20..c7d8d95 100644 (file)
@@ -1,6 +1,28 @@
-#define STRCPY __stpcpy
+/* stpcpy dispatch for RTLD and non-multiarch build
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
 
-#include "multiarch/stpcpy-sse2.S"
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#define STPCPY __stpcpy
+
+#define DEFAULT_IMPL_V1        "multiarch/stpcpy-sse2-unaligned.S"
+#define DEFAULT_IMPL_V3        "multiarch/stpcpy-avx2.S"
+#define DEFAULT_IMPL_V4        "multiarch/stpcpy-evex.S"
+
+#include "isa-default-impl.h"
 
 weak_alias (__stpcpy, stpcpy)
 libc_hidden_def (__stpcpy)
diff --git a/sysdeps/x86_64/stpncpy.S b/sysdeps/x86_64/stpncpy.S
new file mode 100644 (file)
index 0000000..5c2d6ef
--- /dev/null
@@ -0,0 +1,28 @@
+/* stpncpy dispatch for RTLD and non-multiarch build
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#define STPNCPY        __stpncpy
+
+#define DEFAULT_IMPL_V1        "multiarch/stpncpy-sse2-unaligned.S"
+#define DEFAULT_IMPL_V3        "multiarch/stpncpy-avx2.S"
+#define DEFAULT_IMPL_V4        "multiarch/stpncpy-evex.S"
+
+#include "isa-default-impl.h"
+
+weak_alias (__stpncpy, stpncpy)
+libc_hidden_def (__stpncpy)
index fc3e8a9..9bca7ec 100644 (file)
@@ -1,6 +1,5 @@
-/* strcat(dest, src) -- Append SRC on the end of DEST.
-   Optimized for x86-64.
-   Copyright (C) 2002-2022 Free Software Foundation, Inc.
+/* strcat dispatch for RTLD and non-multiarch build
+   Copyright (C) 2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
-#define STRCAT strcat
-#include "multiarch/strcat-sse2.S"
+#define STRCAT strcat
+
+#define DEFAULT_IMPL_V1        "multiarch/strcat-sse2-unaligned.S"
+#define DEFAULT_IMPL_V3        "multiarch/strcat-avx2.S"
+#define DEFAULT_IMPL_V4        "multiarch/strcat-evex.S"
+
+#include "isa-default-impl.h"
+
 libc_hidden_builtin_def (strcat)
index 05f19e6..7c04cc2 100644 (file)
@@ -1,5 +1,5 @@
-/* strcpy/stpcpy implementation for x86-64.
-   Copyright (C) 2002-2022 Free Software Foundation, Inc.
+/* strcpy dispatch for RTLD and non-multiarch build
+   Copyright (C) 2022 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
    <https://www.gnu.org/licenses/>.  */
 
 #define STRCPY strcpy
-#include "multiarch/strcpy-sse2.S"
+
+#define DEFAULT_IMPL_V1        "multiarch/strcpy-sse2-unaligned.S"
+#define DEFAULT_IMPL_V3        "multiarch/strcpy-avx2.S"
+#define DEFAULT_IMPL_V4        "multiarch/strcpy-evex.S"
+
+#include "isa-default-impl.h"
+
 libc_hidden_builtin_def (strcpy)
diff --git a/sysdeps/x86_64/strncat.S b/sysdeps/x86_64/strncat.S
new file mode 100644 (file)
index 0000000..3ba2603
--- /dev/null
@@ -0,0 +1,28 @@
+/* strncat dispatch for RTLD and non-multiarch build
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#define STRNCAT        strncat
+
+#define DEFAULT_IMPL_V1        "multiarch/strncat-sse2-unaligned.S"
+#define DEFAULT_IMPL_V3        "multiarch/strncat-avx2.S"
+#define DEFAULT_IMPL_V4        "multiarch/strncat-evex.S"
+
+#include "isa-default-impl.h"
+
+strong_alias (strncat, __strncat)
+libc_hidden_def (__strncat)
diff --git a/sysdeps/x86_64/strncpy.S b/sysdeps/x86_64/strncpy.S
new file mode 100644 (file)
index 0000000..04c904e
--- /dev/null
@@ -0,0 +1,27 @@
+/* strncpy dispatch for RTLD and non-multiarch build
+   Copyright (C) 2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#define STRNCPY        strncpy
+
+#define DEFAULT_IMPL_V1        "multiarch/strncpy-sse2-unaligned.S"
+#define DEFAULT_IMPL_V3        "multiarch/strncpy-avx2.S"
+#define DEFAULT_IMPL_V4        "multiarch/strncpy-evex.S"
+
+#include "isa-default-impl.h"
+
+libc_hidden_builtin_def (strncpy)