588e70
commit dd59655e9371af86043b97e38953f43bd9496699
588e70
Author: Lucas A. M. Magalhaes <lamm@linux.ibm.com>
588e70
Date:   Fri Apr 30 18:12:08 2021 -0300
588e70
588e70
    powerpc64le: Optimized memmove for POWER10
588e70
    
588e70
    This patch was initially based on the __memmove_power7 with some ideas
588e70
    from strncpy implementation for Power 9.
588e70
    
588e70
    Improvements from __memmove_power7:
588e70
    
588e70
    1. Use lxvl/stxvl for alignment code.
588e70
    
588e70
       The code for Power 7 uses branches when the input is not naturally
588e70
       aligned to the width of a vector. The new implementation uses
588e70
       lxvl/stxvl instead which reduces pressure on GPRs. It also allows
588e70
       the removal of branch instructions, implicitly removing branch stalls
588e70
       and mispredictions.
588e70
    
588e70
    2. Use of lxv/stxv and lxvl/stxvl pair is safe to use on Cache Inhibited
588e70
       memory.
588e70
    
588e70
       On Power 10 vector load and stores are safe to use on CI memory for
588e70
       addresses unaligned to 16B. This code takes advantage of this to
588e70
       do unaligned loads.
588e70
    
588e70
       The unaligned loads don't have a significant performance impact by
588e70
       themselves. However doing so decreases register pressure on GPRs
588e70
       and interdependence stalls on load/store pairs. This also improved
588e70
       readability as there are now less code paths for different alignments.
588e70
       Finally this reduces the overall code size.
588e70
    
588e70
    3. Improved performance.
588e70
    
588e70
       This version runs on average about 30% better than memmove_power7
588e70
       for lengths  larger than 8KB. For input lengths shorter than 8KB
588e70
       the improvement is smaller, it has on average about 17% better
588e70
       performance.
588e70
    
588e70
       This version has a degradation of about 50% for input lengths
588e70
       in the 0 to 31 bytes range when dest is unaligned.
588e70
    
588e70
    Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
588e70
588e70
diff --git a/sysdeps/powerpc/powerpc64/le/power10/memmove.S b/sysdeps/powerpc/powerpc64/le/power10/memmove.S
588e70
new file mode 100644
588e70
index 0000000000000000..7dfd57edeb37e8e4
588e70
--- /dev/null
588e70
+++ b/sysdeps/powerpc/powerpc64/le/power10/memmove.S
588e70
@@ -0,0 +1,320 @@
588e70
+/* Optimized memmove implementation for POWER10.
588e70
+   Copyright (C) 2021 Free Software Foundation, Inc.
588e70
+   This file is part of the GNU C Library.
588e70
+
588e70
+   The GNU C Library is free software; you can redistribute it and/or
588e70
+   modify it under the terms of the GNU Lesser General Public
588e70
+   License as published by the Free Software Foundation; either
588e70
+   version 2.1 of the License, or (at your option) any later version.
588e70
+
588e70
+   The GNU C Library is distributed in the hope that it will be useful,
588e70
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
588e70
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
588e70
+   Lesser General Public License for more details.
588e70
+
588e70
+   You should have received a copy of the GNU Lesser General Public
588e70
+   License along with the GNU C Library; if not, see
588e70
+   <https://www.gnu.org/licenses/>.  */
588e70
+
588e70
+#include <sysdep.h>
588e70
+
588e70
+
588e70
+/* void* [r3] memmove (void *dest [r3], const void *src [r4], size_t len [r5])
588e70
+
588e70
+   This optimization checks if 'src' and 'dst' overlap.  If they do not
588e70
+   or 'src' is ahead of 'dest' then it copies forward.
588e70
+   Otherwise, an optimized backward copy is used.  */
588e70
+
588e70
+#ifndef MEMMOVE
588e70
+# define MEMMOVE memmove
588e70
+#endif
588e70
+	.machine power9
588e70
+ENTRY_TOCLESS (MEMMOVE, 5)
588e70
+	CALL_MCOUNT 3
588e70
+
588e70
+L(_memmove):
588e70
+	.p2align 5
588e70
+	/* Check if there is overlap, if so it will branch to backward copy.  */
588e70
+	subf	r9,r4,r3
588e70
+	cmpld	cr7,r9,r5
588e70
+	blt	cr7,L(memmove_bwd)
588e70
+
588e70
+	/* Fast path for length shorter than 16 bytes.  */
588e70
+	sldi	r7,r5,56
588e70
+	lxvl	32+v2,r4,r7
588e70
+	stxvl	32+v2,r3,r7
588e70
+	subic.	r8,r5,16
588e70
+	blelr
588e70
+
588e70
+	/* For shorter lengths aligning the dest address to 16 bytes either
588e70
+	   decreases performance or is irrelevant.  I'm making use of this
588e70
+	   comparison to skip the alignment in.  */
588e70
+	cmpldi	cr6,r5,256
588e70
+	bge	cr6,L(ge_256)
588e70
+	/* Account for the first 16-byte copy.  */
588e70
+	addi	r4,r4,16
588e70
+	addi	r11,r3,16	/* use r11 to keep dest address on r3.  */
588e70
+	subi	r5,r5,16
588e70
+	b	L(loop_head)
588e70
+
588e70
+	.p2align 5
588e70
+L(ge_256):
588e70
+	/* Account for the first copy <= 16 bytes.  This is necessary for
588e70
+	   memmove because at this point the src address can be in front of the
588e70
+	   dest address.  */
588e70
+	clrldi	r9,r5,56
588e70
+	li	r8,16
588e70
+	cmpldi	r9,16
588e70
+	iselgt	r9,r8,r9
588e70
+	add	r4,r4,r9
588e70
+	add	r11,r3,r9	/* use r11 to keep dest address on r3.  */
588e70
+	sub	r5,r5,r9
588e70
+
588e70
+	/* Align dest to 16 bytes.  */
588e70
+	neg	r7,r3
588e70
+	clrldi.	r9,r7,60
588e70
+	beq	L(loop_head)
588e70
+
588e70
+	.p2align 5
588e70
+	sldi	r6,r9,56
588e70
+	lxvl	32+v0,r4,r6
588e70
+	stxvl	32+v0,r11,r6
588e70
+	sub	r5,r5,r9
588e70
+	add	r4,r4,r9
588e70
+	add	r11,r11,r9
588e70
+
588e70
+L(loop_head):
588e70
+	cmpldi	r5,63
588e70
+	ble	L(final_64)
588e70
+
588e70
+	srdi.	r7,r5,7
588e70
+	beq	L(loop_tail)
588e70
+
588e70
+	mtctr	r7
588e70
+
588e70
+/* Main loop that copies 128 bytes each iteration.  */
588e70
+	.p2align 5
588e70
+L(loop):
588e70
+	addi	r9,r4,64
588e70
+	addi	r10,r11,64
588e70
+
588e70
+	lxv	32+v0,0(r4)
588e70
+	lxv	32+v1,16(r4)
588e70
+	lxv	32+v2,32(r4)
588e70
+	lxv	32+v3,48(r4)
588e70
+
588e70
+	stxv	32+v0,0(r11)
588e70
+	stxv	32+v1,16(r11)
588e70
+	stxv	32+v2,32(r11)
588e70
+	stxv	32+v3,48(r11)
588e70
+
588e70
+	addi	r4,r4,128
588e70
+	addi	r11,r11,128
588e70
+
588e70
+	lxv	32+v4,0(r9)
588e70
+	lxv	32+v5,16(r9)
588e70
+	lxv	32+v6,32(r9)
588e70
+	lxv	32+v7,48(r9)
588e70
+
588e70
+	stxv	32+v4,0(r10)
588e70
+	stxv	32+v5,16(r10)
588e70
+	stxv	32+v6,32(r10)
588e70
+	stxv	32+v7,48(r10)
588e70
+
588e70
+	bdnz	L(loop)
588e70
+	clrldi.	r5,r5,57
588e70
+	beqlr
588e70
+
588e70
+/* Copy 64 bytes.  */
588e70
+	.p2align 5
588e70
+L(loop_tail):
588e70
+	cmpldi 	cr5,r5,63
588e70
+	ble	cr5,L(final_64)
588e70
+
588e70
+	lxv	32+v0,0(r4)
588e70
+	lxv	32+v1,16(r4)
588e70
+	lxv	32+v2,32(r4)
588e70
+	lxv	32+v3,48(r4)
588e70
+
588e70
+	stxv	32+v0,0(r11)
588e70
+	stxv	32+v1,16(r11)
588e70
+	stxv	32+v2,32(r11)
588e70
+	stxv	32+v3,48(r11)
588e70
+
588e70
+	addi	r4,r4,64
588e70
+	addi	r11,r11,64
588e70
+	subi	r5,r5,64
588e70
+
588e70
+/* Copies the last 1-63 bytes.  */
588e70
+	.p2align 5
588e70
+L(final_64):
588e70
+	/* r8 holds the number of bytes that will be copied with lxv/stxv.  */
588e70
+	clrrdi.	r8,r5,4
588e70
+	beq	L(tail1)
588e70
+
588e70
+	cmpldi  cr5,r5,32
588e70
+	lxv	32+v0,0(r4)
588e70
+	blt	cr5,L(tail2)
588e70
+
588e70
+	cmpldi	cr6,r5,48
588e70
+	lxv	32+v1,16(r4)
588e70
+	blt	cr6,L(tail3)
588e70
+
588e70
+	.p2align 5
588e70
+	lxv	32+v2,32(r4)
588e70
+	stxv	32+v2,32(r11)
588e70
+L(tail3):
588e70
+	stxv	32+v1,16(r11)
588e70
+L(tail2):
588e70
+	stxv	32+v0,0(r11)
588e70
+	sub	r5,r5,r8
588e70
+	add	r4,r4,r8
588e70
+	add	r11,r11,r8
588e70
+	.p2align 5
588e70
+L(tail1):
588e70
+	sldi	r6,r5,56
588e70
+	lxvl	v4,r4,r6
588e70
+	stxvl	v4,r11,r6
588e70
+	blr
588e70
+
588e70
+/* If dest and src overlap, we should copy backwards.  */
588e70
+L(memmove_bwd):
588e70
+	add	r11,r3,r5
588e70
+	add	r4,r4,r5
588e70
+
588e70
+	/* Optimization for length smaller than 16 bytes.  */
588e70
+	cmpldi	cr5,r5,15
588e70
+	ble	cr5,L(tail1_bwd)
588e70
+
588e70
+	/* For shorter lengths the alignment either slows down or is irrelevant.
588e70
+	   The forward copy uses a already need 256 comparison for that.  Here
588e70
+	   it's using 128 as it will reduce code and improve readability.  */
588e70
+	cmpldi	cr7,r5,128
588e70
+	blt	cr7,L(bwd_loop_tail)
588e70
+
588e70
+	/* Align dest address to 16 bytes.  */
588e70
+	.p2align 5
588e70
+	clrldi.	r9,r11,60
588e70
+	beq	L(bwd_loop_head)
588e70
+	sub	r4,r4,r9
588e70
+	sub	r11,r11,r9
588e70
+	lxv	32+v0,0(r4)
588e70
+	sldi	r6,r9,56
588e70
+	stxvl   32+v0,r11,r6
588e70
+	sub	r5,r5,r9
588e70
+
588e70
+L(bwd_loop_head):
588e70
+	srdi.	r7,r5,7
588e70
+	beq	L(bwd_loop_tail)
588e70
+
588e70
+	mtctr	r7
588e70
+
588e70
+/* Main loop that copies 128 bytes every iteration.  */
588e70
+	.p2align 5
588e70
+L(bwd_loop):
588e70
+	addi	r9,r4,-64
588e70
+	addi	r10,r11,-64
588e70
+
588e70
+	lxv	32+v0,-16(r4)
588e70
+	lxv	32+v1,-32(r4)
588e70
+	lxv	32+v2,-48(r4)
588e70
+	lxv	32+v3,-64(r4)
588e70
+
588e70
+	stxv	32+v0,-16(r11)
588e70
+	stxv	32+v1,-32(r11)
588e70
+	stxv	32+v2,-48(r11)
588e70
+	stxv	32+v3,-64(r11)
588e70
+
588e70
+	addi	r4,r4,-128
588e70
+	addi	r11,r11,-128
588e70
+
588e70
+	lxv	32+v0,-16(r9)
588e70
+	lxv	32+v1,-32(r9)
588e70
+	lxv	32+v2,-48(r9)
588e70
+	lxv	32+v3,-64(r9)
588e70
+
588e70
+	stxv	32+v0,-16(r10)
588e70
+	stxv	32+v1,-32(r10)
588e70
+	stxv	32+v2,-48(r10)
588e70
+	stxv	32+v3,-64(r10)
588e70
+
588e70
+	bdnz	L(bwd_loop)
588e70
+	clrldi.	r5,r5,57
588e70
+	beqlr
588e70
+
588e70
+/* Copy 64 bytes.  */
588e70
+	.p2align 5
588e70
+L(bwd_loop_tail):
588e70
+	cmpldi 	cr5,r5,63
588e70
+	ble	cr5,L(bwd_final_64)
588e70
+
588e70
+	addi	r4,r4,-64
588e70
+	addi	r11,r11,-64
588e70
+
588e70
+	lxv	32+v0,0(r4)
588e70
+	lxv	32+v1,16(r4)
588e70
+	lxv	32+v2,32(r4)
588e70
+	lxv	32+v3,48(r4)
588e70
+
588e70
+	stxv	32+v0,0(r11)
588e70
+	stxv	32+v1,16(r11)
588e70
+	stxv	32+v2,32(r11)
588e70
+	stxv	32+v3,48(r11)
588e70
+
588e70
+	subi	r5,r5,64
588e70
+
588e70
+/* Copies the last 1-63 bytes.  */
588e70
+	.p2align 5
588e70
+L(bwd_final_64):
588e70
+	/* r8 holds the number of bytes that will be copied with lxv/stxv.  */
588e70
+	clrrdi.	r8,r5,4
588e70
+	beq	L(tail1_bwd)
588e70
+
588e70
+	cmpldi	cr5,r5,32
588e70
+	lxv	32+v2,-16(r4)
588e70
+	blt	cr5,L(tail2_bwd)
588e70
+
588e70
+	cmpldi	cr6,r5,48
588e70
+	lxv	32+v1,-32(r4)
588e70
+	blt	cr6,L(tail3_bwd)
588e70
+
588e70
+	.p2align 5
588e70
+	lxv	32+v0,-48(r4)
588e70
+	stxv	32+v0,-48(r11)
588e70
+L(tail3_bwd):
588e70
+	stxv	32+v1,-32(r11)
588e70
+L(tail2_bwd):
588e70
+	stxv	32+v2,-16(r11)
588e70
+	sub	r4,r4,r5
588e70
+	sub	r11,r11,r5
588e70
+	sub	r5,r5,r8
588e70
+	sldi	r6,r5,56
588e70
+	lxvl	v4,r4,r6
588e70
+	stxvl	v4,r11,r6
588e70
+	blr
588e70
+
588e70
+/* Copy last 16 bytes.  */
588e70
+	.p2align 5
588e70
+L(tail1_bwd):
588e70
+	sub	r4,r4,r5
588e70
+	sub	r11,r11,r5
588e70
+	sldi	r6,r5,56
588e70
+	lxvl	v4,r4,r6
588e70
+	stxvl	v4,r11,r6
588e70
+	blr
588e70
+
588e70
+END_GEN_TB (MEMMOVE,TB_TOCLESS)
588e70
+libc_hidden_builtin_def (memmove)
588e70
+
588e70
+/* void bcopy(const void *src [r3], void *dest [r4], size_t n [r5])
588e70
+   Implemented in this file to avoid linker create a stub function call
588e70
+   in the branch to '_memmove'.  */
588e70
+ENTRY_TOCLESS (__bcopy)
588e70
+	mr	r6,r3
588e70
+	mr	r3,r4
588e70
+	mr	r4,r6
588e70
+	b	L(_memmove)
588e70
+END (__bcopy)
588e70
+#ifndef __bcopy
588e70
+weak_alias (__bcopy, bcopy)
588e70
+#endif
588e70
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
588e70
index 61652b65dd223018..66f8c6ace9824d4a 100644
588e70
--- a/sysdeps/powerpc/powerpc64/multiarch/Makefile
588e70
+++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile
588e70
@@ -32,7 +32,8 @@ sysdep_routines += memcpy-power8-cached memcpy-power7 memcpy-a2 memcpy-power6 \
588e70
 		   strncase-power8
588e70
 
588e70
 ifneq (,$(filter %le,$(config-machine)))
588e70
-sysdep_routines += strcmp-power9 strncmp-power9 strcpy-power9 stpcpy-power9 \
588e70
+sysdep_routines += memmove-power10 \
588e70
+		   strcmp-power9 strncmp-power9 strcpy-power9 stpcpy-power9 \
588e70
 		   rawmemchr-power9 strlen-power9 strncpy-power9 stpncpy-power9 \
588e70
 		   strlen-power10
588e70
 endif
588e70
diff --git a/sysdeps/powerpc/powerpc64/multiarch/bcopy.c b/sysdeps/powerpc/powerpc64/multiarch/bcopy.c
588e70
index 1c4a229b1fc5654a..705fef33d4e57557 100644
588e70
--- a/sysdeps/powerpc/powerpc64/multiarch/bcopy.c
588e70
+++ b/sysdeps/powerpc/powerpc64/multiarch/bcopy.c
588e70
@@ -22,8 +22,17 @@
588e70
 extern __typeof (bcopy) __bcopy_ppc attribute_hidden;
588e70
 /* __bcopy_power7 symbol is implemented at memmove-power7.S  */
588e70
 extern __typeof (bcopy) __bcopy_power7 attribute_hidden;
588e70
+#ifdef __LITTLE_ENDIAN__
588e70
+extern __typeof (bcopy) __bcopy_power10 attribute_hidden;
588e70
+#endif
588e70
 
588e70
 libc_ifunc (bcopy,
588e70
+#ifdef __LITTLE_ENDIAN__
588e70
+	     hwcap2 & (PPC_FEATURE2_ARCH_3_1 |
588e70
+		       PPC_FEATURE2_HAS_ISEL)
588e70
+	     && (hwcap & PPC_FEATURE_HAS_VSX)
588e70
+	     ? __bcopy_power10 :
588e70
+#endif
588e70
             (hwcap & PPC_FEATURE_HAS_VSX)
588e70
             ? __bcopy_power7
588e70
             : __bcopy_ppc);
588e70
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
588e70
index 46d5956adda72b86..4ce04bc51574cca1 100644
588e70
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
588e70
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
588e70
@@ -67,6 +67,13 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
588e70
 
588e70
   /* Support sysdeps/powerpc/powerpc64/multiarch/memmove.c.  */
588e70
   IFUNC_IMPL (i, name, memmove,
588e70
+#ifdef __LITTLE_ENDIAN__
588e70
+	      IFUNC_IMPL_ADD (array, i, memmove,
588e70
+			      hwcap2 & (PPC_FEATURE2_ARCH_3_1 |
588e70
+					PPC_FEATURE2_HAS_ISEL)
588e70
+			      && (hwcap & PPC_FEATURE_HAS_VSX),
588e70
+			      __memmove_power10)
588e70
+#endif
588e70
 	      IFUNC_IMPL_ADD (array, i, memmove, hwcap & PPC_FEATURE_HAS_VSX,
588e70
 			      __memmove_power7)
588e70
 	      IFUNC_IMPL_ADD (array, i, memmove, 1, __memmove_ppc))
588e70
@@ -186,6 +193,13 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
588e70
 
588e70
   /* Support sysdeps/powerpc/powerpc64/multiarch/bcopy.c.  */
588e70
   IFUNC_IMPL (i, name, bcopy,
588e70
+#ifdef __LITTLE_ENDIAN__
588e70
+	      IFUNC_IMPL_ADD (array, i, bcopy,
588e70
+			      hwcap2 & (PPC_FEATURE2_ARCH_3_1 |
588e70
+					PPC_FEATURE2_HAS_ISEL)
588e70
+			      && (hwcap & PPC_FEATURE_HAS_VSX),
588e70
+			      __bcopy_power10)
588e70
+#endif
588e70
 	      IFUNC_IMPL_ADD (array, i, bcopy, hwcap & PPC_FEATURE_HAS_VSX,
588e70
 			      __bcopy_power7)
588e70
 	      IFUNC_IMPL_ADD (array, i, bcopy, 1, __bcopy_ppc))
588e70
diff --git a/sysdeps/powerpc/powerpc64/multiarch/memmove-power10.S b/sysdeps/powerpc/powerpc64/multiarch/memmove-power10.S
588e70
new file mode 100644
588e70
index 0000000000000000..171b32921a0a4d47
588e70
--- /dev/null
588e70
+++ b/sysdeps/powerpc/powerpc64/multiarch/memmove-power10.S
588e70
@@ -0,0 +1,27 @@
588e70
+/* Optimized memmove implementation for POWER10.
588e70
+   Copyright (C) 2021 Free Software Foundation, Inc.
588e70
+   This file is part of the GNU C Library.
588e70
+
588e70
+   The GNU C Library is free software; you can redistribute it and/or
588e70
+   modify it under the terms of the GNU Lesser General Public
588e70
+   License as published by the Free Software Foundation; either
588e70
+   version 2.1 of the License, or (at your option) any later version.
588e70
+
588e70
+   The GNU C Library is distributed in the hope that it will be useful,
588e70
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
588e70
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
588e70
+   Lesser General Public License for more details.
588e70
+
588e70
+   You should have received a copy of the GNU Lesser General Public
588e70
+   License along with the GNU C Library; if not, see
588e70
+   <https://www.gnu.org/licenses/>.  */
588e70
+
588e70
+#define MEMMOVE __memmove_power10
588e70
+
588e70
+#undef libc_hidden_builtin_def
588e70
+#define libc_hidden_builtin_def(name)
588e70
+
588e70
+#undef __bcopy
588e70
+#define __bcopy __bcopy_power10
588e70
+
588e70
+#include <sysdeps/powerpc/powerpc64/le/power10/memmove.S>
588e70
diff --git a/sysdeps/powerpc/powerpc64/multiarch/memmove-power7.S b/sysdeps/powerpc/powerpc64/multiarch/memmove-power7.S
588e70
index 0b251d0f5f087874..fb5261ecda64d061 100644
588e70
--- a/sysdeps/powerpc/powerpc64/multiarch/memmove-power7.S
588e70
+++ b/sysdeps/powerpc/powerpc64/multiarch/memmove-power7.S
588e70
@@ -21,7 +21,7 @@
588e70
 #undef libc_hidden_builtin_def
588e70
 #define libc_hidden_builtin_def(name)
588e70
 
588e70
-#undef bcopy
588e70
-#define bcopy __bcopy_power7
588e70
+#undef __bcopy
588e70
+#define __bcopy __bcopy_power7
588e70
 
588e70
 #include <sysdeps/powerpc/powerpc64/power7/memmove.S>
588e70
diff --git a/sysdeps/powerpc/powerpc64/multiarch/memmove.c b/sysdeps/powerpc/powerpc64/multiarch/memmove.c
588e70
index 39987155cc7d3624..2fd7b6d309e4bedd 100644
588e70
--- a/sysdeps/powerpc/powerpc64/multiarch/memmove.c
588e70
+++ b/sysdeps/powerpc/powerpc64/multiarch/memmove.c
588e70
@@ -28,14 +28,22 @@
588e70
 # include "init-arch.h"
588e70
 
588e70
 extern __typeof (__redirect_memmove) __libc_memmove;
588e70
-
588e70
 extern __typeof (__redirect_memmove) __memmove_ppc attribute_hidden;
588e70
 extern __typeof (__redirect_memmove) __memmove_power7 attribute_hidden;
588e70
+#ifdef __LITTLE_ENDIAN__
588e70
+extern __typeof (__redirect_memmove) __memmove_power10 attribute_hidden;
588e70
+#endif
588e70
 
588e70
 libc_ifunc (__libc_memmove,
588e70
-            (hwcap & PPC_FEATURE_HAS_VSX)
588e70
-            ? __memmove_power7
588e70
-            : __memmove_ppc);
588e70
+#ifdef __LITTLE_ENDIAN__
588e70
+	     hwcap2 & (PPC_FEATURE2_ARCH_3_1 |
588e70
+		       PPC_FEATURE2_HAS_ISEL)
588e70
+	     && (hwcap & PPC_FEATURE_HAS_VSX)
588e70
+	     ? __memmove_power10 :
588e70
+#endif
588e70
+		     (hwcap & PPC_FEATURE_HAS_VSX)
588e70
+		     ? __memmove_power7
588e70
+		     : __memmove_ppc);
588e70
 
588e70
 #undef memmove
588e70
 strong_alias (__libc_memmove, memmove);
588e70
diff --git a/sysdeps/powerpc/powerpc64/power7/memmove.S b/sysdeps/powerpc/powerpc64/power7/memmove.S
588e70
index b7f3dc28d1a8eac3..9e4cabb07ef9b732 100644
588e70
--- a/sysdeps/powerpc/powerpc64/power7/memmove.S
588e70
+++ b/sysdeps/powerpc/powerpc64/power7/memmove.S
588e70
@@ -832,4 +832,6 @@ ENTRY_TOCLESS (__bcopy)
588e70
 	mr	r4,r6
588e70
 	b	L(_memmove)
588e70
 END (__bcopy)
588e70
+#ifndef __bcopy
588e70
 weak_alias (__bcopy, bcopy)
588e70
+#endif