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