|
|
8a984d |
commit e941e0ae80626b7661c1db8953a673cafd3b8b19
|
|
|
8a984d |
Author: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
|
|
|
8a984d |
Date: Fri Apr 30 18:12:08 2021 -0300
|
|
|
8a984d |
|
|
|
8a984d |
powerpc64le: Optimize memcpy for POWER10
|
|
|
8a984d |
|
|
|
8a984d |
This implementation is based on __memcpy_power8_cached and integrates
|
|
|
8a984d |
suggestions from Anton Blanchard.
|
|
|
8a984d |
It benefits from loads and stores with length for short lengths and for
|
|
|
8a984d |
tail code, simplifying the code.
|
|
|
8a984d |
|
|
|
8a984d |
All unaligned memory accesses use instructions that do not generate
|
|
|
8a984d |
alignment interrupts on POWER10, making it safe to use on
|
|
|
8a984d |
caching-inhibited memory.
|
|
|
8a984d |
|
|
|
8a984d |
The main loop has also been modified in order to increase instruction
|
|
|
8a984d |
throughput by reducing the dependency on updates from previous iterations.
|
|
|
8a984d |
|
|
|
8a984d |
On average, this implementation provides around 30% improvement when
|
|
|
8a984d |
compared to __memcpy_power7 and 10% improvement in comparison to
|
|
|
8a984d |
__memcpy_power8_cached.
|
|
|
8a984d |
|
|
|
8a984d |
diff --git a/sysdeps/powerpc/powerpc64/le/power10/memcpy.S b/sysdeps/powerpc/powerpc64/le/power10/memcpy.S
|
|
|
8a984d |
new file mode 100644
|
|
|
8a984d |
index 0000000000000000..ad1414db4a3a8b9f
|
|
|
8a984d |
--- /dev/null
|
|
|
8a984d |
+++ b/sysdeps/powerpc/powerpc64/le/power10/memcpy.S
|
|
|
8a984d |
@@ -0,0 +1,198 @@
|
|
|
8a984d |
+/* Optimized memcpy implementation for POWER10.
|
|
|
8a984d |
+ Copyright (C) 2021 Free Software Foundation, Inc.
|
|
|
8a984d |
+ This file is part of the GNU C Library.
|
|
|
8a984d |
+
|
|
|
8a984d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
8a984d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
8a984d |
+ License as published by the Free Software Foundation; either
|
|
|
8a984d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
8a984d |
+
|
|
|
8a984d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
8a984d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
8a984d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
8a984d |
+ Lesser General Public License for more details.
|
|
|
8a984d |
+
|
|
|
8a984d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
8a984d |
+ License along with the GNU C Library; if not, see
|
|
|
8a984d |
+ <http://www.gnu.org/licenses/>. */
|
|
|
8a984d |
+
|
|
|
8a984d |
+#include <sysdep.h>
|
|
|
8a984d |
+
|
|
|
8a984d |
+
|
|
|
8a984d |
+#ifndef MEMCPY
|
|
|
8a984d |
+# define MEMCPY memcpy
|
|
|
8a984d |
+#endif
|
|
|
8a984d |
+
|
|
|
8a984d |
+/* __ptr_t [r3] memcpy (__ptr_t dst [r3], __ptr_t src [r4], size_t len [r5]);
|
|
|
8a984d |
+ Returns 'dst'. */
|
|
|
8a984d |
+
|
|
|
8a984d |
+ .machine power9
|
|
|
8a984d |
+ENTRY_TOCLESS (MEMCPY, 5)
|
|
|
8a984d |
+ CALL_MCOUNT 3
|
|
|
8a984d |
+
|
|
|
8a984d |
+ /* Copy up to 16 bytes. */
|
|
|
8a984d |
+ sldi r6,r5,56 /* Prepare [l|st]xvl counter. */
|
|
|
8a984d |
+ lxvl v10,r4,r6
|
|
|
8a984d |
+ stxvl v10,r3,r6
|
|
|
8a984d |
+ subic. r6,r5,16 /* Return if len <= 16. */
|
|
|
8a984d |
+ blelr
|
|
|
8a984d |
+
|
|
|
8a984d |
+ /* If len >= 256, assume nothing got copied before and copy
|
|
|
8a984d |
+ again. This might cause issues with overlapped memory, but memcpy
|
|
|
8a984d |
+ is not expected to treat overlapped memory. */
|
|
|
8a984d |
+ cmpdi r5,256
|
|
|
8a984d |
+ bge L(copy_ge_256)
|
|
|
8a984d |
+ /* 16 < len < 256 and the first 16 bytes have already been copied. */
|
|
|
8a984d |
+ addi r10,r3,16 /* Keep r3 intact as return value. */
|
|
|
8a984d |
+ addi r4,r4,16
|
|
|
8a984d |
+ subi r5,r5,16
|
|
|
8a984d |
+ b L(copy_lt_256) /* Avoid the main loop if len < 256. */
|
|
|
8a984d |
+
|
|
|
8a984d |
+ .p2align 5
|
|
|
8a984d |
+L(copy_ge_256):
|
|
|
8a984d |
+ mr r10,r3 /* Keep r3 intact as return value. */
|
|
|
8a984d |
+ /* Align dst to 16 bytes. */
|
|
|
8a984d |
+ andi. r9,r10,0xf
|
|
|
8a984d |
+ beq L(dst_is_align_16)
|
|
|
8a984d |
+ lxv v10,0(r4)
|
|
|
8a984d |
+ subfic r12,r9,16
|
|
|
8a984d |
+ subf r5,r12,r5
|
|
|
8a984d |
+ add r4,r4,r12
|
|
|
8a984d |
+ stxv v10,0(r3)
|
|
|
8a984d |
+ add r10,r3,r12
|
|
|
8a984d |
+
|
|
|
8a984d |
+L(dst_is_align_16):
|
|
|
8a984d |
+ srdi r9,r5,7 /* Divide by 128. */
|
|
|
8a984d |
+ mtctr r9
|
|
|
8a984d |
+ addi r6,r4,64
|
|
|
8a984d |
+ addi r7,r10,64
|
|
|
8a984d |
+
|
|
|
8a984d |
+
|
|
|
8a984d |
+ /* Main loop, copy 128 bytes per iteration.
|
|
|
8a984d |
+ Use r6=src+64 and r7=dest+64 in order to reduce the dependency on
|
|
|
8a984d |
+ r4 and r10. */
|
|
|
8a984d |
+ .p2align 5
|
|
|
8a984d |
+L(copy_128):
|
|
|
8a984d |
+
|
|
|
8a984d |
+ lxv v10, 0(r4)
|
|
|
8a984d |
+ lxv v11, 16(r4)
|
|
|
8a984d |
+ lxv v12, 32(r4)
|
|
|
8a984d |
+ lxv v13, 48(r4)
|
|
|
8a984d |
+
|
|
|
8a984d |
+ addi r4,r4,128
|
|
|
8a984d |
+
|
|
|
8a984d |
+ stxv v10, 0(r10)
|
|
|
8a984d |
+ stxv v11, 16(r10)
|
|
|
8a984d |
+ stxv v12, 32(r10)
|
|
|
8a984d |
+ stxv v13, 48(r10)
|
|
|
8a984d |
+
|
|
|
8a984d |
+ addi r10,r10,128
|
|
|
8a984d |
+
|
|
|
8a984d |
+ lxv v10, 0(r6)
|
|
|
8a984d |
+ lxv v11, 16(r6)
|
|
|
8a984d |
+ lxv v12, 32(r6)
|
|
|
8a984d |
+ lxv v13, 48(r6)
|
|
|
8a984d |
+
|
|
|
8a984d |
+ addi r6,r6,128
|
|
|
8a984d |
+
|
|
|
8a984d |
+ stxv v10, 0(r7)
|
|
|
8a984d |
+ stxv v11, 16(r7)
|
|
|
8a984d |
+ stxv v12, 32(r7)
|
|
|
8a984d |
+ stxv v13, 48(r7)
|
|
|
8a984d |
+
|
|
|
8a984d |
+ addi r7,r7,128
|
|
|
8a984d |
+
|
|
|
8a984d |
+ bdnz L(copy_128)
|
|
|
8a984d |
+
|
|
|
8a984d |
+ clrldi. r5,r5,64-7 /* Have we copied everything? */
|
|
|
8a984d |
+ beqlr
|
|
|
8a984d |
+
|
|
|
8a984d |
+ .p2align 5
|
|
|
8a984d |
+L(copy_lt_256):
|
|
|
8a984d |
+ cmpdi r5,16
|
|
|
8a984d |
+ ble L(copy_le_16)
|
|
|
8a984d |
+ srdi. r9,r5,5 /* Divide by 32. */
|
|
|
8a984d |
+ beq L(copy_lt_32)
|
|
|
8a984d |
+ mtctr r9
|
|
|
8a984d |
+ /* Use r6=src+32, r7=dest+32, r8=src+64, r9=dest+64 in order to reduce
|
|
|
8a984d |
+ the dependency on r4 and r10. */
|
|
|
8a984d |
+ addi r6,r4,32
|
|
|
8a984d |
+ addi r7,r10,32
|
|
|
8a984d |
+ addi r8,r4,64
|
|
|
8a984d |
+ addi r9,r10,64
|
|
|
8a984d |
+
|
|
|
8a984d |
+ .p2align 5
|
|
|
8a984d |
+ /* Copy 32 bytes at a time, unaligned.
|
|
|
8a984d |
+ The loop is unrolled 3 times in order to reduce the dependency on
|
|
|
8a984d |
+ r4 and r10, copying up-to 96 bytes per iteration. */
|
|
|
8a984d |
+L(copy_32):
|
|
|
8a984d |
+ lxv v10, 0(r4)
|
|
|
8a984d |
+ lxv v11, 16(r4)
|
|
|
8a984d |
+ stxv v10, 0(r10)
|
|
|
8a984d |
+ stxv v11, 16(r10)
|
|
|
8a984d |
+ bdz L(end_copy_32a)
|
|
|
8a984d |
+ addi r4,r4,96
|
|
|
8a984d |
+ addi r10,r10,96
|
|
|
8a984d |
+
|
|
|
8a984d |
+ lxv v10, 0(r6)
|
|
|
8a984d |
+ lxv v11, 16(r6)
|
|
|
8a984d |
+ addi r6,r6,96
|
|
|
8a984d |
+ stxv v10, 0(r7)
|
|
|
8a984d |
+ stxv v11, 16(r7)
|
|
|
8a984d |
+ bdz L(end_copy_32b)
|
|
|
8a984d |
+ addi r7,r7,96
|
|
|
8a984d |
+
|
|
|
8a984d |
+ lxv v12, 0(r8)
|
|
|
8a984d |
+ lxv v13, 16(r8)
|
|
|
8a984d |
+ addi r8,r8,96
|
|
|
8a984d |
+ stxv v12, 0(r9)
|
|
|
8a984d |
+ stxv v13, 16(r9)
|
|
|
8a984d |
+ addi r9,r9,96
|
|
|
8a984d |
+ bdnz L(copy_32)
|
|
|
8a984d |
+
|
|
|
8a984d |
+ clrldi. r5,r5,64-5 /* Have we copied everything? */
|
|
|
8a984d |
+ beqlr
|
|
|
8a984d |
+ cmpdi r5,16
|
|
|
8a984d |
+ ble L(copy_le_16)
|
|
|
8a984d |
+ b L(copy_lt_32)
|
|
|
8a984d |
+
|
|
|
8a984d |
+ .p2align 5
|
|
|
8a984d |
+L(end_copy_32a):
|
|
|
8a984d |
+ clrldi. r5,r5,64-5 /* Have we copied everything? */
|
|
|
8a984d |
+ beqlr
|
|
|
8a984d |
+ /* 32 bytes have been copied since the last update of r4 and r10. */
|
|
|
8a984d |
+ addi r4,r4,32
|
|
|
8a984d |
+ addi r10,r10,32
|
|
|
8a984d |
+ cmpdi r5,16
|
|
|
8a984d |
+ ble L(copy_le_16)
|
|
|
8a984d |
+ b L(copy_lt_32)
|
|
|
8a984d |
+
|
|
|
8a984d |
+ .p2align 5
|
|
|
8a984d |
+L(end_copy_32b):
|
|
|
8a984d |
+ clrldi. r5,r5,64-5 /* Have we copied everything? */
|
|
|
8a984d |
+ beqlr
|
|
|
8a984d |
+ /* The last iteration of the loop copied 64 bytes. Update r4 and r10
|
|
|
8a984d |
+ accordingly. */
|
|
|
8a984d |
+ addi r4,r4,-32
|
|
|
8a984d |
+ addi r10,r10,-32
|
|
|
8a984d |
+ cmpdi r5,16
|
|
|
8a984d |
+ ble L(copy_le_16)
|
|
|
8a984d |
+
|
|
|
8a984d |
+ .p2align 5
|
|
|
8a984d |
+L(copy_lt_32):
|
|
|
8a984d |
+ lxv v10, 0(r4)
|
|
|
8a984d |
+ stxv v10, 0(r10)
|
|
|
8a984d |
+ addi r4,r4,16
|
|
|
8a984d |
+ addi r10,r10,16
|
|
|
8a984d |
+ subi r5,r5,16
|
|
|
8a984d |
+
|
|
|
8a984d |
+ .p2align 5
|
|
|
8a984d |
+L(copy_le_16):
|
|
|
8a984d |
+ sldi r6,r5,56
|
|
|
8a984d |
+ lxvl v10,r4,r6
|
|
|
8a984d |
+ stxvl v10,r10,r6
|
|
|
8a984d |
+ blr
|
|
|
8a984d |
+
|
|
|
8a984d |
+
|
|
|
8a984d |
+END_GEN_TB (MEMCPY,TB_TOCLESS)
|
|
|
8a984d |
+libc_hidden_builtin_def (memcpy)
|
|
|
8a984d |
diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile
|
|
|
8a984d |
index 66f8c6ace9824d4a..2e3c8f2e8a81cda4 100644
|
|
|
8a984d |
--- a/sysdeps/powerpc/powerpc64/multiarch/Makefile
|
|
|
8a984d |
+++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile
|
|
|
8a984d |
@@ -32,7 +32,7 @@ sysdep_routines += memcpy-power8-cached memcpy-power7 memcpy-a2 memcpy-power6 \
|
|
|
8a984d |
strncase-power8
|
|
|
8a984d |
|
|
|
8a984d |
ifneq (,$(filter %le,$(config-machine)))
|
|
|
8a984d |
-sysdep_routines += memmove-power10 \
|
|
|
8a984d |
+sysdep_routines += memcpy-power10 memmove-power10 \
|
|
|
8a984d |
strcmp-power9 strncmp-power9 strcpy-power9 stpcpy-power9 \
|
|
|
8a984d |
rawmemchr-power9 strlen-power9 strncpy-power9 stpncpy-power9 \
|
|
|
8a984d |
strlen-power10
|
|
|
8a984d |
diff --git a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
|
|
|
8a984d |
index 4ce04bc51574cca1..9d5a14e480c02171 100644
|
|
|
8a984d |
--- a/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
|
|
|
8a984d |
+++ b/sysdeps/powerpc/powerpc64/multiarch/ifunc-impl-list.c
|
|
|
8a984d |
@@ -51,6 +51,12 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
|
|
|
8a984d |
#ifdef SHARED
|
|
|
8a984d |
/* Support sysdeps/powerpc/powerpc64/multiarch/memcpy.c. */
|
|
|
8a984d |
IFUNC_IMPL (i, name, memcpy,
|
|
|
8a984d |
+#ifdef __LITTLE_ENDIAN__
|
|
|
8a984d |
+ IFUNC_IMPL_ADD (array, i, memcpy,
|
|
|
8a984d |
+ hwcap2 & PPC_FEATURE2_ARCH_3_1
|
|
|
8a984d |
+ && hwcap & PPC_FEATURE_HAS_VSX,
|
|
|
8a984d |
+ __memcpy_power10)
|
|
|
8a984d |
+#endif
|
|
|
8a984d |
IFUNC_IMPL_ADD (array, i, memcpy, hwcap2 & PPC_FEATURE2_ARCH_2_07,
|
|
|
8a984d |
__memcpy_power8_cached)
|
|
|
8a984d |
IFUNC_IMPL_ADD (array, i, memcpy, hwcap & PPC_FEATURE_HAS_VSX,
|
|
|
8a984d |
diff --git a/sysdeps/powerpc/powerpc64/multiarch/memcpy-power10.S b/sysdeps/powerpc/powerpc64/multiarch/memcpy-power10.S
|
|
|
8a984d |
new file mode 100644
|
|
|
8a984d |
index 0000000000000000..70e0fc3ed610cdc3
|
|
|
8a984d |
--- /dev/null
|
|
|
8a984d |
+++ b/sysdeps/powerpc/powerpc64/multiarch/memcpy-power10.S
|
|
|
8a984d |
@@ -0,0 +1,26 @@
|
|
|
8a984d |
+/* Optimized memcpy implementation for POWER10.
|
|
|
8a984d |
+ Copyright (C) 2021 Free Software Foundation, Inc.
|
|
|
8a984d |
+ This file is part of the GNU C Library.
|
|
|
8a984d |
+
|
|
|
8a984d |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
8a984d |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
8a984d |
+ License as published by the Free Software Foundation; either
|
|
|
8a984d |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
8a984d |
+
|
|
|
8a984d |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
8a984d |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
8a984d |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
8a984d |
+ Lesser General Public License for more details.
|
|
|
8a984d |
+
|
|
|
8a984d |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
8a984d |
+ License along with the GNU C Library; if not, see
|
|
|
8a984d |
+ <https://www.gnu.org/licenses/>. */
|
|
|
8a984d |
+
|
|
|
8a984d |
+#if defined __LITTLE_ENDIAN__ && IS_IN (libc)
|
|
|
8a984d |
+#define MEMCPY __memcpy_power10
|
|
|
8a984d |
+
|
|
|
8a984d |
+#undef libc_hidden_builtin_def
|
|
|
8a984d |
+#define libc_hidden_builtin_def(name)
|
|
|
8a984d |
+
|
|
|
8a984d |
+#include <sysdeps/powerpc/powerpc64/le/power10/memcpy.S>
|
|
|
8a984d |
+#endif
|
|
|
8a984d |
diff --git a/sysdeps/powerpc/powerpc64/multiarch/memcpy.c b/sysdeps/powerpc/powerpc64/multiarch/memcpy.c
|
|
|
8a984d |
index 44dea594f3770673..be0e47f32dde2ccf 100644
|
|
|
8a984d |
--- a/sysdeps/powerpc/powerpc64/multiarch/memcpy.c
|
|
|
8a984d |
+++ b/sysdeps/powerpc/powerpc64/multiarch/memcpy.c
|
|
|
8a984d |
@@ -36,8 +36,15 @@ extern __typeof (__redirect_memcpy) __memcpy_power6 attribute_hidden;
|
|
|
8a984d |
extern __typeof (__redirect_memcpy) __memcpy_a2 attribute_hidden;
|
|
|
8a984d |
extern __typeof (__redirect_memcpy) __memcpy_power7 attribute_hidden;
|
|
|
8a984d |
extern __typeof (__redirect_memcpy) __memcpy_power8_cached attribute_hidden;
|
|
|
8a984d |
+# if defined __LITTLE_ENDIAN__
|
|
|
8a984d |
+extern __typeof (__redirect_memcpy) __memcpy_power10 attribute_hidden;
|
|
|
8a984d |
+# endif
|
|
|
8a984d |
|
|
|
8a984d |
libc_ifunc (__libc_memcpy,
|
|
|
8a984d |
+# if defined __LITTLE_ENDIAN__
|
|
|
8a984d |
+ (hwcap2 & PPC_FEATURE2_ARCH_3_1 && hwcap & PPC_FEATURE_HAS_VSX)
|
|
|
8a984d |
+ ? __memcpy_power10 :
|
|
|
8a984d |
+# endif
|
|
|
8a984d |
((hwcap2 & PPC_FEATURE2_ARCH_2_07) && use_cached_memopt)
|
|
|
8a984d |
? __memcpy_power8_cached :
|
|
|
8a984d |
(hwcap & PPC_FEATURE_HAS_VSX)
|