]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
wcsmbs: optimize wcscat
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 5 Feb 2019 19:35:12 +0000 (17:35 -0200)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 27 Feb 2019 13:00:37 +0000 (10:00 -0300)
This patch rewrites wcscat using wcslen and wcscpy.  This is similar to
the optimization done on strcat by 6e46de42fe.

The strcpy changes are mainly to add the internal alias to avoid PLT
calls.

Checked on x86_64-linux-gnu and a build against the affected
architectures.

* include/wchar.h (__wcscpy): New prototype.
* sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy-ppc32.c
(__wcscpy): Route internal symbol to generic implementation.
* sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy.c (wcscpy):
Add internal __wcscpy alias.
* sysdeps/powerpc/powerpc64/multiarch/wcscpy.c (wcscpy): Likewise.
* sysdeps/s390/wcscpy.c (wcscpy): Likewise.
* sysdeps/x86_64/multiarch/wcscpy.c (wcscpy): Likewise.
* wcsmbs/wcscpy.c (wcscpy): Add
* sysdeps/x86_64/multiarch/wcscpy-c.c (WCSCPY): Adjust macro to
use generic implementation.
* wcsmbs/wcscat.c (wcscat): Rewrite using wcslen and wcscpy.

ChangeLog
include/wchar.h
sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy-ppc32.c
sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy.c
sysdeps/powerpc/powerpc64/multiarch/wcscpy.c
sysdeps/s390/wcscpy.c
sysdeps/x86_64/multiarch/wcscpy-c.c
sysdeps/x86_64/multiarch/wcscpy.c
wcsmbs/wcscat.c
wcsmbs/wcscpy.c

index 5ff8f8af438dbae2d6c51f914c8c823a3073c1f3..b9637367dd8e71a9945fbf12637f9fdf7a0e5745 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2019-02-27  Adhemerval Zanella  <adhemerval.zanella@linaro.org>
 
+       * include/wchar.h (__wcscpy): New prototype.
+       * sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy-ppc32.c
+       (__wcscpy): Route internal symbol to generic implementation.
+       * sysdeps/powerpc/powerpc32/power4/multiarch/wcscpy.c (wcscpy):
+       Add internal __wcscpy alias.
+       * sysdeps/powerpc/powerpc64/multiarch/wcscpy.c (wcscpy): Likewise.
+       * sysdeps/s390/wcscpy.c (wcscpy): Likewise.
+       * sysdeps/x86_64/multiarch/wcscpy.c (wcscpy): Likewise.
+       * wcsmbs/wcscpy.c (wcscpy): Add
+       * sysdeps/x86_64/multiarch/wcscpy-c.c (WCSCPY): Adjust macro to
+       use generic implementation.
+       * wcsmbs/wcscat.c (wcscat): Rewrite using wcslen and wcscpy.
+
        * wcsmbs/wcpncpy.c (__wcpcpy): Rewrite using wcslen, wmemcpy, and
        wmemset.
 
index 614073bcb3a011a787478d8562e9216cdbd9cf7f..2cb44954fc2da9a429b38b8f97452dec8f3a0ae5 100644 (file)
@@ -182,6 +182,10 @@ extern size_t __wcsnrtombs (char *__restrict __dst,
                            size_t __nwc, size_t __len,
                            __mbstate_t *__restrict __ps)
      attribute_hidden;
+extern wchar_t *__wcscpy (wchar_t *__restrict __dest,
+                         const wchar_t *__restrict __src)
+                         attribute_hidden __nonnull ((1, 2));
+libc_hidden_proto (__wcscpy)
 extern wchar_t *__wcsncpy (wchar_t *__restrict __dest,
                           const wchar_t *__restrict __src, size_t __n);
 extern wchar_t *__wcpcpy (wchar_t *__dest, const wchar_t *__src);
index 52b692b47b73c5d65dac588b9cbb15119393506d..31e0d81ef03cf14c3e638e5951da7a439dde9a34 100644 (file)
 
 #include <wchar.h>
 
-#if IS_IN (libc)
-# define WCSCPY  __wcscpy_ppc
-#endif
-
 extern __typeof (wcscpy) __wcscpy_ppc;
 
+#define WCSCPY  __wcscpy_ppc
 #include <wcsmbs/wcscpy.c>
+
+#ifdef SHARED
+__hidden_ver1 (__wcscpy_ppc, __GI___wcscpy, __wcscpy_ppc);
+#endif
index ecca37d5d66415d3735f5e090ff23b4e32efa732..e87984669e5c8ea61cc5e91660384a5b32e9c0f0 100644 (file)
    <http://www.gnu.org/licenses/>.  */
 
 #if IS_IN (libc)
+# define wcscpy __redirect_wcscpy
 # include <wchar.h>
-# include <shlib-compat.h>
+# undef wcscpy
 # include "init-arch.h"
 
-extern __typeof (wcscpy) __wcscpy_ppc attribute_hidden;
-extern __typeof (wcscpy) __wcscpy_power6 attribute_hidden;
-extern __typeof (wcscpy) __wcscpy_power7 attribute_hidden;
+extern __typeof (__redirect_wcscpy) __wcscpy_ppc attribute_hidden;
+extern __typeof (__redirect_wcscpy) __wcscpy_power6 attribute_hidden;
+extern __typeof (__redirect_wcscpy) __wcscpy_power7 attribute_hidden;
 
-libc_ifunc (wcscpy,
-            (hwcap & PPC_FEATURE_HAS_VSX)
-             ? __wcscpy_power7 :
-              (hwcap & PPC_FEATURE_ARCH_2_05)
-              ? __wcscpy_power6
-             : __wcscpy_ppc);
-#else
-#include <wcsmbs/wcscpy.c>
+libc_ifunc_redirected (__redirect_wcscpy, wcscpy,
+                      (hwcap & PPC_FEATURE_HAS_VSX)
+                      ? __wcscpy_power7 :
+                        (hwcap & PPC_FEATURE_ARCH_2_05)
+                        ? __wcscpy_power6
+                      : __wcscpy_ppc);
+weak_alias (wcscpy, __wcscpy)
 #endif
index 3cea9a489d74787a6be8a8992305aa675c44fd69..3f918b27c68b745d7af0c953c97c8666e6a45e27 100644 (file)
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#if IS_IN (libc)
-# include <wchar.h>
-# include <shlib-compat.h>
-# include "init-arch.h"
+#define __wcscpy __redirect___wcscpy
+#include <wchar.h>
+#undef __wcscpy
+#include <shlib-compat.h>
+#include "init-arch.h"
 
 extern __typeof (wcscpy) __wcscpy_ppc attribute_hidden;
 extern __typeof (wcscpy) __wcscpy_power6 attribute_hidden;
 extern __typeof (wcscpy) __wcscpy_power7 attribute_hidden;
 
-libc_ifunc (wcscpy,
-            (hwcap & PPC_FEATURE_HAS_VSX)
-             ? __wcscpy_power7 :
-              (hwcap & PPC_FEATURE_ARCH_2_05)
-              ? __wcscpy_power6
-             : __wcscpy_ppc);
-#else
-#include <wcsmbs/wcscpy.c>
-#endif
+libc_ifunc_redirected (__redirect___wcscpy, __wcscpy,
+                      (hwcap & PPC_FEATURE_HAS_VSX)
+                      ? __wcscpy_power7 :
+                        (hwcap & PPC_FEATURE_ARCH_2_05)
+                        ? __wcscpy_power6
+                      : __wcscpy_ppc);
+weak_alias (__wcscpy, wcscpy)
index 2e8ef5024f6a86d1599be1109f88e9a76e97b2d8..a569f917af97743984a3f8731a0ff46c085dd85c 100644 (file)
@@ -30,9 +30,11 @@ extern __typeof (wcscpy) WCSCPY_C attribute_hidden;
 extern __typeof (wcscpy) WCSCPY_Z13 attribute_hidden;
 # endif
 
-s390_libc_ifunc_expr (wcscpy, wcscpy,
+s390_libc_ifunc_expr (wcscpy, __wcscpy,
                      (HAVE_WCSCPY_Z13 && (hwcap & HWCAP_S390_VX))
                      ? WCSCPY_Z13
                      : WCSCPY_DEFAULT
                      )
+weak_alias (__wcscpy, wcscpy)
+libc_hidden_def (__wcscpy)
 #endif
index a51a83a9bec2adbc578c4bf5a3b79a0e5ab93013..26d6984e9b5caac8a9d0b36b8fa149006e5f530c 100644 (file)
@@ -1,5 +1,5 @@
 #if IS_IN (libc)
-# define wcscpy  __wcscpy_sse2
+# define WCSCPY  __wcscpy_sse2
 #endif
 
-#include "wcsmbs/wcscpy.c"
+#include <wcsmbs/wcscpy.c>
index 101a585358f6d9bcb00e885cb15a794aaf23d908..96151b4963b8c2d4112f40a9f8984839aba6afec 100644 (file)
@@ -19,9 +19,9 @@
 
 /* Define multiple versions only for the definition in libc.  */
 #if IS_IN (libc)
-# define wcscpy __redirect_wcscpy
+# define __wcscpy __redirect_wcscpy
 # include <wchar.h>
-# undef wcscpy
+# undef __wcscpy
 
 # define SYMBOL_NAME wcscpy
 # include <init-arch.h>
@@ -40,5 +40,10 @@ IFUNC_SELECTOR (void)
   return OPTIMIZE (sse2);
 }
 
-libc_ifunc_redirected (__redirect_wcscpy, wcscpy, IFUNC_SELECTOR ());
+libc_ifunc_redirected (__redirect_wcscpy, __wcscpy, IFUNC_SELECTOR ());
+weak_alias (__wcscpy, wcscpy)
+# ifdef SHARED
+__hidden_ver1 (__wcscpy, __GI___wcscpy, __redirect_wcscpy)
+  __attribute__((visibility ("hidden"))) __attribute_copy__ (wcscpy);
+# endif
 #endif
index 6a25b20e3185696359926a419bb10cb7ba6b544b..1a9d667fda2491b132390ef4fa513d57ce6d04b9 100644 (file)
 wchar_t *
 __wcscat (wchar_t *dest, const wchar_t *src)
 {
-  wchar_t *s1 = dest;
-  const wchar_t *s2 = src;
-  wchar_t c;
-
-  /* Find the end of the string.  */
-  do
-    c = *s1++;
-  while (c != L'\0');
-
-  /* Make S1 point before the next character, so we can increment
-     it while memory is read (wins on pipelined cpus). */
-  s1 -= 2;
-
-  do
-    {
-      c = *s2++;
-      *++s1 = c;
-    }
-  while (c != L'\0');
-
+  __wcscpy (dest + __wcslen (dest), src);
   return dest;
 }
 #ifndef WCSCAT
index 7a34c77a9e21da7daa7a7a47c597860d5e7ebdec..636bf6bd01142f0cfec5e4d77df23171b2086fcf 100644 (file)
 #include <wchar.h>
 
 
-#ifndef WCSCPY
-# define WCSCPY wcscpy
+#ifdef WCSCPY
+# define __wcscpy WCSCPY
 #endif
 
 /* Copy SRC to DEST.  */
 wchar_t *
-WCSCPY (wchar_t *dest, const wchar_t *src)
+__wcscpy (wchar_t *dest, const wchar_t *src)
 {
   wint_t c;
   wchar_t *wcp;
@@ -58,3 +58,7 @@ WCSCPY (wchar_t *dest, const wchar_t *src)
 
   return dest;
 }
+#ifndef WCSCPY
+weak_alias (__wcscpy, wcscpy)
+libc_hidden_def (__wcscpy)
+#endif