Blame SOURCES/glibc-rh1240351-5.patch

147e83
    Backport of the following commit:
147e83
    
147e83
    commit 96d6fd6c4060d739abb1822e7ad633af749532b2
147e83
    Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
147e83
    Date:   Tue Dec 23 05:59:44 2014 -0600
147e83
    
147e83
        powerpc: Optimized st{r,p}cpy for POWER8/PPC64
147e83
    
147e83
        This patch adds an optimized POWER8 strcpy using unaligned accesses.
147e83
        For strings up to 16 bytes the implementation first calculate the
147e83
        string size, like strlen, and issues a memcpy.  For larger strings,
147e83
        source is first aligned to 16 bytes and then tested over a loop that
147e83
        reads 16 bytes am combine the cmpb results for speedup.  Special case is
147e83
        added for page cross reads.
147e83
    
147e83
        It shows 30%-60% improvement over the optimized POWER7 one that uses
147e83
        only aligned accesses.
147e83
    
147e83
        ChangeLog:
147e83
    	2015-01-13  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>
147e83
    
147e83
    	* sysdeps/powerpc/powerpc64/multiarch/Makefile [sysdep_routines]: Add
147e83
    	strcpy-power8 and stpcpy-power8 objects.
147e83
    	* sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
147e83
    	(__libc_ifunc_impl_list): Add __strcpy_power8 and __stpcpy_power8
147e83
    	implementations.
147e83
    	* sysdeps/powerpc/powerpc64/multiarch/stpcpy-power8.S: New file:
147e83
    	multiarch stpcpy implementation for POWER8.
147e83
    	* sysdeps/powerpc/powerpc64/multiarch/strcpy-power8.S: New file;
147e83
    	multiarch strcpy implementation for POWER8.
147e83
    	* sysdeps/powerpc/powerpc64/multiarch/strcpy.c (strcpy): Add
147e83
    	__strcpy_power8 function.
147e83
    	* sysdeps/powerpc/powerpc64/power8/stpcpy.S: New file: optimized
147e83
    	stpcpy for POWER8.
147e83
    	* sysdeps/powerpc/powerpc64/power8/strcpy.S: New file: optimized
147e83
    	strcpy for POWER8.
147e83
    	* NEWS: Update.
147e83
    
147e83
    and the commits it depends on:
147e83
    
147e83
    commit a52374e82b90a6039c720f7b9b7dfa9db24ff4f0
147e83
    Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
147e83
    Date:   Fri Dec 13 14:55:22 2013 -0500
147e83
    
147e83
        PowerPC: multiarch stpcpy for PowerPC64
147e83
    
147e83
        ChangeLog:
147e83
           2013-12-13  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>
147e83
    
147e83
           * sysdeps/powerpc/powerpc64/multiarch/Makefile: Add stpcpy
147e83
           multiarch implementations.
147e83
           * sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
147e83
           (__libc_ifunc_impl_list): Likewise.
147e83
           * sysdeps/powerpc/powerpc64/multiarch/stpcpy-power7.c: New file.
147e83
           * sysdeps/powerpc/powerpc64/multiarch/stpcpy-ppc64.c: New file.
147e83
           * sysdeps/powerpc/powerpc64/multiarch/stpcpy.c : New file:
147e83
           multiarch stpcpy for PPC64.
147e83
    
147e83
    commit 7f5ec11336e46d0449a6b5a8e5a0604c3c78ecbf
147e83
    Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
147e83
    Date:   Fri Dec 13 14:54:41 2013 -0500
147e83
    
147e83
        PowerPC: multiarch strcpy for PowerPC64
147e83
    
147e83
        ChangeLog:
147e83
            2013-12-13  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>
147e83
    
147e83
           * sysdeps/powerpc/powerpc64/multiarch/Makefile: Add strcpy
147e83
           multiarch implementations.
147e83
           * sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
147e83
           (__libc_ifunc_impl_list): Likewise.
147e83
           * sysdeps/powerpc/powerpc64/multiarch/strcpy-power7.c: New file.
147e83
           * sysdeps/powerpc/powerpc64/multiarch/strcpy-ppc64.c: New file.
147e83
           * sysdeps/powerpc/powerpc64/multiarch/strcpy.c : New file:
147e83
           multiarch strcpy for PPC64.
147e83
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
147e83
index 8dceb09..1cdd5d6 100644
147e83
--- a/sysdeps/powerpc/powerpc64/multiarch/Makefile
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile
147e83
@@ -5,6 +5,8 @@ sysdep_routines += memcpy-power7 memcpy-a2 memcpy-power6 memcpy-cell \
147e83
                   memset-ppc64 bzero-power4 bzero-power6 bzero-power7 \
147e83
                   mempcpy-power7 mempcpy-ppc64 memchr-power7 memchr-ppc64 \
147e83
                   memrchr-power7 memrchr-ppc64 rawmemchr-power7 \
147e83
+                  stpcpy-power8 stpcpy-power7 stpcpy-ppc64 \
147e83
+                  strcpy-power8 strcpy-power7 strcpy-ppc64 \
147e83
                   rawmemchr-ppc64 strlen-power7 strlen-ppc64 strnlen-power7 \
147e83
                   strnlen-ppc64 strcasecmp-power7 strcasecmp_l-power7 \
147e83
                   strncase-power7 strncase_l-power7 strncmp-power7 \
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
147e83
index 2d21ce1..e89fd3e 100644
147e83
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
147e83
@@ -34,6 +34,8 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
147e83
   size_t i = 0;
147e83
 
147e83
   unsigned long int hwcap = GLRO(dl_hwcap);
147e83
+  unsigned long int hwcap2 = GLRO(dl_hwcap2);
147e83
+
147e83
   /* hwcap contains only the latest supported ISA, the code checks which is
147e83
      and fills the previous supported ones.  */
147e83
   if (hwcap & PPC_FEATURE_ARCH_2_06)
147e83
@@ -71,6 +73,24 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
147e83
                              __memset_power4)
147e83
              IFUNC_IMPL_ADD (array, i, memset, 1, __memset_ppc))
147e83
 
147e83
+  /* Support sysdeps/powerpc/powerpc64/multiarch/strcpy.c.  */
147e83
+  IFUNC_IMPL (i, name, strcpy,
147e83
+              IFUNC_IMPL_ADD (array, i, strcpy, hwcap2 & PPC_FEATURE2_ARCH_2_07,
147e83
+                              __strcpy_power8)
147e83
+              IFUNC_IMPL_ADD (array, i, strcpy, hwcap & PPC_FEATURE_HAS_VSX,
147e83
+                              __strcpy_power7)
147e83
+              IFUNC_IMPL_ADD (array, i, strcpy, 1,
147e83
+                              __strcpy_ppc))
147e83
+
147e83
+  /* Support sysdeps/powerpc/powerpc64/multiarch/stpcpy.c.  */
147e83
+  IFUNC_IMPL (i, name, stpcpy,
147e83
+              IFUNC_IMPL_ADD (array, i, stpcpy, hwcap2 & PPC_FEATURE2_ARCH_2_07,
147e83
+                              __stpcpy_power8)
147e83
+              IFUNC_IMPL_ADD (array, i, stpcpy, hwcap & PPC_FEATURE_HAS_VSX,
147e83
+                              __stpcpy_power7)
147e83
+              IFUNC_IMPL_ADD (array, i, stpcpy, 1,
147e83
+                              __stpcpy_ppc))
147e83
+
147e83
   /* Support sysdeps/powerpc/powerpc64/multiarch/strlen.c.  */
147e83
   IFUNC_IMPL (i, name, strlen,
147e83
              IFUNC_IMPL_ADD (array, i, strlen, hwcap & PPC_FEATURE_HAS_VSX,
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/stpcpy-power7.S b/sysdeps/powerpc/powerpc64/multiarch/stpcpy-power7.S
147e83
new file mode 100644
147e83
index 0000000..0943611
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/stpcpy-power7.S
147e83
@@ -0,0 +1,40 @@
147e83
+/* Optimized stpcpy implementation for POWER7.
147e83
+   Copyright (C) 2013-2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#include <sysdep.h>
147e83
+
147e83
+#undef EALIGN
147e83
+#define EALIGN(name, alignt, words)				\
147e83
+  .section ".text";						\
147e83
+  ENTRY_2(__stpcpy_power7)					\
147e83
+  .align ALIGNARG(alignt);					\
147e83
+  EALIGN_W_##words;						\
147e83
+  BODY_LABEL(__stpcpy_power7):					\
147e83
+  cfi_startproc;						\
147e83
+  LOCALENTRY(__stpcpy_power7)
147e83
+
147e83
+#undef END
147e83
+#define END(name)						\
147e83
+  cfi_endproc;							\
147e83
+  TRACEBACK(__stpcpy_power7)					\
147e83
+  END_2(__stpcpy_power7)
147e83
+
147e83
+#undef libc_hidden_builtin_def
147e83
+#define libc_hidden_builtin_def(name)
147e83
+
147e83
+#include <sysdeps/powerpc/powerpc64/power7/stpcpy.S>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/stpcpy-power8.S b/sysdeps/powerpc/powerpc64/multiarch/stpcpy-power8.S
147e83
new file mode 100644
147e83
index 0000000..66e6f70
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/stpcpy-power8.S
147e83
@@ -0,0 +1,40 @@
147e83
+/* Optimized stpcpy implementation for POWER8/PPC64.
147e83
+   Copyright (C) 2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#include <sysdep.h>
147e83
+
147e83
+#undef EALIGN
147e83
+#define EALIGN(name, alignt, words)				\
147e83
+  .section ".text";						\
147e83
+  ENTRY_2(__stpcpy_power8)					\
147e83
+  .align ALIGNARG(alignt);					\
147e83
+  EALIGN_W_##words;						\
147e83
+  BODY_LABEL(__stpcpy_power8):					\
147e83
+  cfi_startproc;						\
147e83
+  LOCALENTRY(__stpcpy_power8)
147e83
+
147e83
+#undef END
147e83
+#define END(name)						\
147e83
+  cfi_endproc;							\
147e83
+  TRACEBACK(__stpcpy_power8)					\
147e83
+  END_2(__stpcpy_power8)
147e83
+
147e83
+#undef libc_hidden_builtin_def
147e83
+#define libc_hidden_builtin_def(name)
147e83
+
147e83
+#include <sysdeps/powerpc/powerpc64/power8/stpcpy.S>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/stpcpy-ppc64.S b/sysdeps/powerpc/powerpc64/multiarch/stpcpy-ppc64.S
147e83
new file mode 100644
147e83
index 0000000..ac70c1b
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/stpcpy-ppc64.S
147e83
@@ -0,0 +1,48 @@
147e83
+/* Default stpcpy implementation for PowerPC64.
147e83
+   Copyright (C) 2013-2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#include <sysdep.h>
147e83
+
147e83
+#if defined SHARED && !defined NOT_IN_libc
147e83
+# undef EALIGN
147e83
+# define EALIGN(name, alignt, words)				\
147e83
+  .section ".text";						\
147e83
+  ENTRY_2(__stpcpy_ppc)						\
147e83
+  .align ALIGNARG(alignt);					\
147e83
+  EALIGN_W_##words;						\
147e83
+  BODY_LABEL(__stpcpy_ppc):					\
147e83
+  cfi_startproc;						\
147e83
+  LOCALENTRY(__stpcpy_ppc)
147e83
+
147e83
+# undef END
147e83
+# define END(name)						\
147e83
+  cfi_endproc;							\
147e83
+  TRACEBACK(__stpcpy_ppc)					\
147e83
+  END_2(__stpcpy_ppc)
147e83
+
147e83
+# undef weak_alias
147e83
+# define weak_alias(name, alias)
147e83
+# undef libc_hidden_def
147e83
+# define libc_hidden_def(name)
147e83
+
147e83
+# undef libc_hidden_builtin_def
147e83
+# define libc_hidden_builtin_def(name)				\
147e83
+    .globl __GI___stpcpy; __GI___stpcpy = __stpcpy_ppc
147e83
+#endif
147e83
+
147e83
+#include <sysdeps/powerpc/powerpc64/stpcpy.S>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/stpcpy.c b/sysdeps/powerpc/powerpc64/multiarch/stpcpy.c
147e83
new file mode 100644
147e83
index 0000000..2ab62bf
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/stpcpy.c
147e83
@@ -0,0 +1,35 @@
147e83
+/* Multiple versions of stpcpy. PowerPC64 version.
147e83
+   Copyright (C) 2013-2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#if defined SHARED && !defined NOT_IN_libc
147e83
+# define NO_MEMPCPY_STPCPY_REDIRECT
147e83
+# include <string.h>
147e83
+# include <shlib-compat.h>
147e83
+# include "init-arch.h"
147e83
+
147e83
+extern __typeof (__stpcpy) __stpcpy_ppc attribute_hidden;
147e83
+extern __typeof (__stpcpy) __stpcpy_power7 attribute_hidden;
147e83
+
147e83
+libc_ifunc (__stpcpy,
147e83
+            (hwcap & PPC_FEATURE_HAS_VSX)
147e83
+            ? __stpcpy_power7
147e83
+            : __stpcpy_ppc);
147e83
+
147e83
+weak_alias (__stpcpy, stpcpy)
147e83
+libc_hidden_def (stpcpy)
147e83
+#endif
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcpy-power7.S b/sysdeps/powerpc/powerpc64/multiarch/strcpy-power7.S
147e83
new file mode 100644
147e83
index 0000000..69851bb
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcpy-power7.S
147e83
@@ -0,0 +1,40 @@
147e83
+/* Optimized strcpy implementation for POWER7.
147e83
+   Copyright (C) 2013-2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#include <sysdep.h>
147e83
+
147e83
+#undef EALIGN
147e83
+#define EALIGN(name, alignt, words)				\
147e83
+  .section ".text";						\
147e83
+  ENTRY_2(__strcpy_power7)					\
147e83
+  .align ALIGNARG(alignt);					\
147e83
+  EALIGN_W_##words;						\
147e83
+  BODY_LABEL(__strcpy_power7):					\
147e83
+  cfi_startproc;						\
147e83
+  LOCALENTRY(__strcpy_power7)
147e83
+
147e83
+#undef END
147e83
+#define END(name)						\
147e83
+  cfi_endproc;							\
147e83
+  TRACEBACK(__strcpy_power7)					\
147e83
+  END_2(__strcpy_power7)
147e83
+
147e83
+#undef libc_hidden_builtin_def
147e83
+#define libc_hidden_builtin_def(name)
147e83
+
147e83
+#include <sysdeps/powerpc/powerpc64/power7/strcpy.S>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcpy-power8.S b/sysdeps/powerpc/powerpc64/multiarch/strcpy-power8.S
147e83
new file mode 100644
147e83
index 0000000..64cbc16
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcpy-power8.S
147e83
@@ -0,0 +1,40 @@
147e83
+/* Optimized strcpy implementation for POWER8/PPC64.
147e83
+   Copyright (C) 2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#include <sysdep.h>
147e83
+
147e83
+#undef EALIGN
147e83
+#define EALIGN(name, alignt, words)				\
147e83
+  .section ".text";						\
147e83
+  ENTRY_2(__strcpy_power8)					\
147e83
+  .align ALIGNARG(alignt);					\
147e83
+  EALIGN_W_##words;						\
147e83
+  BODY_LABEL(__strcpy_power8):					\
147e83
+  cfi_startproc;						\
147e83
+  LOCALENTRY(__strcpy_power8)
147e83
+
147e83
+#undef END
147e83
+#define END(name)						\
147e83
+  cfi_endproc;							\
147e83
+  TRACEBACK(__strcpy_power8)					\
147e83
+  END_2(__strcpy_power8)
147e83
+
147e83
+#undef libc_hidden_builtin_def
147e83
+#define libc_hidden_builtin_def(name)
147e83
+
147e83
+#include <sysdeps/powerpc/powerpc64/power8/strcpy.S>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcpy-ppc64.S b/sysdeps/powerpc/powerpc64/multiarch/strcpy-ppc64.S
147e83
new file mode 100644
147e83
index 0000000..e5452b1
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcpy-ppc64.S
147e83
@@ -0,0 +1,43 @@
147e83
+/* Default strcpy implementation for PowerPC64.
147e83
+   Copyright (C) 2013-2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#include <sysdep.h>
147e83
+
147e83
+#if defined SHARED && !defined NOT_IN_libc
147e83
+# undef EALIGN
147e83
+# define EALIGN(name, alignt, words)				\
147e83
+  .section ".text";						\
147e83
+  ENTRY_2(__strcpy_ppc)						\
147e83
+  .align ALIGNARG(alignt);					\
147e83
+  EALIGN_W_##words;						\
147e83
+  BODY_LABEL(__strcpy_ppc):					\
147e83
+  cfi_startproc;						\
147e83
+  LOCALENTRY(__strcpy_ppc)
147e83
+
147e83
+# undef END
147e83
+# define END(name)						\
147e83
+  cfi_endproc;							\
147e83
+  TRACEBACK(__strcpy_ppc)					\
147e83
+  END_2(__strcpy_ppc)
147e83
+
147e83
+# undef libc_hidden_builtin_def
147e83
+# define libc_hidden_builtin_def(name)				\
147e83
+    .globl __GI_strcpy; __GI_strcpy = __strcpy_ppc
147e83
+#endif
147e83
+
147e83
+#include <sysdeps/powerpc/powerpc64/strcpy.S>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strcpy.c b/sysdeps/powerpc/powerpc64/multiarch/strcpy.c
147e83
new file mode 100644
147e83
index 0000000..5a86f26
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/strcpy.c
147e83
@@ -0,0 +1,34 @@
147e83
+/* Multiple versions of strcpy. PowerPC64 version.
147e83
+   Copyright (C) 2013-2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#if defined SHARED && !defined NOT_IN_libc
147e83
+# include <string.h>
147e83
+# include <shlib-compat.h>
147e83
+# include "init-arch.h"
147e83
+
147e83
+extern __typeof (strcpy) __strcpy_ppc attribute_hidden;
147e83
+extern __typeof (strcpy) __strcpy_power7 attribute_hidden;
147e83
+extern __typeof (strcpy) __strcpy_power8 attribute_hidden;
147e83
+
147e83
+libc_ifunc (strcpy,
147e83
+            (hwcap2 & PPC_FEATURE2_ARCH_2_07)
147e83
+            ? __strcpy_power8 :
147e83
+              (hwcap & PPC_FEATURE_HAS_VSX)
147e83
+              ? __strcpy_power7
147e83
+            : __strcpy_ppc);
147e83
+#endif
147e83
diff --git a/sysdeps/powerpc/powerpc64/power8/stpcpy.S b/sysdeps/powerpc/powerpc64/power8/stpcpy.S
147e83
new file mode 100644
147e83
index 0000000..bf72065
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/power8/stpcpy.S
147e83
@@ -0,0 +1,24 @@
147e83
+/* Optimized stpcpy implementation for PowerPC64/POWER8.
147e83
+   Copyright (C) 2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#define USE_AS_STPCPY
147e83
+#include <sysdeps/powerpc/powerpc64/power8/strcpy.S>
147e83
+
147e83
+weak_alias (__stpcpy, stpcpy)
147e83
+libc_hidden_def (__stpcpy)
147e83
+libc_hidden_builtin_def (stpcpy)
147e83
diff --git a/sysdeps/powerpc/powerpc64/power8/strcpy.S b/sysdeps/powerpc/powerpc64/power8/strcpy.S
147e83
new file mode 100644
147e83
index 0000000..d3e9a10
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/power8/strcpy.S
147e83
@@ -0,0 +1,262 @@
147e83
+/* Optimized strcpy/stpcpy implementation for PowerPC64/POWER8.
147e83
+   Copyright (C) 2015 Free Software Foundation, Inc.
147e83
+   This file is part of the GNU C Library.
147e83
+
147e83
+   The GNU C Library is free software; you can redistribute it and/or
147e83
+   modify it under the terms of the GNU Lesser General Public
147e83
+   License as published by the Free Software Foundation; either
147e83
+   version 2.1 of the License, or (at your option) any later version.
147e83
+
147e83
+   The GNU C Library is distributed in the hope that it will be useful,
147e83
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
147e83
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
147e83
+   Lesser General Public License for more details.
147e83
+
147e83
+   You should have received a copy of the GNU Lesser General Public
147e83
+   License along with the GNU C Library; if not, see
147e83
+   <http://www.gnu.org/licenses/>.  */
147e83
+
147e83
+#include <sysdep.h>
147e83
+
147e83
+#ifdef USE_AS_STPCPY
147e83
+# define FUNC_NAME __stpcpy
147e83
+#else
147e83
+# define FUNC_NAME strcpy
147e83
+#endif
147e83
+
147e83
+/* Implements the function
147e83
+
147e83
+   char * [r3] strcpy (char *dest [r3], const char *src [r4])
147e83
+
147e83
+   or
147e83
+
147e83
+   char * [r3] stpcpy (char *dest [r3], const char *src [r4])
147e83
+
147e83
+   if USE_AS_STPCPY is defined.
147e83
+
147e83
+   The implementation uses unaligned doubleword access to avoid specialized
147e83
+   code paths depending of data alignment.  Although recent powerpc64 uses
147e83
+   64K as default, the page cross handling assumes minimum page size of
147e83
+   4k.  */
147e83
+
147e83
+	.machine  power7
147e83
+EALIGN (FUNC_NAME, 4, 0)
147e83
+        li      r0,0          /* Doubleword with null chars to use
147e83
+                                 with cmpb.  */
147e83
+
147e83
+	/* Check if the [src]+15 will cross a 4K page by checking if the bit
147e83
+	   indicating the page size changes.  Basically:
147e83
+
147e83
+	   uint64_t srcin = (uint64_t)src;
147e83
+	   uint64_t ob = srcin & 4096UL;
147e83
+	   uint64_t nb = (srcin+15UL) & 4096UL;
147e83
+	   if (ob ^ nb)
147e83
+	     goto pagecross;  */
147e83
+
147e83
+	addi	r9,r4,15
147e83
+	xor	r9,r9,r4
147e83
+	rlwinm.	r9,r9,0,19,19
147e83
+	bne	L(pagecross)
147e83
+
147e83
+	/* For short string (less than 16 bytes), just calculate its size as
147e83
+	   strlen and issues a memcpy if null is found.  */
147e83
+	mr	r7,r4
147e83
+        ld      r12,0(r7)     /* Load doubleword from memory.  */
147e83
+        cmpb    r10,r12,r0    /* Check for null bytes in DWORD1.  */
147e83
+        cmpdi   cr7,r10,0     /* If r10 == 0, no null's have been found.  */
147e83
+        bne     cr7,L(done)
147e83
+
147e83
+        ldu     r8,8(r7)
147e83
+        cmpb    r10,r8,r0
147e83
+        cmpdi   cr7,r10,0
147e83
+        bne     cr7,L(done)
147e83
+
147e83
+	b	L(loop_before)
147e83
+
147e83
+	.align	4
147e83
+L(pagecross):
147e83
+	clrrdi  r7,r4,3       /* Align the address to doubleword boundary.  */
147e83
+	rlwinm  r6,r4,3,26,28 /* Calculate padding.  */
147e83
+	li      r5,-1         /* MASK = 0xffffffffffffffff.  */
147e83
+        ld      r12,0(r7)     /* Load doubleword from memory.  */
147e83
+#ifdef __LITTLE_ENDIAN__
147e83
+        sld     r5,r5,r6
147e83
+#else
147e83
+        srd     r5,r5,r6      /* MASK = MASK >> padding.  */
147e83
+#endif
147e83
+        orc     r9,r12,r5     /* Mask bits that are not part of the string.  */
147e83
+        cmpb    r10,r9,r0     /* Check for null bytes in DWORD1.  */
147e83
+        cmpdi   cr7,r10,0     /* If r10 == 0, no null's have been found.  */
147e83
+        bne     cr7,L(done)
147e83
+
147e83
+        ldu     r6,8(r7)
147e83
+        cmpb    r10,r6,r0
147e83
+        cmpdi   cr7,r10,0
147e83
+        bne     cr7,L(done)
147e83
+
147e83
+        ld      r12,0(r7)
147e83
+        cmpb    r10,r12,r0
147e83
+        cmpdi   cr7,r10,0
147e83
+        bne     cr7,L(done)
147e83
+
147e83
+        ldu     r6,8(r7)
147e83
+        cmpb    r10,r6,r0
147e83
+        cmpdi   cr7,r10,0
147e83
+        bne     cr7,L(done)
147e83
+
147e83
+	/* We checked for 24 - x bytes, with x being the source alignment
147e83
+	   (0 <= x <= 16), and no zero has been found.  Start the loop
147e83
+	   copy with doubleword aligned address.  */
147e83
+	mr	r7,r4
147e83
+	ld	r12, 0(r7)
147e83
+	ldu	r8, 8(r7)
147e83
+
147e83
+L(loop_before):
147e83
+	/* Save the two doublewords readed from source and align the source
147e83
+	   to 16 bytes for the loop.  */
147e83
+	mr	r11,r3
147e83
+	std	r12,0(r11)
147e83
+	std	r8,8(r11)
147e83
+	addi	r11,r11,16
147e83
+	rldicl	r9,r4,0,60
147e83
+	subf	r7,r9,r7
147e83
+	subf	r11,r9,r11
147e83
+	b	L(loop_start)
147e83
+
147e83
+        .align  5
147e83
+L(loop):
147e83
+        std     r12, 0(r11)
147e83
+        std     r6, 8(r11)
147e83
+	addi	r11,r11,16
147e83
+L(loop_start):
147e83
+        /* Load two doublewords, compare and merge in a
147e83
+           single register for speed.  This is an attempt
147e83
+           to speed up the null-checking process for bigger strings.  */
147e83
+
147e83
+        ld      r12, 8(r7)
147e83
+        ldu     r6, 16(r7)
147e83
+        cmpb    r10,r12,r0
147e83
+        cmpb    r9,r6,r0
147e83
+        or      r8,r9,r10     /* Merge everything in one doubleword.  */
147e83
+        cmpdi   cr7,r8,0
147e83
+        beq     cr7,L(loop)
147e83
+
147e83
+
147e83
+        /* OK, one (or both) of the doublewords contains a null byte.  Check
147e83
+           the first doubleword and decrement the address in case the first
147e83
+           doubleword really contains a null byte.  */
147e83
+
147e83
+	addi	r4,r7,-8
147e83
+        cmpdi   cr6,r10,0
147e83
+        addi    r7,r7,-8
147e83
+        bne     cr6,L(done2)
147e83
+
147e83
+        /* The null byte must be in the second doubleword.  Adjust the address
147e83
+           again and move the result of cmpb to r10 so we can calculate the
147e83
+           length.  */
147e83
+
147e83
+        mr      r10,r9
147e83
+        addi    r7,r7,8
147e83
+	b	L(done2)
147e83
+
147e83
+        /* r10 has the output of the cmpb instruction, that is, it contains
147e83
+           0xff in the same position as the null byte in the original
147e83
+           doubleword from the string.  Use that to calculate the length.  */
147e83
+L(done):
147e83
+	mr	r11,r3
147e83
+L(done2):
147e83
+#ifdef __LITTLE_ENDIAN__
147e83
+        addi    r9, r10, -1   /* Form a mask from trailing zeros.  */
147e83
+        andc    r9, r9, r10
147e83
+        popcntd r6, r9        /* Count the bits in the mask.  */
147e83
+#else
147e83
+        cntlzd  r6,r10        /* Count leading zeros before the match.  */
147e83
+#endif
147e83
+        subf    r5,r4,r7
147e83
+        srdi    r6,r6,3       /* Convert leading/trailing zeros to bytes.  */
147e83
+        add     r8,r5,r6      /* Compute final length.  */
147e83
+#ifdef USE_AS_STPCPY
147e83
+	/* stpcpy returns the dest address plus the size not counting the
147e83
+	   final '\0'.  */
147e83
+	add	r3,r11,r8
147e83
+#endif
147e83
+	addi	r8,r8,1       /* Final '/0'.  */
147e83
+
147e83
+	cmpldi	cr6,r8,8
147e83
+	mtocrf	0x01,r8
147e83
+	ble	cr6,L(copy_LE_8)
147e83
+
147e83
+	cmpldi	cr1,r8,16
147e83
+	blt	cr1,8f
147e83
+
147e83
+	/* Handle copies of 0~31 bytes.  */
147e83
+	.align	4
147e83
+L(copy_LT_32):
147e83
+	/* At least 6 bytes to go.  */
147e83
+	blt	cr1,8f
147e83
+
147e83
+	/* Copy 16 bytes.  */
147e83
+	ld	r6,0(r4)
147e83
+	ld	r8,8(r4)
147e83
+	addi	r4,r4,16
147e83
+	std	r6,0(r11)
147e83
+	std	r8,8(r11)
147e83
+	addi	r11,r11,16
147e83
+8:	/* Copy 8 bytes.  */
147e83
+	bf	28,L(tail4)
147e83
+	ld	r6,0(r4)
147e83
+	addi	r4,r4,8
147e83
+	std	r6,0(r11)
147e83
+	addi	r11,r11,8
147e83
+
147e83
+	.align	4
147e83
+/* Copies 4~7 bytes.  */
147e83
+L(tail4):
147e83
+	bf	29,L(tail2)
147e83
+	lwz	r6,0(r4)
147e83
+	stw	r6,0(r11)
147e83
+	bf	30,L(tail5)
147e83
+	lhz	r7,4(r4)
147e83
+	sth	r7,4(r11)
147e83
+	bflr	31
147e83
+	lbz	r8,6(r4)
147e83
+	stb	r8,6(r11)
147e83
+	blr
147e83
+
147e83
+	.align	4
147e83
+/* Copies 2~3 bytes.  */
147e83
+L(tail2):
147e83
+	bf	30,1f
147e83
+	lhz	r6,0(r4)
147e83
+	sth	r6,0(r11)
147e83
+	bflr	31
147e83
+	lbz	r7,2(r4)
147e83
+	stb	r7,2(r11)
147e83
+	blr
147e83
+
147e83
+	.align	4
147e83
+L(tail5):
147e83
+	bf	31,1f
147e83
+	lbz	r6,4(r4)
147e83
+	stb	r6,4(r11)
147e83
+	blr
147e83
+
147e83
+	.align	4
147e83
+1:
147e83
+	bflr	31
147e83
+	lbz	r6,0(r4)
147e83
+	stb	r6,0(r11)
147e83
+	blr
147e83
+
147e83
+/* Handles copies of 0~8 bytes.  */
147e83
+	.align	4
147e83
+L(copy_LE_8):
147e83
+	bne	cr6,L(tail4)
147e83
+	ld	r6,0(r4)
147e83
+	std	r6,0(r11)
147e83
+	blr
147e83
+END (FUNC_NAME)
147e83
+
147e83
+#ifndef USE_AS_STPCPY
147e83
+libc_hidden_builtin_def (strcpy)
147e83
+#endif