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