Blame SOURCES/glibc-rh1240351-8.patch

147e83
    Backport of:
147e83
    
147e83
    commit f06a4faf8a2b4d046eb40e94b47948cc47d79902
147e83
    Author: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
147e83
    Date:   Wed Dec 31 11:47:41 2014 -0500
147e83
    
147e83
        powerpc: Optimized st{r,p}ncpy for POWER8/PPC64
147e83
    
147e83
        This patch adds an optimized POWER8 st{r,p}ncpy using unaligned accesses.
147e83
        It shows 10%-80% improvement over the optimized POWER7 one that uses
147e83
        only aligned accesses, specially on unaligned inputs.
147e83
    
147e83
        The algorithm first read and check 16 bytes (if inputs do not cross a 4K
147e83
        page size).  The it realign source to 16-bytes and issue a 16 bytes read
147e83
        and compare loop to speedup null byte checks for large strings.  Also,
147e83
        different from POWER7 optimization, the null pad is done inline in the
147e83
        implementation using possible unaligned accesses, instead of realying on
147e83
        a memset call.  Special case is added for page cross reads.
147e83
    
147e83
        ChangeLog:
147e83
    	2015-01-13  Adhemerval Zanella  <azanella@linux.vnet.ibm.com>
147e83
    
147e83
    	* sysdeps/powerpc/powerpc64/multiarch/Makefile [sysdep_routines]:
147e83
    	Add strncpy-power8 and stpncpy-power8 objects.
147e83
    	* sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
147e83
    	(__libc_ifunc_impl_list): Add __strncpy_power8 and stpncpy_power8
147e83
    	implementations.
147e83
    	* sysdeps/powerpc/powerpc64/multiarch/stpncpy-power8.S: New file.
147e83
    	* sysdeps/powerpc/powerpc64/multiarch/stpncpy.c (__stpncpy): Add
147e83
    	__stpncpy_power8 implementation.
147e83
    	* sysdeps/powerpc/powerpc64/multiarch/strncpy-power8.S: New file.
147e83
    	* sysdeps/powerpc/powerpc64/multiarch/strncpy.c (strncpy): Add
147e83
    	__strncpy_power8 implementation.
147e83
    	* sysdeps/powerpc/powerpc64/power8/stpncpy.S: New file.
147e83
    	* sysdeps/powerpc/powerpc64/power8/strncpy.S: New file.
147e83
    	* NEWS: Update.
147e83
    
147e83
    and its dependency:
147e83
    
147e83
    commit f360f94a05570045be615649e9a411cefba2e210
147e83
    Author: Vidya Ranganathan <vidya@linux.vnet.ibm.com>
147e83
    Date:   Mon May 5 19:10:45 2014 -0500
147e83
    
147e83
        PowerPC: strncpy/stpncpy optimization for PPC64/POWER7
147e83
    
147e83
        The optimization is achieved by following techniques:
147e83
          > data alignment [gain from aligned memory access on read/write]
147e83
          > POWER7 gains performance with loop unrolling/unwinding
147e83
            [gain by reduction of branch penalty].
147e83
          > zero padding done by calling optimized memset
147e83
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
147e83
index 74ae710..ef39917 100644
147e83
--- a/sysdeps/powerpc/powerpc64/multiarch/Makefile
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile
147e83
@@ -8,6 +8,8 @@ sysdep_routines += memcpy-power7 memcpy-a2 memcpy-power6 memcpy-cell \
147e83
                   stpcpy-power8 stpcpy-power7 stpcpy-ppc64 \
147e83
                   strcat-power8 strcat-power7 strcat-ppc64 \
147e83
                   strcpy-power8 strcpy-power7 strcpy-ppc64 \
147e83
+                  stpncpy-power8 stpncpy-power7 stpncpy-ppc64 \
147e83
+                  strncpy-power8 strncpy-power7 strncpy-ppc64 
147e83
                   strncat-power7 \
147e83
                   rawmemchr-ppc64 strlen-power7 strlen-ppc64 strnlen-power7 \
147e83
                   strnlen-ppc64 strcasecmp-power7 strcasecmp_l-power7 \
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
147e83
index 4e5bb17..23bf5dc 100644
147e83
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
147e83
@@ -255,5 +255,27 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
147e83
              IFUNC_IMPL_ADD (array, i, wcscpy, 1,
147e83
                              __wcscpy_ppc))
147e83
 
147e83
+  /* Support sysdeps/powerpc/powerpc64/multiarch/strncpy.c.  */
147e83
+  IFUNC_IMPL (i, name, strncpy,
147e83
+	      IFUNC_IMPL_ADD (array, i, strncpy,
147e83
+			      hwcap2 & PPC_FEATURE2_ARCH_2_07,
147e83
+			      __strncpy_power8)
147e83
+	      IFUNC_IMPL_ADD (array, i, strncpy,
147e83
+			      hwcap & PPC_FEATURE_HAS_VSX,
147e83
+			      __strncpy_power7)
147e83
+	      IFUNC_IMPL_ADD (array, i, strncpy, 1,
147e83
+			     __strncpy_ppc))
147e83
+
147e83
+  /* Support sysdeps/powerpc/powerpc64/multiarch/stpncpy.c.  */
147e83
+  IFUNC_IMPL (i, name, stpncpy,
147e83
+	      IFUNC_IMPL_ADD (array, i, stpncpy,
147e83
+			      hwcap2 & PPC_FEATURE2_ARCH_2_07,
147e83
+			      __stpncpy_power8)
147e83
+	      IFUNC_IMPL_ADD (array, i, stpncpy,
147e83
+			      hwcap & PPC_FEATURE_HAS_VSX,
147e83
+			      __stpncpy_power7)
147e83
+	      IFUNC_IMPL_ADD (array, i, stpncpy, 1,
147e83
+			     __stpncpy_ppc))
147e83
+
147e83
   return i;
147e83
 }
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/stpncpy-power7.S b/sysdeps/powerpc/powerpc64/multiarch/stpncpy-power7.S
147e83
new file mode 100644
147e83
index 0000000..e29674f
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/stpncpy-power7.S
147e83
@@ -0,0 +1,44 @@
147e83
+/* Optimized stpncpy implementation for POWER7.
147e83
+   Copyright (C) 2014 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
+#define USE_AS_STPNCPY
147e83
+
147e83
+#undef EALIGN
147e83
+#define EALIGN(name, alignt, words)				\
147e83
+  .section ".text";						\
147e83
+  ENTRY_2(__stpncpy_power7)					\
147e83
+  .align ALIGNARG(alignt);					\
147e83
+  EALIGN_W_##words;						\
147e83
+  BODY_LABEL(__stpncpy_power7):					\
147e83
+  cfi_startproc;						\
147e83
+  LOCALENTRY(__stpncpy_power7)
147e83
+
147e83
+#undef END
147e83
+#define END(name)						\
147e83
+  cfi_endproc;							\
147e83
+  TRACEBACK(__stpncpy_power7)					\
147e83
+  END_2(__stpncpy_power7)
147e83
+
147e83
+#undef libc_hidden_builtin_def
147e83
+#define libc_hidden_builtin_def(name)
147e83
+
147e83
+#define MEMSET __memset_power7
147e83
+
147e83
+#include <sysdeps/powerpc/powerpc64/power7/stpncpy.S>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/stpncpy-power8.S b/sysdeps/powerpc/powerpc64/multiarch/stpncpy-power8.S
147e83
new file mode 100644
147e83
index 0000000..d5d835d
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/stpncpy-power8.S
147e83
@@ -0,0 +1,39 @@
147e83
+/* Optimized stpncpy implementation for 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
+#define USE_AS_STPNCPY
147e83
+
147e83
+#undef EALIGN
147e83
+#define EALIGN(name, alignt, words)				\
147e83
+  .section ".text";						\
147e83
+  ENTRY_2(__stpncpy_power8)					\
147e83
+  .align ALIGNARG(alignt);					\
147e83
+  EALIGN_W_##words;						\
147e83
+  BODY_LABEL(__stpncpy_power8):					\
147e83
+  cfi_startproc;						\
147e83
+  LOCALENTRY(__stpncpy_power8)
147e83
+
147e83
+#undef END
147e83
+#define END(name)						\
147e83
+  cfi_endproc;							\
147e83
+  TRACEBACK(__stpncpy_power8)					\
147e83
+  END_2(__stpncpy_power8)
147e83
+
147e83
+#include <sysdeps/powerpc/powerpc64/power8/stpncpy.S>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/stpncpy-ppc64.c b/sysdeps/powerpc/powerpc64/multiarch/stpncpy-ppc64.c
147e83
new file mode 100644
147e83
index 0000000..74f47a7
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/stpncpy-ppc64.c
147e83
@@ -0,0 +1,26 @@
147e83
+/* Default stpncpy implementation for PowerPC64.
147e83
+   Copyright (C) 2014 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 STPNCPY __stpncpy_ppc
147e83
+#ifdef SHARED
147e83
+#undef libc_hidden_def
147e83
+#define libc_hidden_def(name) \
147e83
+  __hidden_ver1 (__stpncpy_ppc, __GI___stpncpy, __stpncpy_ppc);
147e83
+#endif
147e83
+
147e83
+#include <string/stpncpy.c>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/stpncpy.c b/sysdeps/powerpc/powerpc64/multiarch/stpncpy.c
147e83
new file mode 100644
147e83
index 0000000..3ee50e5
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/stpncpy.c
147e83
@@ -0,0 +1,36 @@
147e83
+/* Multiple versions of stpncpy. PowerPC64 version.
147e83
+   Copyright (C) 2014 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
+#ifndef NOT_IN_libc
147e83
+# include <string.h>
147e83
+# include <shlib-compat.h>
147e83
+# include "init-arch.h"
147e83
+
147e83
+extern __typeof (__stpncpy) __stpncpy_ppc attribute_hidden;
147e83
+extern __typeof (__stpncpy) __stpncpy_power7 attribute_hidden;
147e83
+extern __typeof (__stpncpy) __stpncpy_power8 attribute_hidden;
147e83
+
147e83
+libc_ifunc (__stpncpy,
147e83
+            (hwcap2 & PPC_FEATURE2_ARCH_2_07)
147e83
+            ? __stpncpy_power8 :
147e83
+              (hwcap & PPC_FEATURE_HAS_VSX)
147e83
+              ? __stpncpy_power7
147e83
+            : __stpncpy_ppc);
147e83
+
147e83
+weak_alias (__stpncpy, stpncpy)
147e83
+#endif
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strncpy-power7.S b/sysdeps/powerpc/powerpc64/multiarch/strncpy-power7.S
147e83
new file mode 100644
147e83
index 0000000..be349f9
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/strncpy-power7.S
147e83
@@ -0,0 +1,42 @@
147e83
+/* Optimized strncpy implementation for POWER7.
147e83
+   Copyright (C) 2014 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(__strncpy_power7)					\
147e83
+  .align ALIGNARG(alignt);					\
147e83
+  EALIGN_W_##words;						\
147e83
+  BODY_LABEL(__strncpy_power7):					\
147e83
+  cfi_startproc;						\
147e83
+  LOCALENTRY(__strncpy_power7)
147e83
+
147e83
+#undef END
147e83
+#define END(name)						\
147e83
+  cfi_endproc;							\
147e83
+  TRACEBACK(__strncpy_power7)					\
147e83
+  END_2(__strncpy_power7)
147e83
+
147e83
+#undef libc_hidden_builtin_def
147e83
+#define libc_hidden_builtin_def(name)
147e83
+
147e83
+#define MEMSET __memset_power7
147e83
+
147e83
+#include <sysdeps/powerpc/powerpc64/power7/strncpy.S>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strncpy-power8.S b/sysdeps/powerpc/powerpc64/multiarch/strncpy-power8.S
147e83
new file mode 100644
147e83
index 0000000..ed906a4
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/strncpy-power8.S
147e83
@@ -0,0 +1,40 @@
147e83
+/* Optimized strncpy implementation for 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
+#undef EALIGN
147e83
+#define EALIGN(name, alignt, words)				\
147e83
+  .section ".text";						\
147e83
+  ENTRY_2(__strncpy_power8)					\
147e83
+  .align ALIGNARG(alignt);					\
147e83
+  EALIGN_W_##words;						\
147e83
+  BODY_LABEL(__strncpy_power8):					\
147e83
+  cfi_startproc;						\
147e83
+  LOCALENTRY(__strncpy_power8)
147e83
+
147e83
+#undef END
147e83
+#define END(name)						\
147e83
+  cfi_endproc;							\
147e83
+  TRACEBACK(__strncpy_power8)					\
147e83
+  END_2(__strncpy_power8)
147e83
+
147e83
+#undef libc_hidden_builtin_def
147e83
+#define libc_hidden_builtin_def(name)
147e83
+
147e83
+#include <sysdeps/powerpc/powerpc64/power8/strncpy.S>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strncpy-ppc64.c b/sysdeps/powerpc/powerpc64/multiarch/strncpy-ppc64.c
147e83
new file mode 100644
147e83
index 0000000..e3111d2
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/strncpy-ppc64.c
147e83
@@ -0,0 +1,33 @@
147e83
+/* Copyright (C) 2014 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 <string.h>
147e83
+
147e83
+#define STRNCPY __strncpy_ppc
147e83
+#undef weak_alias
147e83
+#define weak_alias(name, aliasname) \
147e83
+  extern __typeof (__strncpy_ppc) aliasname \
147e83
+    __attribute__ ((weak, alias ("__strncpy_ppc")));
147e83
+#if !defined(NOT_IN_libc) && defined(SHARED)
147e83
+# undef libc_hidden_builtin_def
147e83
+# define libc_hidden_builtin_def(name) \
147e83
+  __hidden_ver1(__strncpy_ppc, __GI_strncpy, __strncpy_ppc);
147e83
+#endif
147e83
+
147e83
+extern __typeof (strncpy) __strncpy_ppc attribute_hidden;
147e83
+
147e83
+#include <string/strncpy.c>
147e83
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strncpy.c b/sysdeps/powerpc/powerpc64/multiarch/strncpy.c
147e83
new file mode 100644
147e83
index 0000000..19927bc
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/multiarch/strncpy.c
147e83
@@ -0,0 +1,38 @@
147e83
+/* Multiple versions of strncpy.
147e83
+   Copyright (C) 2014 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 multiple versions only for definition in libc. */
147e83
+#ifndef NOT_IN_libc
147e83
+# include <string.h>
147e83
+# include <shlib-compat.h>
147e83
+# include "init-arch.h"
147e83
+
147e83
+extern __typeof (strncpy) __strncpy_ppc attribute_hidden;
147e83
+extern __typeof (strncpy) __strncpy_power7 attribute_hidden;
147e83
+extern __typeof (strncpy) __strncpy_power8 attribute_hidden;
147e83
+
147e83
+/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
147e83
+ ifunc symbol properly. */
147e83
+libc_ifunc (strncpy,
147e83
+            (hwcap2 & PPC_FEATURE2_ARCH_2_07)
147e83
+            ? __strncpy_power8 :
147e83
+              (hwcap & PPC_FEATURE_HAS_VSX)
147e83
+              ? __strncpy_power7
147e83
+            : __strncpy_ppc);
147e83
+
147e83
+#endif
147e83
diff --git a/sysdeps/powerpc/powerpc64/power7/stpncpy.S b/sysdeps/powerpc/powerpc64/power7/stpncpy.S
147e83
new file mode 100644
147e83
index 0000000..a539093
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/power7/stpncpy.S
147e83
@@ -0,0 +1,24 @@
147e83
+/* Optimized stpncpy implementation for PowerPC64/POWER7.
147e83
+   Copyright (C) 2014 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_STPNCPY
147e83
+#include <sysdeps/powerpc/powerpc64/power7/strncpy.S>
147e83
+
147e83
+weak_alias (__stpncpy, stpncpy)
147e83
+libc_hidden_def (__stpncpy)
147e83
+libc_hidden_builtin_def (stpncpy)
147e83
diff --git a/sysdeps/powerpc/powerpc64/power7/strncpy.S b/sysdeps/powerpc/powerpc64/power7/strncpy.S
147e83
new file mode 100644
147e83
index 0000000..51860df
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/power7/strncpy.S
147e83
@@ -0,0 +1,338 @@
147e83
+/* Copyright (C) 2014 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
+/* Implements the functions
147e83
+
147e83
+   char * [r3] strncpy (char *dst [r3], const char *src [r4], size_t n [r5])
147e83
+
147e83
+   AND
147e83
+
147e83
+   char * [r3] stpncpy (char *dst [r3], const char *src [r4], size_t n [r5])
147e83
+
147e83
+   The algorithm is as follows:
147e83
+   > if src and dest are 8 byte aligned, perform double word copy
147e83
+     else
147e83
+   > copy byte by byte on unaligned addresses.
147e83
+
147e83
+   The aligned comparison are made using cmpb instructions.  */
147e83
+
147e83
+/* The focus on optimization for performance improvements are as follows:
147e83
+   1. data alignment [gain from aligned memory access on read/write]
147e83
+   2. POWER7 gains performance with loop unrolling/unwinding
147e83
+      [gain by reduction of branch penalty].
147e83
+   3. The final pad with null bytes is done by calling an optimized
147e83
+      memset.  */
147e83
+
147e83
+#ifdef USE_AS_STPNCPY
147e83
+# define FUNC_NAME __stpncpy
147e83
+#else
147e83
+# define FUNC_NAME strncpy
147e83
+#endif
147e83
+
147e83
+#define		FRAMESIZE	(FRAME_MIN_SIZE+32)
147e83
+
147e83
+#ifndef MEMSET
147e83
+/* For builds with no IFUNC support, local calls should be made to internal
147e83
+   GLIBC symbol (created by libc_hidden_builtin_def).  */
147e83
+# ifdef SHARED
147e83
+#  define MEMSET   __GI_memset
147e83
+# else
147e83
+#  define MEMSET   memset
147e83
+# endif
147e83
+#endif
147e83
+
147e83
+	.machine  power7
147e83
+EALIGN(FUNC_NAME, 4, 0)
147e83
+	CALL_MCOUNT 3
147e83
+
147e83
+	mflr r0			/* load link register LR to r0  */
147e83
+	or r10, r3, r4		/* to verify source and destination  */
147e83
+	rldicl. r8, r10, 0, 61	/* is double word aligned .. ?  */
147e83
+
147e83
+	std r19, -8(r1)		/* save callers register , r19  */
147e83
+	std r18, -16(r1)	/* save callers register , r18  */
147e83
+	std r0, 16(r1)		/* store the link register  */
147e83
+	stdu r1, -FRAMESIZE(r1)	/* create the stack frame  */
147e83
+
147e83
+	mr r9, r3		/* save r3 into r9 for use  */
147e83
+	mr r18, r3		/* save r3 for retCode of strncpy  */
147e83
+	bne 0, L(byte_by_byte)
147e83
+
147e83
+
147e83
+	srdi r11, r5, 3		/* compute count for CTR ; count = n/8  */
147e83
+	cmpldi cr7, r11, 3	/* if count > 4 ; perform unrolling 4 times  */
147e83
+	ble 7, L(update1)
147e83
+
147e83
+	ld r10, 0(r4)		/* load doubleWord from src  */
147e83
+	cmpb r8, r10, r8	/* compare src with NULL ,we read just now  */
147e83
+	cmpdi cr7, r8, 0	/* if cmpb returned NULL ; we continue  */
147e83
+	bne cr7, L(update3)
147e83
+
147e83
+	std r10, 0(r3)		/* copy doubleword at offset=0  */
147e83
+	ld r10, 8(r4)		/* load next doubleword from offset=8  */
147e83
+	cmpb r8, r10, r8	/* compare src with NULL , we read just now  */
147e83
+	cmpdi cr7, r8, 0	/* if cmpb returned NULL ; we continue  */
147e83
+	bne 7,L(HopBy8)
147e83
+
147e83
+	addi r8, r11, -4
147e83
+	mr r7, r3
147e83
+	srdi r8, r8, 2
147e83
+	mr r6, r4
147e83
+	addi r8, r8, 1
147e83
+	li r12, 0
147e83
+	mtctr r8
147e83
+	b L(dwordCopy)
147e83
+
147e83
+	.p2align 4
147e83
+L(dWordUnroll):
147e83
+	std r8, 16(r9)
147e83
+	ld r8, 24(r4)		/* load dword,perform loop unrolling again  */
147e83
+	cmpb r10, r8, r10
147e83
+	cmpdi cr7, r10, 0
147e83
+	bne cr7, L(HopBy24)
147e83
+
147e83
+	std r8, 24(r7)		/* copy dword at offset=24  */
147e83
+	addi r9, r9, 32
147e83
+	addi r4, r4, 32
147e83
+	bdz  L(leftDwords)	/* continue with loop on counter  */
147e83
+
147e83
+	ld r3, 32(r6)
147e83
+	cmpb r8, r3, r10
147e83
+	cmpdi cr7, r8, 0
147e83
+	bne cr7, L(update2)
147e83
+
147e83
+	std r3, 32(r7)
147e83
+	ld r10, 40(r6)
147e83
+	cmpb r8, r10, r8
147e83
+	cmpdi cr7, r8, 0
147e83
+	bne cr7, L(HopBy40)
147e83
+
147e83
+	mr r6, r4		/* update values  */
147e83
+	mr r7, r9
147e83
+	mr r11, r0
147e83
+	mr r5, r19
147e83
+
147e83
+L(dwordCopy):
147e83
+	std r10, 8(r9)		/* copy dword at offset=8  */
147e83
+	addi r19, r5, -32
147e83
+	addi r0, r11, -4
147e83
+	ld r8, 16(r4)
147e83
+	cmpb r10, r8, r12
147e83
+	cmpdi cr7, r10, 0
147e83
+	beq cr7, L(dWordUnroll)
147e83
+
147e83
+	addi r9, r9, 16		/* increment dst by 16  */
147e83
+	addi r4, r4, 16		/* increment src by 16  */
147e83
+	addi r5, r5, -16	/* decrement length 'n' by 16  */
147e83
+	addi r0, r11, -2	/* decrement loop counter  */
147e83
+
147e83
+L(dWordUnrollOFF):
147e83
+	ld r10, 0(r4)		/* load first dword  */
147e83
+	li r8, 0		/* load mask  */
147e83
+	cmpb r8, r10, r8
147e83
+	cmpdi cr7, r8, 0
147e83
+	bne cr7, L(byte_by_byte)
147e83
+	mtctr r0
147e83
+	li r7, 0
147e83
+	b L(CopyDword)
147e83
+
147e83
+	.p2align 4
147e83
+L(loadDWordandCompare):
147e83
+	ld r10, 0(r4)
147e83
+	cmpb r8, r10, r7
147e83
+	cmpdi cr7, r8, 0
147e83
+	bne cr7, L(byte_by_byte)
147e83
+
147e83
+L(CopyDword):
147e83
+	addi r9, r9, 8
147e83
+	std r10, -8(r9)
147e83
+	addi r4, r4, 8
147e83
+	addi r5, r5, -8
147e83
+	bdnz L(loadDWordandCompare)
147e83
+
147e83
+L(byte_by_byte):
147e83
+	cmpldi cr7, r5, 3
147e83
+	ble cr7, L(verifyByte)
147e83
+	srdi r10, r5, 2
147e83
+	mr r19, r9
147e83
+	mtctr r10
147e83
+	b L(firstByteUnroll)
147e83
+
147e83
+	.p2align 4
147e83
+L(bytes_unroll):
147e83
+	lbz r10, 1(r4)		/* load byte from src  */
147e83
+	cmpdi cr7, r10, 0	/* compare for NULL  */
147e83
+	stb r10, 1(r19)		/* store byte to dst  */
147e83
+	beq cr7, L(updtDestComputeN2ndByte)
147e83
+
147e83
+	addi r4, r4, 4		/* advance src  */
147e83
+
147e83
+	lbz r10, -2(r4)		/* perform loop unrolling for byte r/w  */
147e83
+	cmpdi cr7, r10, 0
147e83
+	stb r10, 2(r19)
147e83
+	beq cr7, L(updtDestComputeN3rdByte)
147e83
+
147e83
+	lbz r10, -1(r4)		/* perform loop unrolling for byte r/w  */
147e83
+	addi r19, r19, 4
147e83
+	cmpdi cr7, r10, 0
147e83
+	stb r10, -1(r19)
147e83
+	beq cr7, L(ComputeNByte)
147e83
+
147e83
+	bdz L(update0)
147e83
+
147e83
+L(firstByteUnroll):
147e83
+	lbz r10, 0(r4)		/* perform loop unrolling for byte r/w  */
147e83
+	cmpdi cr7, 10, 0
147e83
+	stb r10, 0(r19)
147e83
+	bne cr7, L(bytes_unroll)
147e83
+	addi r19, r19, 1
147e83
+
147e83
+L(ComputeNByte):
147e83
+	subf r9, r19, r9	/* compute 'n'n bytes to fill  */
147e83
+	add r8, r9, r5
147e83
+
147e83
+L(zeroFill):
147e83
+	cmpdi cr7, r8, 0	/* compare if length is zero  */
147e83
+	beq cr7, L(update3return)
147e83
+
147e83
+	mr r3, r19		/* fill buffer with  */
147e83
+	li r4, 0		/* zero fill buffer  */
147e83
+	mr r5, r8		/* how many bytes to fill buffer with  */
147e83
+	bl MEMSET		/* call optimized memset  */
147e83
+	nop
147e83
+
147e83
+L(update3return):
147e83
+#ifdef USE_AS_STPNCPY
147e83
+	addi r3, r19, -1	/* update return value  */
147e83
+#endif
147e83
+
147e83
+L(hop2return):
147e83
+#ifndef USE_AS_STPNCPY
147e83
+	mr r3, r18		/* set return value  */
147e83
+#endif
147e83
+	addi r1, r1, FRAMESIZE	/* restore stack pointer  */
147e83
+	ld r0, 16(r1)		/* read the saved link register  */
147e83
+	ld r18, -16(r1)		/* restore callers save register, r18  */
147e83
+	ld r19, -8(r1)		/* restore callers save register, r19  */
147e83
+	mtlr r0			/* branch to link register  */
147e83
+	blr			/* return  */
147e83
+
147e83
+	.p2align 4
147e83
+L(update0):
147e83
+	mr r9, r19
147e83
+
147e83
+	.p2align 4
147e83
+L(verifyByte):
147e83
+	rldicl. r8, r5, 0, 62
147e83
+#ifdef USE_AS_STPNCPY
147e83
+	mr r3, r9
147e83
+#endif
147e83
+	beq cr0, L(hop2return)
147e83
+	mtctr r8
147e83
+	addi r4, r4, -1
147e83
+	mr r19, r9
147e83
+	b L(oneBYone)
147e83
+
147e83
+	.p2align 4
147e83
+L(proceed):
147e83
+	bdz L(done)
147e83
+
147e83
+L(oneBYone):
147e83
+	lbzu r10, 1(r4)		/* copy byte  */
147e83
+	addi r19, r19, 1
147e83
+	addi r8, r8, -1
147e83
+	cmpdi cr7, r10, 0
147e83
+	stb r10, -1(r19)
147e83
+	bne cr7, L(proceed)
147e83
+	b L(zeroFill)
147e83
+
147e83
+	.p2align 4
147e83
+L(done):
147e83
+	addi r1, r1, FRAMESIZE	/* restore stack pointer  */
147e83
+#ifdef USE_AS_STPNCPY
147e83
+	mr r3, r19		/* set the return value  */
147e83
+#else
147e83
+	mr r3, r18		/* set the return value  */
147e83
+#endif
147e83
+	ld r0, 16(r1)		/* read the saved link register  */
147e83
+	ld r18, -16(r1)		/* restore callers save register, r18  */
147e83
+	ld r19, -8(r1)		/* restore callers save register, r19  */
147e83
+	mtlr r0			/* branch to link register  */
147e83
+	blr			/* return  */
147e83
+
147e83
+L(update1):
147e83
+	mr r0, r11
147e83
+	mr r19, r5
147e83
+
147e83
+	.p2align 4
147e83
+L(leftDwords):
147e83
+	cmpdi cr7, r0, 0
147e83
+	mr r5, r19
147e83
+	bne cr7, L(dWordUnrollOFF)
147e83
+	b L(byte_by_byte)
147e83
+
147e83
+	.p2align 4
147e83
+L(updtDestComputeN2ndByte):
147e83
+	addi r19, r19, 2	/* update dst by 2  */
147e83
+	subf r9, r19, r9	/* compute distance covered  */
147e83
+	add r8, r9, r5
147e83
+	b L(zeroFill)
147e83
+
147e83
+	.p2align 4
147e83
+L(updtDestComputeN3rdByte):
147e83
+	addi r19, r19, 3	/* update dst by 3  */
147e83
+	subf r9, r19, r9	/* compute distance covered  */
147e83
+	add r8, r9, r5
147e83
+	b L(zeroFill)
147e83
+
147e83
+	.p2align 4
147e83
+L(HopBy24):
147e83
+	addi r9, r9, 24		/* increment dst by 24  */
147e83
+	addi r4, r4, 24		/* increment src by 24  */
147e83
+	addi r5, r5, -24	/* decrement length 'n' by 24  */
147e83
+	addi r0, r11, -3	/* decrement loop counter  */
147e83
+	b L(dWordUnrollOFF)
147e83
+
147e83
+	.p2align 4
147e83
+L(update2):
147e83
+	mr r5, r19
147e83
+	b L(dWordUnrollOFF)
147e83
+
147e83
+	.p2align 4
147e83
+L(HopBy40):
147e83
+	addi r9, r7, 40		/* increment dst by 40  */
147e83
+	addi r4, r6, 40		/* increment src by 40  */
147e83
+	addi r5, r5, -40	/* decrement length 'n' by 40  */
147e83
+	addi r0, r11, -5	/* decrement loop counter  */
147e83
+	b L(dWordUnrollOFF)
147e83
+
147e83
+L(update3):
147e83
+	mr r0, r11
147e83
+	b L(dWordUnrollOFF)
147e83
+
147e83
+L(HopBy8):
147e83
+	addi r9, r3, 8		/* increment dst by 8  */
147e83
+	addi r4, r4, 8		/* increment src by 8  */
147e83
+	addi r5, r5, -8		/* decrement length 'n' by 8  */
147e83
+	addi r0, r11, -1	/* decrement loop counter  */
147e83
+	b L(dWordUnrollOFF)
147e83
+END(FUNC_NAME)
147e83
+#ifndef USE_AS_STPNCPY
147e83
+libc_hidden_builtin_def (strncpy)
147e83
+#endif
147e83
diff --git a/sysdeps/powerpc/powerpc64/power8/stpncpy.S b/sysdeps/powerpc/powerpc64/power8/stpncpy.S
147e83
new file mode 100644
147e83
index 0000000..76a1466
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/power8/stpncpy.S
147e83
@@ -0,0 +1,20 @@
147e83
+/* Optimized stpncpy 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_STPNCPY
147e83
+#include <sysdeps/powerpc/powerpc64/power8/strncpy.S>
147e83
diff --git a/sysdeps/powerpc/powerpc64/power8/strncpy.S b/sysdeps/powerpc/powerpc64/power8/strncpy.S
147e83
new file mode 100644
147e83
index 0000000..5fda953
147e83
--- /dev/null
147e83
+++ b/sysdeps/powerpc/powerpc64/power8/strncpy.S
147e83
@@ -0,0 +1,424 @@
147e83
+/* Optimized strncpy/stpncpy 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_STPNCPY
147e83
+# define FUNC_NAME __stpncpy
147e83
+#else
147e83
+# define FUNC_NAME strncpy
147e83
+#endif
147e83
+
147e83
+/* Implements the function
147e83
+
147e83
+   char * [r3] strncpy (char *dest [r3], const char *src [r4], size_t n [r5])
147e83
+
147e83
+   or
147e83
+
147e83
+   char * [r3] stpncpy (char *dest [r3], const char *src [r4], size_t n [r5])
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
+
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	r10,r4,16
147e83
+	rlwinm	r9,r4,0,19,19
147e83
+
147e83
+	/* Since it is a leaf function, save some non-volatile registers on the
147e83
+	   protected/red zone.  */
147e83
+	std	r26,-48(r1)
147e83
+	std	r27,-40(r1)
147e83
+
147e83
+	rlwinm	r8,r10,0,19,19
147e83
+
147e83
+	std	r28,-32(r1)
147e83
+	std	r29,-24(r1)
147e83
+
147e83
+	cmpld	r7,r9,r8
147e83
+
147e83
+	std	r30,-16(r1)
147e83
+	std	r31,-8(r1)
147e83
+
147e83
+	beq	cr7,L(unaligned_lt_16)
147e83
+	rldicl	r9,r4,0,61
147e83
+	subfic	r8,r9,8
147e83
+	cmpld	cr7,r5,r8
147e83
+	bgt 	cr7,L(pagecross)
147e83
+
147e83
+	/* At this points there is 1 to 15 bytes to check and write.  Since it could
147e83
+	   be either from first unaligned 16 bytes access or from bulk copy, the code
147e83
+	   uses an unrolled byte read/write instead of trying to analyze the cmpb
147e83
+	   results.  */
147e83
+L(short_path):
147e83
+	mr	r9,r3
147e83
+L(short_path_1):
147e83
+	cmpdi	cr7,r5,0
147e83
+	beq	cr7,L(short_path_loop_end_1)
147e83
+L(short_path_2):
147e83
+	lbz	r10,0(r4)
147e83
+	cmpdi	cr7,r10,0
147e83
+	stb	r10,0(r9)
147e83
+	beq	cr7,L(zero_pad_start_1)
147e83
+	cmpdi	cr0,r5,1
147e83
+	addi	r8,r9,1
147e83
+	addi	r6,r5,-1
147e83
+	beq	cr0,L(short_path_loop_end_0)
147e83
+	lbz	r10,1(r4)
147e83
+	cmpdi	cr7,r10,0
147e83
+	stb	r10,1(r9)
147e83
+	beq	cr7,L(zero_pad_start_prepare_1)
147e83
+	addi	r10,r5,-3
147e83
+	b	L(short_path_loop_1)
147e83
+
147e83
+	.align	4
147e83
+L(short_path_loop):
147e83
+	lbz	r8,0(r4)
147e83
+	addi	r7,r10,-2
147e83
+	cmpdi	cr5,r8,0
147e83
+	stb	r8,0(r9)
147e83
+	beq	cr5,L(zero_pad_start_1)
147e83
+	beq	r7,L(short_path_loop_end_0)
147e83
+	lbz	r8,1(r4)
147e83
+	cmpdi	cr7,r8,0
147e83
+	stb	r8,1(r9)
147e83
+	beq	cr7,L(zero_pad_start)
147e83
+	mr	r10,r7
147e83
+L(short_path_loop_1):
147e83
+	addic.	r5,r5,-2
147e83
+	addi	r9,r9,2
147e83
+	cmpdi	cr7,r10,0
147e83
+	addi	r4,r4,2
147e83
+	addi	r6,r9,1
147e83
+	bne	cr0,L(short_path_loop)
147e83
+#ifdef USE_AS_STPNCPY
147e83
+	mr	r3,r9
147e83
+	b	L(short_path_loop_end)
147e83
+#endif
147e83
+
147e83
+L(short_path_loop_end_0):
147e83
+#ifdef USE_AS_STPNCPY
147e83
+	addi	r3,r9,1
147e83
+	b	L(short_path_loop_end)
147e83
+#endif
147e83
+L(short_path_loop_end_1):
147e83
+#ifdef USE_AS_STPNCPY
147e83
+	mr	r3,r9
147e83
+#endif
147e83
+L(short_path_loop_end):
147e83
+	/* Restore non-volatile registers.  */
147e83
+	ld	r26,-48(r1)
147e83
+	ld	r27,-40(r1)
147e83
+	ld	r28,-32(r1)
147e83
+	ld	r29,-24(r1)
147e83
+	ld	r30,-16(r1)
147e83
+	ld	r31,-8(r1)
147e83
+	blr
147e83
+
147e83
+	/* This code pads the remainder dest with NULL bytes.  The algorithm
147e83
+	   calculate the remanining size and issues a doubleword unrolled
147e83
+	   loops followed by a byte a byte set.  */
147e83
+	.align	4
147e83
+L(zero_pad_start):
147e83
+	mr	r5,r10
147e83
+	mr	r9,r6
147e83
+L(zero_pad_start_1):
147e83
+	srdi.	r8,r5,r3
147e83
+	mr	r10,r9
147e83
+#ifdef USE_AS_STPNCPY
147e83
+	mr	r3,r9
147e83
+#endif
147e83
+	beq-	cr0,L(zero_pad_loop_b_start)
147e83
+	cmpldi	cr7,r8,1
147e83
+	li	cr7,0
147e83
+	std	r7,0(r9)
147e83
+	beq	cr7,L(zero_pad_loop_b_prepare)
147e83
+	addic.	r8,r8,-2
147e83
+	addi	r10,r9,r16
147e83
+	std	r7,8(r9)
147e83
+	beq	cr0,L(zero_pad_loop_dw_2)
147e83
+	std	r7,16(r9)
147e83
+	li	r9,0
147e83
+	b	L(zero_pad_loop_dw_1)
147e83
+
147e83
+	.align	4
147e83
+L(zero_pad_loop_dw):
147e83
+	addi	r10,r10,16
147e83
+	std	r9,-8(r10)
147e83
+	beq	cr0,L(zero_pad_loop_dw_2)
147e83
+	std	r9,0(r10)
147e83
+L(zero_pad_loop_dw_1):
147e83
+	cmpldi	cr7,r8,1
147e83
+	std	r9,0(r10)
147e83
+	addic.	r8,r8,-2
147e83
+	bne	cr7,L(zero_pad_loop_dw)
147e83
+	addi	r10,r10,8
147e83
+L(zero_pad_loop_dw_2):
147e83
+	rldicl	r5,r5,0,61
147e83
+L(zero_pad_loop_b_start):
147e83
+	cmpdi	cr7,r5,0
147e83
+	addi	r5,r5,-1
147e83
+	addi	r9,r10,-1
147e83
+	add	r10,r10,5
147e83
+	subf	r10,r9,r10
147e83
+	li	r8,0
147e83
+	beq-	cr7,L(short_path_loop_end)
147e83
+
147e83
+	/* Write remaining 1-8 bytes.  */
147e83
+        .align  4
147e83
+	addi	r9,r9,1
147e83
+	mtocrf	0x1,r10
147e83
+	bf	29,4f
147e83
+        stw     r8,0(r9)
147e83
+        addi	r9,r9,4
147e83
+
147e83
+        .align  4
147e83
+4:      bf      30,2f
147e83
+        sth     r8,0(r9)
147e83
+        addi	r9,r9,2
147e83
+
147e83
+        .align  4
147e83
+2:      bf	31,1f
147e83
+        stb	r8,0(r9)
147e83
+
147e83
+	/* Restore non-volatile registers.  */
147e83
+1:	ld	r26,-48(r1)
147e83
+	ld	r27,-40(r1)
147e83
+	ld	r28,-32(r1)
147e83
+	ld	r29,-24(r1)
147e83
+	ld	r30,-16(r1)
147e83
+	ld	r31,-8(r1)
147e83
+	blr
147e83
+
147e83
+	/* The common case where [src]+16 will not cross a 4K page boundary.
147e83
+	   In this case the code fast check the first 16 bytes by using doubleword
147e83
+	   read/compares and update destiny if neither total size or null byte
147e83
+	   is found in destiny. */
147e83
+	.align	4
147e83
+L(unaligned_lt_16):
147e83
+	cmpldi	cr7,r5,7
147e83
+	ble	cr7,L(short_path)
147e83
+	ld	r7,0(r4)
147e83
+	li	r8,0
147e83
+	cmpb	r8,r7,r8
147e83
+	cmpdi	cr7,r8,0
147e83
+	bne	cr7,L(short_path_prepare_2)
147e83
+	addi	r6,r5,-8
147e83
+	std	r7,0(r3)
147e83
+	addi	r9,r3,r8
147e83
+	cmpldi	cr7,r6,7
147e83
+	addi	r7,r4,8
147e83
+	ble	cr7,L(short_path_prepare_1_1)
147e83
+	ld	r4,8(r4)
147e83
+	cmpb	r8,r4,r8
147e83
+	cmpdi	cr7,r8,0
147e83
+	bne	cr7,L(short_path_prepare_2_1)
147e83
+	std	r4,8(r3)
147e83
+	addi	r29,r3,16
147e83
+	addi	r5,r5,-16
147e83
+	/* Neither the null byte was found or total length was reached,
147e83
+	   align to 16 bytes and issue a bulk copy/compare.  */
147e83
+	b	L(align_to_16b)
147e83
+
147e83
+	/* In the case of 4k page boundary cross, the algorithm first align
147e83
+	   the address to a doubleword, calculate a mask based on alignment
147e83
+	   to ignore the bytes and continue using doubleword.  */
147e83
+	.align	4
147e83
+L(pagecross):
147e83
+	rldicr	r11,r4,0,59	/* Align the address to 8 bytes boundary.  */
147e83
+	li	r6,-1		/* MASK = 0xffffffffffffffffUL.  */
147e83
+	sldi	r9,r9,3		/* Calculate padding.  */
147e83
+	ld	r7,0(r11)	/* Load doubleword from memory.  */
147e83
+#ifdef __LITTLE_ENDIAN__
147e83
+	sld	r9,r6,r9	/* MASK = MASK << padding.  */
147e83
+#else
147e83
+	srd	r9,r6,r9	/* MASK = MASK >> padding.  */
147e83
+#endif
147e83
+	orc	r9,r7,r9	/* Mask bits that are not part of the
147e83
+				   string.  */
147e83
+	li	cr7,0
147e83
+	cmpb	r9,r9,r7	/* Check for null bytes in DWORD1.  */
147e83
+	cmpdi	cr7,r9,0
147e83
+	bne	cr7,L(short_path_prepare_2)
147e83
+	subf	r8,r8,r5	/* Adjust total length.  */
147e83
+	cmpldi	cr7,r8,8	/* Check if length was reached.  */
147e83
+	ble	cr7,L(short_path_prepare_2)
147e83
+
147e83
+	/* For next checks we have aligned address, so we check for more
147e83
+	   three doublewords to make sure we can read 16 unaligned bytes
147e83
+	   to start the bulk copy with 16 aligned addresses.  */
147e83
+	ld	cr7,8(r11)
147e83
+	cmpb	r9,r7,r9
147e83
+	cmpdi	cr7,r9,0
147e83
+	bne	cr7,L(short_path_prepare_2)
147e83
+	addi	cr7,r8,-8
147e83
+	cmpldi	cr7,r7,8
147e83
+	ble	cr7,L(short_path_prepare_2)
147e83
+	ld	cr7,16(r11)
147e83
+	cmpb	r9,r7,r9
147e83
+	cmpdi	cr7,r9,0
147e83
+	bne	cr7,L(short_path_prepare_2)
147e83
+	addi	r8,r8,-16
147e83
+	cmpldi	r7,r8,8
147e83
+	ble	cr7,L(short_path_prepare_2)
147e83
+	ld	r8,24(r11)
147e83
+	cmpb	r9,r8,r9
147e83
+	cmpdi	r7,r9,0
147e83
+	bne	cr7,L(short_path_prepare_2)
147e83
+
147e83
+	/* No null byte found in the 32 bytes readed and length not reached,
147e83
+	   read source again using unaligned loads and store them.  */
147e83
+	ld	r9,0(r4)
147e83
+	addi	r29,r3,16
147e83
+	addi	r5,r5,-16
147e83
+	std	r9,0(r3)
147e83
+	ld	r9,8(r4)
147e83
+	std	r9,8(r3)
147e83
+
147e83
+	/* Align source to 16 bytes and adjust destiny and size.  */
147e83
+L(align_to_16b):
147e83
+	rldicl	r9,r10,0,60
147e83
+	rldicr	r28,r10,0,59
147e83
+	add	r12,r5,r9
147e83
+	subf	r29,r9,r29
147e83
+
147e83
+	/* The bulk read/compare/copy loads two doublewords, compare and merge
147e83
+	   in a single register for speed.  This is an attempt to speed up the
147e83
+	   null-checking process for bigger strings.  */
147e83
+
147e83
+	cmpldi	cr7,r12,15
147e83
+	ble	cr7,L(short_path_prepare_1_2)
147e83
+
147e83
+	/* Main loop for large sizes, unrolled 2 times to get better use of
147e83
+	   pipeline.  */
147e83
+	ld	r8,0(28)
147e83
+	ld	r10,8(28)
147e83
+	li	r9,0
147e83
+	cmpb	r7,r8,r9
147e83
+	cmpb	r9,r10,r9
147e83
+	or.	r6,r9,r7
147e83
+	bne	cr0,L(short_path_prepare_2_3)
147e83
+	addi	r5,r12,-16
147e83
+	addi	r4,r28,16
147e83
+	std	r8,0(r29)
147e83
+	std	r10,8(r29)
147e83
+	cmpldi	cr7,r5,15
147e83
+	addi	r9,r29,16
147e83
+	ble	cr7,L(short_path_1)
147e83
+	mr	r11,r28
147e83
+	mr	r6,r29
147e83
+	li	r30,0
147e83
+	subfic	r26,r4,48
147e83
+	subfic	r27,r9,48
147e83
+
147e83
+	b	L(loop_16b)
147e83
+
147e83
+	.align	4
147e83
+L(loop_start):
147e83
+	ld	r31,0(r11)
147e83
+	ld	r10,8(r11)
147e83
+	cmpb	r0,r31,r7
147e83
+	cmpb	r8,r10,r7
147e83
+	or.	r7,r0,r8
147e83
+	addi	r5,r5,-32
147e83
+	cmpldi	cr7,r5,15
147e83
+	add	r4,r4,r26
147e83
+	add	r9,r9,r27
147e83
+	bne	cr0,L(short_path_prepare_2_2)
147e83
+	add	r4,r28,r4
147e83
+	std	r31,0(r6)
147e83
+	add	r9,r29,r9
147e83
+	std	r10,8(r6)
147e83
+	ble	cr7,L(short_path_1)
147e83
+
147e83
+L(loop_16b):
147e83
+	ld	r10,16(r11)
147e83
+	ld	r0,24(r11)
147e83
+	cmpb	r8,r10,r30
147e83
+	cmpb	r7,r0,r30
147e83
+	or.	r7,r8,r7
147e83
+	addi	r12,r12,-32
147e83
+	cmpldi	r7,r12,15
147e83
+	addi	r11,r11,32
147e83
+	bne	cr0,L(short_path_2)
147e83
+	std	r10,16(r6)
147e83
+	addi	r6,r6,32
147e83
+	std	r0,-8(r6)
147e83
+	bgt	cr7,L(loop_start)
147e83
+
147e83
+	mr	r5,r12
147e83
+	mr	r4,r11
147e83
+	mr	r9,r6
147e83
+	b	L(short_path_1)
147e83
+
147e83
+	.align	4
147e83
+L(short_path_prepare_1_1):
147e83
+	mr	r5,r6
147e83
+	mr	r4,r7
147e83
+	b	L(short_path_1)
147e83
+L(short_path_prepare_1_2):
147e83
+	mr	r5,r12
147e83
+	mr	r4,r28
147e83
+	mr	r9,r29
147e83
+	b	L(short_path_1)
147e83
+L(short_path_prepare_2):
147e83
+	mr	r9,r3
147e83
+	b	L(short_path_2)
147e83
+L(short_path_prepare_2_1):
147e83
+	mr	r5,r6
147e83
+	mr	r4,r7
147e83
+	b	L(short_path_2)
147e83
+L(short_path_prepare_2_2):
147e83
+	mr	r5,r12
147e83
+	mr	r4,r11
147e83
+	mr	r9,r6
147e83
+	b	L(short_path_2)
147e83
+L(short_path_prepare_2_3):
147e83
+	mr	r5,r12
147e83
+	mr	r4,r28
147e83
+	mr	r9,r29
147e83
+	b	L(short_path_2)
147e83
+L(zero_pad_loop_b_prepare):
147e83
+	addi	r10,r9,8
147e83
+	rldicl	r5,r5,0,61
147e83
+	b	L(zero_pad_loop_b_start)
147e83
+L(zero_pad_start_prepare_1):
147e83
+	mr	r5,r6
147e83
+	mr	r9,r8
147e83
+	b	L(zero_pad_start_1)
147e83
+END (FUNC_NAME)
147e83
+
147e83
+#ifdef USE_AS_STPNCPY
147e83
+libc_hidden_def (__stpncpy)
147e83
+#else
147e83
+libc_hidden_builtin_def (strncpy)
147e83
+#endif