]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86: Add support to build wcscpy with explicit ISA level
authorNoah Goldstein <goldstein.w.n@gmail.com>
Wed, 13 Jul 2022 23:33:00 +0000 (16:33 -0700)
committerNoah Goldstein <goldstein.w.n@gmail.com>
Sat, 16 Jul 2022 10:07:59 +0000 (03:07 -0700)
1. Add ISA level build guards to different implementations.
    - wcscpy-ssse3.S is used as ISA level 2/3/4.
    - wcscpy-generic.c is only used at ISA level 1 and will
      only build if compiled with ISA level == 1. Otherwise
      there is no reason to include it as we will always use
      wcscpy-ssse3.S

2. 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.

sysdeps/x86_64/Makefile
sysdeps/x86_64/multiarch/Makefile
sysdeps/x86_64/multiarch/ifunc-impl-list.c
sysdeps/x86_64/multiarch/wcscpy-generic.c
sysdeps/x86_64/multiarch/wcscpy-ssse3.S
sysdeps/x86_64/multiarch/wcscpy.c
sysdeps/x86_64/wcscpy-generic.c [new file with mode: 0644]
sysdeps/x86_64/wcscpy.S [new file with mode: 0644]

index 341ee69a3537d0a41c2827b3e5fddb016f8e5aa4..c19bef2decacd052fe90c2b6d87b99f59822e6df 100644 (file)
@@ -199,6 +199,7 @@ endif
 ifeq ($(subdir),wcsmbs)
 
 sysdep_routines += \
+  wcscpy-generic \
   wcsncmp-generic \
   wcsnlen-generic \
 # sysdep_routines
index ba29a65716fb8ee390b09b5854c217429e0284bc..df4601c294deb17990c0fe5d5b0d7948c0fe76c6 100644 (file)
@@ -134,7 +134,6 @@ sysdep_routines += \
   wcscmp-avx2-rtm \
   wcscmp-evex \
   wcscmp-sse2 \
-  wcscpy-generic \
   wcscpy-ssse3 \
   wcslen-avx2 \
   wcslen-avx2-rtm \
index 3b1df9b73cb2a9b73df5f3112bbcf519f11c2d18..9318e98cc859206b3693cccfed90b20b6876a8d3 100644 (file)
@@ -791,9 +791,15 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 
   /* Support sysdeps/x86_64/multiarch/wcscpy.c.  */
   IFUNC_IMPL (i, name, wcscpy,
-             IFUNC_IMPL_ADD (array, i, wcscpy, CPU_FEATURE_USABLE (SSSE3),
-                             __wcscpy_ssse3)
-             IFUNC_IMPL_ADD (array, i, wcscpy, 1, __wcscpy_generic))
+             /* ISA V4 wrapper for SSSE3 implementation because
+                the SSSE3 implementation is also used at ISA
+                level 3/4.  */
+             X86_IFUNC_IMPL_ADD_V4 (array, i, wcscpy,
+                                    CPU_FEATURE_USABLE (SSSE3),
+                                    __wcscpy_ssse3)
+             X86_IFUNC_IMPL_ADD_V1 (array, i, wcscpy,
+                                    1,
+                                    __wcscpy_generic))
 
   /* Support sysdeps/x86_64/multiarch/wcslen.c.  */
   IFUNC_IMPL (i, name, wcslen,
index 5ea905f33fa2a9066c65490b9fb4c12d81f7d463..93d314aaad4cd8d52d6144321dc1c4d1b704bda7 100644 (file)
    <https://www.gnu.org/licenses/>.  */
 
 
-#if IS_IN (libc)
+#include <isa-level.h>
+
+#if ISA_SHOULD_BUILD (1)
+
 # define WCSCPY  __wcscpy_generic
-#endif
+# include <wcsmbs/wcscpy.c>
 
-#include <wcsmbs/wcscpy.c>
+#endif
index aa2b9d030f880f583483fe1c204a4cdbc3c08656..62741071e653ae531a06b221847c35f085e87930 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 <= 4 because there are not V3/V4
+   implementations so we need this to build for ISA V3/V4
+    builds. */
+#if ISA_SHOULD_BUILD (4)
+
+# ifndef WCSCPY
+#  define WCSCPY       __wcscpy_ssse3
+# endif
+
 # include <sysdep.h>
 
        .section .text.ssse3,"ax",@progbits
-ENTRY (__wcscpy_ssse3)
+ENTRY (WCSCPY)
 
        mov     %rsi, %rcx
        mov     %rdi, %rdx
@@ -547,5 +557,5 @@ L(Exit16):
        mov     %rdi, %rax
        ret
 
-END(__wcscpy_ssse3)
+END(WCSCPY)
 #endif
index 53c3228dc2cc9471bacd24fd0790373f6b7c53e7..92c917b6b4951fb0cfe74bd32852ea298e3ab7bf 100644 (file)
 # define SYMBOL_NAME wcscpy
 # include <init-arch.h>
 
-extern __typeof (REDIRECT_NAME) OPTIMIZE (generic) attribute_hidden;
 extern __typeof (REDIRECT_NAME) OPTIMIZE (ssse3) attribute_hidden;
 
+extern __typeof (REDIRECT_NAME) OPTIMIZE (generic) attribute_hidden;
+
 static inline void *
 IFUNC_SELECTOR (void)
 {
   const struct cpu_features* cpu_features = __get_cpu_features ();
 
-  if (CPU_FEATURE_USABLE_P (cpu_features, SSSE3))
+  if (X86_ISA_CPU_FEATURE_USABLE_P (cpu_features, SSSE3))
     return OPTIMIZE (ssse3);
 
   return OPTIMIZE (generic);
diff --git a/sysdeps/x86_64/wcscpy-generic.c b/sysdeps/x86_64/wcscpy-generic.c
new file mode 100644 (file)
index 0000000..eef74ae
--- /dev/null
@@ -0,0 +1,31 @@
+/* wcscpy dispatch for RTLD and non-multiarch .c ISA level 1 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/>.  */
+
+/* wcscpy non-multiarch build is split into two files,
+   wcscpy-generic.c and wcscpy.S. The wcscpy-generic.c build is for
+   ISA level <= 1 and just uses wcsmbs/wcscpy.c.  This must be split
+   into two files because we cannot include C code from assembly or
+   vice versa.  */
+
+#include <isa-level.h>
+
+#if MINIMUM_X86_ISA_LEVEL <= 1
+
+# include "wcsmbs/wcscpy.c"
+
+#endif
diff --git a/sysdeps/x86_64/wcscpy.S b/sysdeps/x86_64/wcscpy.S
new file mode 100644 (file)
index 0000000..11d0bb4
--- /dev/null
@@ -0,0 +1,40 @@
+/* wcscpy dispatch for RTLD and non-multiarch .c files
+   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/>.  */
+
+/* wcscpy non-multiarch build is split into two files,
+   wcscpy-generic.c and wcscpy.S. The wcscpy.S build is for
+   ISA level >= 2 uses the optimized assembly implementations in
+   multiarch/wcscpy*.S.  This must be split into two files because
+   we cannot include C code from assembly or vice versa.  */
+
+#include <isa-level.h>
+
+#if MINIMUM_X86_ISA_LEVEL >= 2
+
+# define WCSCPY        __wcscpy
+
+# define DEFAULT_IMPL_V2       "multiarch/wcscpy-ssse3.S"
+/* isa-default-impl.h expects DEFAULT_IMPL_V1 to be defined but it
+   should never be used from here.  */
+# define DEFAULT_IMPL_V1       "ERROR -- Invalid ISA IMPL"
+
+# include "isa-default-impl.h"
+
+weak_alias (__wcscpy, wcscpy)
+libc_hidden_def (__wcscpy)
+#endif