]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
sparc: Implement memcpy/mempcpy ifunc selection in C
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 3 Oct 2017 03:48:27 +0000 (00:48 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 28 Nov 2017 10:53:15 +0000 (08:53 -0200)
This patch refactor the SPARC64 ifunc selector to a C implementation.
The x86_64 implementation is used as default, which resulted in common
definitions (ifunc-init.h) used on both architectures.  No functional
change is expected, including ifunc resolution rules.

Checked on sparc64-linux-gnu, sparcv9-linux-gnu and x86_64-linux-gnu.

* sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy-ultra1.S: New
file.
* sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy.c: Likewise.
* sysdeps/sparc/sparc32/sparcv9/multiarch/mempcpy.c: Likewise.
* sysdeps/sparc/sparc64/multiarch/ifunc-memcpy.h: Likewise.
* sysdeps/sparc/sparc64/multiarch/memcpy-ultra1.S: Likewise.
* sysdeps/sparc/sparc64/multiarch/memcpy.c: Likewise.
* sysdeps/sparc/sparc64/multiarch/mempcpy.c: Likewise.
* sysdeps/sparc/sparc-ifunc.h (sparc_libc_ifunc_redirected): New
macro.
* sysdeps/sparc/sparc32/sparcv9/multiarch/Makefile
[$(subdir) = string] (sysdep_routines): Add memcpy-ultra1.
* sysdeps/sparc/sparc64/multiarch/Makefile [$(subdir) = string]
(sysdep_routines): Add memcpy-ultra1.
* sysdeps/sparc/sparc64/multiarch/memcpy.S: Remove file.
* sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy.S: Likewise.

Signed-off-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
13 files changed:
ChangeLog
sysdeps/sparc/sparc-ifunc.h
sysdeps/sparc/sparc32/sparcv9/multiarch/Makefile
sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy-ultra1.S [new file with mode: 0644]
sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy.S [deleted file]
sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy.c [new file with mode: 0644]
sysdeps/sparc/sparc32/sparcv9/multiarch/mempcpy.c [new file with mode: 0644]
sysdeps/sparc/sparc64/multiarch/Makefile
sysdeps/sparc/sparc64/multiarch/ifunc-memcpy.h [new file with mode: 0644]
sysdeps/sparc/sparc64/multiarch/memcpy-ultra1.S [new file with mode: 0644]
sysdeps/sparc/sparc64/multiarch/memcpy.S [deleted file]
sysdeps/sparc/sparc64/multiarch/memcpy.c [new file with mode: 0644]
sysdeps/sparc/sparc64/multiarch/mempcpy.c [new file with mode: 0644]

index 2458b1105e2409ae68e4122e5f481fd40590e3ee..2b2baae0158b04b4ff943e68014c800a7d125d2f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2017-11-28  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
+
+       * sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy-ultra1.S: New
+       file.
+       * sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy.c: Likewise.
+       * sysdeps/sparc/sparc32/sparcv9/multiarch/mempcpy.c: Likewise.
+       * sysdeps/sparc/sparc64/multiarch/ifunc-memcpy.h: Likewise.
+       * sysdeps/sparc/sparc64/multiarch/memcpy-ultra1.S: Likewise.
+       * sysdeps/sparc/sparc64/multiarch/memcpy.c: Likewise.
+       * sysdeps/sparc/sparc64/multiarch/mempcpy.c: Likewise.
+       * sysdeps/sparc/sparc-ifunc.h (sparc_libc_ifunc_redirected): New
+       macro.
+       * sysdeps/sparc/sparc32/sparcv9/multiarch/Makefile
+       [$(subdir) = string] (sysdep_routines): Add memcpy-ultra1.
+       * sysdeps/sparc/sparc64/multiarch/Makefile [$(subdir) = string]
+       (sysdep_routines): Add memcpy-ultra1.
+       * sysdeps/sparc/sparc64/multiarch/memcpy.S: Remove file.
+       * sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy.S: Likewise.
+
 2017-11-28  Joseph Myers  <joseph@codesourcery.com>
 
        * sysdeps/alpha/fpu/cfloat-compat.h: Include <libm-alias-float.h>.
index 4b1ea00bded60f2ee3f866d90baae87b2c18559d..044fe365d68e6b455441b9ac6d5b96231a9417ab 100644 (file)
@@ -161,10 +161,23 @@ END (__##name)
 
 
 #else  /* __ASSEMBLER__ */
+# define INIT_ARCH()
+
+# define sparc_libc_ifunc_redirected(redirected_name, name, expr)      \
+  __ifunc (redirected_name, name, expr(hwcap), int hwcap, INIT_ARCH)
 
 # define sparc_libm_ifunc(name, expr)                          \
   __ifunc (name, name, expr, int hwcap, libm_ifunc_init)
 
 # define sparc_libc_ifunc(name, expr) sparc_libm_ifunc (name, expr)
 
+/* It essentially does libc_hidden_builtin_def (name) and redirect
+   the internal redirected symbol to ifunc implementation.  */
+# if defined SHARED
+#  define sparc_ifunc_redirected_hidden_def(redirect_name, name) \
+  __hidden_ver1 (name, __GI_##name, redirect_name) \
+    __attribute__ ((visibility ("hidden")));
+# else
+#  define sparc_ifunc_redirected_hidden_def(redirect_name, name)
+# endif
 #endif /* __ASSEMBLER__ */
index 4ad7aff9147073b04190960993ca0fdb0048eb1a..ca44798b2385717592c05f43bc8e8f75293b509d 100644 (file)
@@ -8,5 +8,6 @@ endif
 
 ifeq ($(subdir),string)
 sysdep_routines += memcpy-ultra3 memcpy-niagara1 memcpy-niagara2 \
-                  memset-niagara1 memcpy-niagara4 memset-niagara4
+                  memset-niagara1 memcpy-niagara4 memset-niagara4 \
+                  memcpy-ultra1
 endif
diff --git a/sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy-ultra1.S b/sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy-ultra1.S
new file mode 100644 (file)
index 0000000..d28a899
--- /dev/null
@@ -0,0 +1,33 @@
+/* Default SPARC32 memcpy implementation.
+   Copyright (C) 2017 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
+   <http://www.gnu.org/licenses/>.  */
+
+#if IS_IN (libc)
+# include <sysdep.h>
+
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef weak_alias
+# define weak_alias(x, y)
+# undef libc_hidden_def
+# define libc_hidden_def(name)
+
+# define memcpy         __memcpy_ultra1
+# define __memcpy_large __memcpy_large_ultra1
+# define __mempcpy      __mempcpy_ultra1
+# include <sysdeps/sparc/sparc32/sparcv9/memcpy.S>
+#endif
diff --git a/sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy.S b/sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy.S
deleted file mode 100644 (file)
index 14df91e..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#define ASI_PNF     0x82
-#define ASI_BLK_P   0xf0
-#define XCC icc
-#include <sparc64/multiarch/memcpy.S>
diff --git a/sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy.c b/sysdeps/sparc/sparc32/sparcv9/multiarch/memcpy.c
new file mode 100644 (file)
index 0000000..369acac
--- /dev/null
@@ -0,0 +1 @@
+#include <sysdeps/sparc/sparc64/multiarch/memcpy.c>
diff --git a/sysdeps/sparc/sparc32/sparcv9/multiarch/mempcpy.c b/sysdeps/sparc/sparc32/sparcv9/multiarch/mempcpy.c
new file mode 100644 (file)
index 0000000..616a538
--- /dev/null
@@ -0,0 +1 @@
+#include <sysdeps/sparc/sparc64/multiarch/mempcpy.c>
index 55b757f9add4be6c4ca9cb5e08d1283cbf01a48b..4e52526c1529b44f54a3e4c33aeb83a9bdbaaca8 100644 (file)
@@ -8,7 +8,8 @@ endif
 
 ifeq ($(subdir),string)
 sysdep_routines += memcpy-ultra3 memcpy-niagara1 memcpy-niagara2 \
-                  memset-niagara1 memcpy-niagara4 memset-niagara4
+                  memset-niagara1 memcpy-niagara4 memset-niagara4 \
+                  memcpy-ultra1
 endif
 
 ifeq ($(subdir),stdlib)
diff --git a/sysdeps/sparc/sparc64/multiarch/ifunc-memcpy.h b/sysdeps/sparc/sparc64/multiarch/ifunc-memcpy.h
new file mode 100644 (file)
index 0000000..46f3795
--- /dev/null
@@ -0,0 +1,40 @@
+/* Common definition for memcpy and mempcpy implementation.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2017 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <ifunc-init.h>
+
+extern __typeof (REDIRECT_NAME) OPTIMIZE (niagara4) attribute_hidden;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (niagara2) attribute_hidden;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (niagara1) attribute_hidden;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (ultra3) attribute_hidden;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (ultra1) attribute_hidden;
+
+static inline void *
+IFUNC_SELECTOR (int hwcap)
+{
+  if (hwcap & HWCAP_SPARC_CRYPTO)
+    return OPTIMIZE (niagara4);
+  if (hwcap & HWCAP_SPARC_N2)
+    return OPTIMIZE (niagara2);
+  if (hwcap & HWCAP_SPARC_BLKINIT)
+    return OPTIMIZE (niagara1);
+  if (hwcap & HWCAP_SPARC_ULTRA3)
+    return OPTIMIZE (ultra3);
+  return OPTIMIZE (ultra1);
+}
diff --git a/sysdeps/sparc/sparc64/multiarch/memcpy-ultra1.S b/sysdeps/sparc/sparc64/multiarch/memcpy-ultra1.S
new file mode 100644 (file)
index 0000000..c5a4479
--- /dev/null
@@ -0,0 +1,33 @@
+/* Default SPARC64 memcpy implementation.
+   Copyright (C) 2017 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
+   <http://www.gnu.org/licenses/>.  */
+
+#if IS_IN (libc)
+# include <sysdep.h>
+
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef weak_alias
+# define weak_alias(x, y)
+# undef libc_hidden_def
+# define libc_hidden_def(name)
+
+# define memcpy         __memcpy_ultra1
+# define __memcpy_large __memcpy_large_ultra1
+# define __mempcpy      __mempcpy_ultra1
+# include <sysdeps/sparc/sparc64/memcpy.S>
+#endif
diff --git a/sysdeps/sparc/sparc64/multiarch/memcpy.S b/sysdeps/sparc/sparc64/multiarch/memcpy.S
deleted file mode 100644 (file)
index b6396ee..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/* Multiple versions of memcpy
-   All versions must be listed in ifunc-impl-list.c.
-   Copyright (C) 2010-2017 Free Software Foundation, Inc.
-   Contributed by David S. Miller (davem@davemloft.net)
-   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
-   <http://www.gnu.org/licenses/>.  */
-
-#include <sysdep.h>
-
-#if IS_IN (libc)
-       .text
-ENTRY(memcpy)
-       .type   memcpy, @gnu_indirect_function
-# ifdef SHARED
-       SETUP_PIC_REG_LEAF(o3, o5)
-# endif
-       set     HWCAP_SPARC_CRYPTO, %o1
-       andcc   %o0, %o1, %g0
-       be      1f
-        andcc  %o0, HWCAP_SPARC_N2, %g0
-# ifdef SHARED
-       sethi   %gdop_hix22(__memcpy_niagara4), %o1
-       xor     %o1, %gdop_lox10(__memcpy_niagara4), %o1
-# else
-       set     __memcpy_niagara4, %o1
-# endif
-       ba      10f
-        nop
-1:     be      1f
-        andcc  %o0, HWCAP_SPARC_BLKINIT, %g0
-# ifdef SHARED
-       sethi   %gdop_hix22(__memcpy_niagara2), %o1
-       xor     %o1, %gdop_lox10(__memcpy_niagara2), %o1
-# else
-       set     __memcpy_niagara2, %o1
-# endif
-       ba      10f
-        nop
-1:     be      1f
-        andcc  %o0, HWCAP_SPARC_ULTRA3, %g0
-# ifdef SHARED
-       sethi   %gdop_hix22(__memcpy_niagara1), %o1
-       xor     %o1, %gdop_lox10(__memcpy_niagara1), %o1
-# else
-       set     __memcpy_niagara1, %o1
-# endif
-       ba      10f
-        nop
-1:     be      9f
-        nop
-# ifdef SHARED
-       sethi   %gdop_hix22(__memcpy_ultra3), %o1
-       xor     %o1, %gdop_lox10(__memcpy_ultra3), %o1
-# else
-       set     __memcpy_ultra3, %o1
-# endif
-       ba      10f
-        nop
-9:
-# ifdef SHARED
-       sethi   %gdop_hix22(__memcpy_ultra1), %o1
-       xor     %o1, %gdop_lox10(__memcpy_ultra1), %o1
-# else
-       set     __memcpy_ultra1, %o1
-# endif
-10:
-# ifdef SHARED
-       add     %o3, %o1, %o1
-# endif
-       retl
-        mov    %o1, %o0
-END(memcpy)
-
-ENTRY(__mempcpy)
-       .type   __mempcpy, @gnu_indirect_function
-# ifdef SHARED
-       SETUP_PIC_REG_LEAF(o3, o5)
-# endif
-       set     HWCAP_SPARC_CRYPTO, %o1
-       andcc   %o0, %o1, %g0
-       be      1f
-        andcc  %o0, HWCAP_SPARC_N2, %g0
-# ifdef SHARED
-       sethi   %gdop_hix22(__mempcpy_niagara4), %o1
-       xor     %o1, %gdop_lox10(__mempcpy_niagara4), %o1
-# else
-       set     __mempcpy_niagara4, %o1
-# endif
-       ba      10f
-        nop
-1:     be      1f
-        andcc  %o0, HWCAP_SPARC_BLKINIT, %g0
-# ifdef SHARED
-       sethi   %gdop_hix22(__mempcpy_niagara2), %o1
-       xor     %o1, %gdop_lox10(__mempcpy_niagara2), %o1
-# else
-       set     __mempcpy_niagara2, %o1
-# endif
-       ba      10f
-        nop
-1:     be      1f
-        andcc  %o0, HWCAP_SPARC_ULTRA3, %g0
-# ifdef SHARED
-       sethi   %gdop_hix22(__mempcpy_niagara1), %o1
-       xor     %o1, %gdop_lox10(__mempcpy_niagara1), %o1
-# else
-       set     __mempcpy_niagara1, %o1
-# endif
-       ba      10f
-        nop
-1:     be      9f
-        nop
-# ifdef SHARED
-       sethi   %gdop_hix22(__mempcpy_ultra3), %o1
-       xor     %o1, %gdop_lox10(__mempcpy_ultra3), %o1
-# else
-       set     __mempcpy_ultra3, %o1
-# endif
-       ba      10f
-        nop
-9:
-# ifdef SHARED
-       sethi   %gdop_hix22(__mempcpy_ultra1), %o1
-       xor     %o1, %gdop_lox10(__mempcpy_ultra1), %o1
-# else
-       set     __mempcpy_ultra1, %o1
-# endif
-10:
-# ifdef SHARED
-       add     %o3, %o1, %o1
-# endif
-       retl
-        mov    %o1, %o0
-END(__mempcpy)
-
-libc_hidden_builtin_def (memcpy)
-
-libc_hidden_def (__mempcpy)
-weak_alias (__mempcpy, mempcpy)
-libc_hidden_builtin_def (mempcpy)
-
-#undef libc_hidden_builtin_def
-#define libc_hidden_builtin_def(name)
-#undef weak_alias
-#define weak_alias(x, y)
-#undef libc_hidden_def
-#define libc_hidden_def(name)
-
-#define memcpy __memcpy_ultra1
-#define __mempcpy __mempcpy_ultra1
-
-#endif
-
-#include "../memcpy.S"
diff --git a/sysdeps/sparc/sparc64/multiarch/memcpy.c b/sysdeps/sparc/sparc64/multiarch/memcpy.c
new file mode 100644 (file)
index 0000000..7d1cb2d
--- /dev/null
@@ -0,0 +1,33 @@
+/* Multiple versions of memcpy.  SPARC64/Linux version.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2017 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
+   <http://www.gnu.org/licenses/>.  */
+
+#if IS_IN (libc)
+# define memcpy __redirect_memcpy
+# include <string.h>
+# undef memcpy
+
+# include <sparc-ifunc.h>
+
+# define SYMBOL_NAME memcpy
+# include "ifunc-memcpy.h"
+
+sparc_libc_ifunc_redirected (__redirect_memcpy, memcpy, IFUNC_SELECTOR)
+
+sparc_ifunc_redirected_hidden_def (__redirect_memcpy, memcpy)
+#endif
diff --git a/sysdeps/sparc/sparc64/multiarch/mempcpy.c b/sysdeps/sparc/sparc64/multiarch/mempcpy.c
new file mode 100644 (file)
index 0000000..53c415b
--- /dev/null
@@ -0,0 +1,39 @@
+/* Multiple versions of mempcpy.  SPARC64/Linux version.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2017 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
+   <http://www.gnu.org/licenses/>.  */
+
+#if IS_IN (libc)
+# define mempcpy __redirect_mempcpy
+# define __mempcpy __redirect___mempcpy
+# define NO_MEMPCPY_STPCPY_REDIRECT
+# define __NO_STRING_INLINES
+# include <string.h>
+# undef mempcpy
+# undef __mempcpy
+
+# include <sparc-ifunc.h>
+
+# define SYMBOL_NAME mempcpy
+# include "ifunc-memcpy.h"
+
+sparc_libc_ifunc_redirected (__redirect_mempcpy, __mempcpy, IFUNC_SELECTOR)
+
+sparc_ifunc_redirected_hidden_def (__redirect___mempcpy, __mempcpy)
+weak_alias (__mempcpy, mempcpy)
+sparc_ifunc_redirected_hidden_def (__redirect_mempcpy, mempcpy)
+#endif