9bb5d6
From b9d83bf3eb57e1cf8ef785f1a58e13ddf162b6f3 Mon Sep 17 00:00:00 2001
9bb5d6
From: Raphael M Zinsly <rzinsly@linux.ibm.com>
9bb5d6
Date: Thu, 12 Nov 2020 13:12:24 -0300
9bb5d6
Subject: powerpc: Add optimized strncpy for POWER9
9bb5d6
9bb5d6
Similar to the strcpy P9 optimization, this version uses VSX to improve
9bb5d6
performance.
9bb5d6
9bb5d6
Reviewed-by: Matheus Castanho <msc@linux.ibm.com>
9bb5d6
Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
9bb5d6
9bb5d6
diff --git a/sysdeps/powerpc/powerpc64/le/power9/strncpy.S b/sysdeps/powerpc/powerpc64/le/power9/strncpy.S
9bb5d6
new file mode 100644
9bb5d6
index 0000000000..cbfc37bda3
9bb5d6
--- /dev/null
9bb5d6
+++ b/sysdeps/powerpc/powerpc64/le/power9/strncpy.S
9bb5d6
@@ -0,0 +1,344 @@
9bb5d6
+/* Optimized strncpy implementation for POWER9 LE.
9bb5d6
+   Copyright (C) 2020 Free Software Foundation, Inc.
9bb5d6
+   This file is part of the GNU C Library.
9bb5d6
+
9bb5d6
+   The GNU C Library is free software; you can redistribute it and/or
9bb5d6
+   modify it under the terms of the GNU Lesser General Public
9bb5d6
+   License as published by the Free Software Foundation; either
9bb5d6
+   version 2.1 of the License, or (at your option) any later version.
9bb5d6
+
9bb5d6
+   The GNU C Library is distributed in the hope that it will be useful,
9bb5d6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
9bb5d6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9bb5d6
+   Lesser General Public License for more details.
9bb5d6
+
9bb5d6
+   You should have received a copy of the GNU Lesser General Public
9bb5d6
+   License along with the GNU C Library; if not, see
9bb5d6
+   <https://www.gnu.org/licenses/>.  */
9bb5d6
+
9bb5d6
+#include <sysdep.h>
9bb5d6
+
9bb5d6
+# ifndef STRNCPY
9bb5d6
+#  define FUNC_NAME strncpy
9bb5d6
+# else
9bb5d6
+#  define FUNC_NAME STRNCPY
9bb5d6
+# endif
9bb5d6
+
9bb5d6
+#ifndef MEMSET
9bb5d6
+/* For builds without IFUNC support, local calls should be made to internal
9bb5d6
+   GLIBC symbol (created by libc_hidden_builtin_def).  */
9bb5d6
+# ifdef SHARED
9bb5d6
+#  define MEMSET_is_local
9bb5d6
+#  define MEMSET   __GI_memset
9bb5d6
+# else
9bb5d6
+#  define MEMSET   memset
9bb5d6
+# endif
9bb5d6
+#endif
9bb5d6
+
9bb5d6
+#define FRAMESIZE (FRAME_MIN_SIZE+8)
9bb5d6
+
9bb5d6
+/* Implements the function
9bb5d6
+
9bb5d6
+   char * [r3] strncpy (char *dest [r3], const char *src [r4], size_t n [r5])
9bb5d6
+
9bb5d6
+   The implementation can load bytes past a null terminator, but only
9bb5d6
+   up to the next 16-byte aligned address, so it never crosses a page.  */
9bb5d6
+
9bb5d6
+.machine power9
9bb5d6
+#ifdef MEMSET_is_local
9bb5d6
+ENTRY_TOCLESS (FUNC_NAME, 4)
9bb5d6
+#else
9bb5d6
+ENTRY (FUNC_NAME, 4)
9bb5d6
+#endif
9bb5d6
+	CALL_MCOUNT 2
9bb5d6
+
9bb5d6
+	/* NULL string optimizations  */
9bb5d6
+	cmpdi   r5, 0
9bb5d6
+	beqlr
9bb5d6
+
9bb5d6
+	lbz	r0,0(r4)
9bb5d6
+	stb	r0,0(r3)
9bb5d6
+	addi	r11,r3,1
9bb5d6
+	addi	r5,r5,-1
9bb5d6
+	vspltisb v18,0		/* Zeroes in v18  */
9bb5d6
+	cmpdi	r0,0
9bb5d6
+	beq	L(zero_padding)
9bb5d6
+
9bb5d6
+	/* Empty/1-byte string optimization  */
9bb5d6
+	cmpdi	r5,0
9bb5d6
+	beqlr
9bb5d6
+
9bb5d6
+	addi	r4,r4,1
9bb5d6
+	neg	r7,r4
9bb5d6
+	rldicl	r9,r7,0,60	/* How many bytes to get source 16B aligned?  */
9bb5d6
+
9bb5d6
+	/* Get source 16B aligned  */
9bb5d6
+	lvx	v0,0,r4
9bb5d6
+	lvsr	v1,0,r4
9bb5d6
+	vperm	v0,v18,v0,v1
9bb5d6
+
9bb5d6
+	vcmpequb v6,v0,v18	/* 0xff if byte is NULL, 0x00 otherwise  */
9bb5d6
+	vctzlsbb r7,v6		/* Number of trailing zeroes  */
9bb5d6
+	addi	r8,r7,1		/* Add null terminator  */
9bb5d6
+
9bb5d6
+	/* r8 = bytes including null
9bb5d6
+	   r9 = bytes to get source 16B aligned
9bb5d6
+	   if r8 > r9
9bb5d6
+	      no null, copy r9 bytes
9bb5d6
+	   else
9bb5d6
+	      there is a null, copy r8 bytes and return.  */
9bb5d6
+	cmpld	r8,r9
9bb5d6
+	bgt	L(no_null)
9bb5d6
+
9bb5d6
+	cmpld	cr6,r8,r5	/* r8 <= n?  */
9bb5d6
+	ble	cr6,L(null)
9bb5d6
+
9bb5d6
+	sldi	r10,r5,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	stxvl	32+v0,r11,r10	/* Partial store  */
9bb5d6
+
9bb5d6
+	blr
9bb5d6
+
9bb5d6
+L(null):
9bb5d6
+	sldi	r10,r8,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	stxvl	32+v0,r11,r10	/* Partial store  */
9bb5d6
+
9bb5d6
+	add	r11,r11,r8
9bb5d6
+	sub	r5,r5,r8
9bb5d6
+	b L(zero_padding)
9bb5d6
+
9bb5d6
+L(no_null):
9bb5d6
+	cmpld	r9,r5		/* Check if length was reached.  */
9bb5d6
+	bge	L(n_tail1)
9bb5d6
+
9bb5d6
+	sldi	r10,r9,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	stxvl	32+v0,r11,r10	/* Partial store  */
9bb5d6
+
9bb5d6
+	add	r4,r4,r9
9bb5d6
+	add	r11,r11,r9
9bb5d6
+	sub	r5,r5,r9
9bb5d6
+
9bb5d6
+L(loop):
9bb5d6
+	cmpldi	cr6,r5,64	/* Check if length was reached.  */
9bb5d6
+	ble	cr6,L(final_loop)
9bb5d6
+
9bb5d6
+	lxv	32+v0,0(r4)
9bb5d6
+	vcmpequb. v6,v0,v18	/* Any zero bytes?  */
9bb5d6
+	bne	cr6,L(prep_tail1)
9bb5d6
+
9bb5d6
+	lxv	32+v1,16(r4)
9bb5d6
+	vcmpequb. v6,v1,v18	/* Any zero bytes?  */
9bb5d6
+	bne	cr6,L(prep_tail2)
9bb5d6
+
9bb5d6
+	lxv	32+v2,32(r4)
9bb5d6
+	vcmpequb. v6,v2,v18	/* Any zero bytes?  */
9bb5d6
+	bne	cr6,L(prep_tail3)
9bb5d6
+
9bb5d6
+	lxv	32+v3,48(r4)
9bb5d6
+	vcmpequb. v6,v3,v18	/* Any zero bytes?  */
9bb5d6
+	bne	cr6,L(prep_tail4)
9bb5d6
+
9bb5d6
+	stxv	32+v0,0(r11)
9bb5d6
+	stxv	32+v1,16(r11)
9bb5d6
+	stxv	32+v2,32(r11)
9bb5d6
+	stxv	32+v3,48(r11)
9bb5d6
+
9bb5d6
+	addi	r4,r4,64
9bb5d6
+	addi	r11,r11,64
9bb5d6
+	addi	r5,r5,-64
9bb5d6
+
9bb5d6
+	b	L(loop)
9bb5d6
+
9bb5d6
+L(final_loop):
9bb5d6
+	cmpldi	cr5,r5,16
9bb5d6
+	lxv	32+v0,0(r4)
9bb5d6
+	vcmpequb. v6,v0,v18	/* Any zero bytes?  */
9bb5d6
+	ble	cr5,L(prep_n_tail1)
9bb5d6
+	bne	cr6,L(count_tail1)
9bb5d6
+	addi	r5,r5,-16
9bb5d6
+
9bb5d6
+	cmpldi	cr5,r5,16
9bb5d6
+	lxv	32+v1,16(r4)
9bb5d6
+	vcmpequb. v6,v1,v18	/* Any zero bytes?  */
9bb5d6
+	ble	cr5,L(prep_n_tail2)
9bb5d6
+	bne	cr6,L(count_tail2)
9bb5d6
+	addi	r5,r5,-16
9bb5d6
+
9bb5d6
+	cmpldi	cr5,r5,16
9bb5d6
+	lxv	32+v2,32(r4)
9bb5d6
+	vcmpequb. v6,v2,v18	/* Any zero bytes?  */
9bb5d6
+	ble	cr5,L(prep_n_tail3)
9bb5d6
+	bne	cr6,L(count_tail3)
9bb5d6
+	addi	r5,r5,-16
9bb5d6
+
9bb5d6
+	lxv	32+v3,48(r4)
9bb5d6
+	vcmpequb. v6,v3,v18	/* Any zero bytes?  */
9bb5d6
+	beq	cr6,L(n_tail4)
9bb5d6
+
9bb5d6
+	vctzlsbb r8,v6		/* Number of trailing zeroes  */
9bb5d6
+	cmpld	r8,r5		/* r8 < n?  */
9bb5d6
+	blt	L(tail4)
9bb5d6
+
9bb5d6
+L(n_tail4):
9bb5d6
+	stxv	32+v0,0(r11)
9bb5d6
+	stxv	32+v1,16(r11)
9bb5d6
+	stxv	32+v2,32(r11)
9bb5d6
+	sldi	r10,r5,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	addi	r11,r11,48	/* Offset */
9bb5d6
+	stxvl	32+v3,r11,r10	/* Partial store  */
9bb5d6
+	blr
9bb5d6
+
9bb5d6
+L(prep_n_tail1):
9bb5d6
+	beq	cr6,L(n_tail1)	/* Any zero bytes?  */
9bb5d6
+	vctzlsbb r8,v6		/* Number of trailing zeroes  */
9bb5d6
+	cmpld	r8,r5		/* r8 < n?  */
9bb5d6
+	blt	L(tail1)
9bb5d6
+
9bb5d6
+L(n_tail1):
9bb5d6
+	sldi	r10,r5,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	stxvl	32+v0,r11,r10	/* Partial store  */
9bb5d6
+	blr
9bb5d6
+
9bb5d6
+L(prep_n_tail2):
9bb5d6
+	beq	cr6,L(n_tail2)	/* Any zero bytes?  */
9bb5d6
+	vctzlsbb r8,v6		/* Number of trailing zeroes  */
9bb5d6
+	cmpld	r8,r5		/* r8 < n?  */
9bb5d6
+	blt	L(tail2)
9bb5d6
+
9bb5d6
+L(n_tail2):
9bb5d6
+	stxv	32+v0,0(r11)
9bb5d6
+	sldi	r10,r5,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	addi	r11,r11,16	/* offset */
9bb5d6
+	stxvl	32+v1,r11,r10	/* Partial store  */
9bb5d6
+	blr
9bb5d6
+
9bb5d6
+L(prep_n_tail3):
9bb5d6
+	beq	cr6,L(n_tail3)	/* Any zero bytes?  */
9bb5d6
+	vctzlsbb r8,v6		/* Number of trailing zeroes  */
9bb5d6
+	cmpld	r8,r5		/* r8 < n?  */
9bb5d6
+	blt	L(tail3)
9bb5d6
+
9bb5d6
+L(n_tail3):
9bb5d6
+	stxv	32+v0,0(r11)
9bb5d6
+	stxv	32+v1,16(r11)
9bb5d6
+	sldi	r10,r5,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	addi	r11,r11,32	/* Offset */
9bb5d6
+	stxvl	32+v2,r11,r10	/* Partial store  */
9bb5d6
+	blr
9bb5d6
+
9bb5d6
+L(prep_tail1):
9bb5d6
+L(count_tail1):
9bb5d6
+	vctzlsbb r8,v6		/* Number of trailing zeroes  */
9bb5d6
+L(tail1):
9bb5d6
+	addi	r9,r8,1		/* Add null terminator  */
9bb5d6
+	sldi	r10,r9,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	stxvl	32+v0,r11,r10	/* Partial store  */
9bb5d6
+	add	r11,r11,r9
9bb5d6
+	sub	r5,r5,r9
9bb5d6
+	b L(zero_padding)
9bb5d6
+
9bb5d6
+L(prep_tail2):
9bb5d6
+	addi	r5,r5,-16
9bb5d6
+L(count_tail2):
9bb5d6
+	vctzlsbb r8,v6		/* Number of trailing zeroes  */
9bb5d6
+L(tail2):
9bb5d6
+	addi	r9,r8,1		/* Add null terminator  */
9bb5d6
+	stxv	32+v0,0(r11)
9bb5d6
+	sldi	r10,r9,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	addi	r11,r11,16	/* offset */
9bb5d6
+	stxvl	32+v1,r11,r10	/* Partial store  */
9bb5d6
+	add	r11,r11,r9
9bb5d6
+	sub	r5,r5,r9
9bb5d6
+	b L(zero_padding)
9bb5d6
+
9bb5d6
+L(prep_tail3):
9bb5d6
+	addi	r5,r5,-32
9bb5d6
+L(count_tail3):
9bb5d6
+	vctzlsbb r8,v6		/* Number of trailing zeroes  */
9bb5d6
+L(tail3):
9bb5d6
+	addi	r9,r8,1		/* Add null terminator  */
9bb5d6
+	stxv	32+v0,0(r11)
9bb5d6
+	stxv	32+v1,16(r11)
9bb5d6
+	sldi	r10,r9,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	addi	r11,r11,32	/* offset */
9bb5d6
+	stxvl	32+v2,r11,r10	/* Partial store  */
9bb5d6
+	add	r11,r11,r9
9bb5d6
+	sub	r5,r5,r9
9bb5d6
+	b L(zero_padding)
9bb5d6
+
9bb5d6
+L(prep_tail4):
9bb5d6
+	addi	r5,r5,-48
9bb5d6
+	vctzlsbb r8,v6		/* Number of trailing zeroes  */
9bb5d6
+L(tail4):
9bb5d6
+	addi	r9,r8,1		/* Add null terminator  */
9bb5d6
+	stxv	32+v0,0(r11)
9bb5d6
+	stxv	32+v1,16(r11)
9bb5d6
+	stxv	32+v2,32(r11)
9bb5d6
+	sldi	r10,r9,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	addi	r11,r11,48	/* offset */
9bb5d6
+	stxvl	32+v3,r11,r10	/* Partial store  */
9bb5d6
+	add	r11,r11,r9
9bb5d6
+	sub	r5,r5,r9
9bb5d6
+
9bb5d6
+/* This code pads the remainder of dest with NULL bytes.  For large numbers
9bb5d6
+   memset gives a better performance, 255 was chosen through experimentation.
9bb5d6
+   */
9bb5d6
+L(zero_padding):
9bb5d6
+	cmpldi	r5,255
9bb5d6
+	bge	L(zero_padding_memset)
9bb5d6
+
9bb5d6
+L(zero_padding_loop):
9bb5d6
+	cmpldi	cr6,r5,16	/* Check if length was reached.  */
9bb5d6
+	ble	cr6,L(zero_padding_end)
9bb5d6
+
9bb5d6
+	stxv	v18,0(r11)
9bb5d6
+	addi	r11,r11,16
9bb5d6
+	addi	r5,r5,-16
9bb5d6
+
9bb5d6
+	b	L(zero_padding_loop)
9bb5d6
+
9bb5d6
+L(zero_padding_end):
9bb5d6
+	sldi	r10,r5,56	/* stxvl wants size in top 8 bits  */
9bb5d6
+	stxvl	v18,r11,r10	/* Partial store  */
9bb5d6
+	blr
9bb5d6
+
9bb5d6
+	.align	4
9bb5d6
+L(zero_padding_memset):
9bb5d6
+	std	r30,-8(r1)   /* Save r30 on the stack.  */
9bb5d6
+	cfi_offset(r30, -8)
9bb5d6
+	mr	r30,r3       /* Save the return value of strncpy.  */
9bb5d6
+	/* Prepare the call to memset.  */
9bb5d6
+	mr	r3,r11       /* Pointer to the area to be zero-filled.  */
9bb5d6
+	li	r4,0         /* Byte to be written (zero).  */
9bb5d6
+
9bb5d6
+	/* We delayed the creation of the stack frame, as well as the saving of
9bb5d6
+	   the link register, because only at this point, we are sure that
9bb5d6
+	   doing so is actually needed.  */
9bb5d6
+
9bb5d6
+	/* Save the link register.  */
9bb5d6
+	mflr	r0
9bb5d6
+	std	r0,16(r1)
9bb5d6
+
9bb5d6
+	/* Create the stack frame.  */
9bb5d6
+	stdu	r1,-FRAMESIZE(r1)
9bb5d6
+	cfi_adjust_cfa_offset(FRAMESIZE)
9bb5d6
+	cfi_offset(lr, 16)
9bb5d6
+
9bb5d6
+	bl	MEMSET
9bb5d6
+#ifndef MEMSET_is_local
9bb5d6
+	nop
9bb5d6
+#endif
9bb5d6
+
9bb5d6
+	ld	r0,FRAMESIZE+16(r1)
9bb5d6
+
9bb5d6
+	mr	r3,r30       /* Restore the return value of strncpy, i.e.:
9bb5d6
+				dest.  */
9bb5d6
+	ld	r30,FRAMESIZE-8(r1) /* Restore r30.  */
9bb5d6
+	/* Restore the stack frame.  */
9bb5d6
+	addi	r1,r1,FRAMESIZE
9bb5d6
+	cfi_adjust_cfa_offset(-FRAMESIZE)
9bb5d6
+	/* Restore the link register.  */
9bb5d6
+	mtlr	r0
9bb5d6
+	cfi_restore(lr)
9bb5d6
+	blr
9bb5d6
+
9bb5d6
+END (FUNC_NAME)
9bb5d6
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
9bb5d6
index 19acb6c64a..cd2b47b403 100644
9bb5d6
--- a/sysdeps/powerpc/powerpc64/multiarch/Makefile
9bb5d6
+++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile
9bb5d6
@@ -33,7 +33,7 @@ sysdep_routines += memcpy-power8-cached memcpy-power7 memcpy-a2 memcpy-power6 \
9bb5d6
 
9bb5d6
 ifneq (,$(filter %le,$(config-machine)))
9bb5d6
 sysdep_routines += strcmp-power9 strncmp-power9 strcpy-power9 stpcpy-power9 \
9bb5d6
-		   rawmemchr-power9 strlen-power9
9bb5d6
+		   rawmemchr-power9 strlen-power9 strncpy-power9
9bb5d6
 endif
9bb5d6
 CFLAGS-strncase-power7.c += -mcpu=power7 -funroll-loops
9bb5d6
 CFLAGS-strncase_l-power7.c += -mcpu=power7 -funroll-loops
9bb5d6
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
9bb5d6
index dd54e7d6bb..135326c97a 100644
9bb5d6
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
9bb5d6
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
9bb5d6
@@ -301,6 +301,12 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
9bb5d6
 
9bb5d6
   /* Support sysdeps/powerpc/powerpc64/multiarch/strncpy.c.  */
9bb5d6
   IFUNC_IMPL (i, name, strncpy,
9bb5d6
+#ifdef __LITTLE_ENDIAN__
9bb5d6
+	      IFUNC_IMPL_ADD (array, i, strncpy,
9bb5d6
+			      (hwcap2 & PPC_FEATURE2_ARCH_3_00)
9bb5d6
+			      && (hwcap & PPC_FEATURE_HAS_VSX),
9bb5d6
+			      __strncpy_power9)
9bb5d6
+#endif
9bb5d6
 	      IFUNC_IMPL_ADD (array, i, strncpy,
9bb5d6
 			      hwcap2 & PPC_FEATURE2_ARCH_2_07,
9bb5d6
 			      __strncpy_power8)
9bb5d6
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strncpy-power9.S b/sysdeps/powerpc/powerpc64/multiarch/strncpy-power9.S
9bb5d6
new file mode 100644
9bb5d6
index 0000000000..2b57c190f5
9bb5d6
--- /dev/null
9bb5d6
+++ b/sysdeps/powerpc/powerpc64/multiarch/strncpy-power9.S
9bb5d6
@@ -0,0 +1,32 @@
9bb5d6
+/* Optimized strncpy implementation for POWER9 LE.
9bb5d6
+   Copyright (C) 2020 Free Software Foundation, Inc.
9bb5d6
+   This file is part of the GNU C Library.
9bb5d6
+
9bb5d6
+   The GNU C Library is free software; you can redistribute it and/or
9bb5d6
+   modify it under the terms of the GNU Lesser General Public
9bb5d6
+   License as published by the Free Software Foundation; either
9bb5d6
+   version 2.1 of the License, or (at your option) any later version.
9bb5d6
+
9bb5d6
+   The GNU C Library is distributed in the hope that it will be useful,
9bb5d6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
9bb5d6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9bb5d6
+   Lesser General Public License for more details.
9bb5d6
+
9bb5d6
+   You should have received a copy of the GNU Lesser General Public
9bb5d6
+   License along with the GNU C Library; if not, see
9bb5d6
+   <https://www.gnu.org/licenses/>.  */
9bb5d6
+
9bb5d6
+#if defined __LITTLE_ENDIAN__ && IS_IN (libc)
9bb5d6
+# define STRNCPY __strncpy_power9
9bb5d6
+
9bb5d6
+# undef libc_hidden_builtin_def
9bb5d6
+# define libc_hidden_builtin_def(name)
9bb5d6
+
9bb5d6
+/* memset is used to pad the end of the string.  */
9bb5d6
+# define MEMSET __memset_power8
9bb5d6
+# ifdef SHARED
9bb5d6
+#  define MEMSET_is_local
9bb5d6
+# endif
9bb5d6
+
9bb5d6
+# include <sysdeps/powerpc/powerpc64/le/power9/strncpy.S>
9bb5d6
+#endif
9bb5d6
diff --git a/sysdeps/powerpc/powerpc64/multiarch/strncpy.c b/sysdeps/powerpc/powerpc64/multiarch/strncpy.c
9bb5d6
index 7bacf28aca..af8b6cdd9c 100644
9bb5d6
--- a/sysdeps/powerpc/powerpc64/multiarch/strncpy.c
9bb5d6
+++ b/sysdeps/powerpc/powerpc64/multiarch/strncpy.c
9bb5d6
@@ -28,11 +28,19 @@
9bb5d6
 extern __typeof (strncpy) __strncpy_ppc attribute_hidden;
9bb5d6
 extern __typeof (strncpy) __strncpy_power7 attribute_hidden;
9bb5d6
 extern __typeof (strncpy) __strncpy_power8 attribute_hidden;
9bb5d6
+# ifdef __LITTLE_ENDIAN__
9bb5d6
+extern __typeof (strncpy) __strncpy_power9 attribute_hidden;
9bb5d6
+# endif
9bb5d6
 # undef strncpy
9bb5d6
 
9bb5d6
 /* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
9bb5d6
  ifunc symbol properly. */
9bb5d6
 libc_ifunc_redirected (__redirect_strncpy, strncpy,
9bb5d6
+# ifdef __LITTLE_ENDIAN__
9bb5d6
+		       (hwcap2 & PPC_FEATURE2_ARCH_3_00) &&
9bb5d6
+		       (hwcap & PPC_FEATURE_HAS_VSX)
9bb5d6
+		       ? __strncpy_power9 :
9bb5d6
+# endif
9bb5d6
 		       (hwcap2 & PPC_FEATURE2_ARCH_2_07)
9bb5d6
 		       ? __strncpy_power8
9bb5d6
 		       : (hwcap & PPC_FEATURE_HAS_VSX)