|
|
190885 |
From cd2eeb1be618b5edfc9c6929c07201ff941b31d9 Mon Sep 17 00:00:00 2001
|
|
|
190885 |
From: "H.J. Lu" <hjl.tools@gmail.com>
|
|
|
190885 |
Date: Fri, 5 Mar 2021 07:20:28 -0800
|
|
|
190885 |
Subject: [PATCH] x86-64: Add memcmp family functions with 256-bit EVEX
|
|
|
190885 |
|
|
|
190885 |
Update ifunc-memcmp.h to select the function optimized with 256-bit EVEX
|
|
|
190885 |
instructions using YMM16-YMM31 registers to avoid RTM abort with usable
|
|
|
190885 |
AVX512VL, AVX512BW and MOVBE since VZEROUPPER isn't needed at function
|
|
|
190885 |
exit.
|
|
|
190885 |
|
|
|
190885 |
(cherry picked from commit 91264fe3577fe887b4860923fa6142b5274c8965)
|
|
|
190885 |
---
|
|
|
190885 |
sysdeps/x86_64/multiarch/Makefile | 4 +-
|
|
|
190885 |
sysdeps/x86_64/multiarch/ifunc-impl-list.c | 10 +
|
|
|
190885 |
sysdeps/x86_64/multiarch/ifunc-memcmp.h | 13 +-
|
|
|
190885 |
sysdeps/x86_64/multiarch/memcmp-evex-movbe.S | 440 ++++++++++++++++++
|
|
|
190885 |
sysdeps/x86_64/multiarch/wmemcmp-evex-movbe.S | 4 +
|
|
|
190885 |
5 files changed, 467 insertions(+), 4 deletions(-)
|
|
|
190885 |
create mode 100644 sysdeps/x86_64/multiarch/memcmp-evex-movbe.S
|
|
|
190885 |
create mode 100644 sysdeps/x86_64/multiarch/wmemcmp-evex-movbe.S
|
|
|
190885 |
|
|
|
190885 |
diff --git a/sysdeps/x86_64/multiarch/Makefile b/sysdeps/x86_64/multiarch/Makefile
|
|
|
190885 |
index 1cc0a10e..9d79b138 100644
|
|
|
190885 |
--- a/sysdeps/x86_64/multiarch/Makefile
|
|
|
190885 |
+++ b/sysdeps/x86_64/multiarch/Makefile
|
|
|
190885 |
@@ -41,6 +41,7 @@ sysdep_routines += strncat-c stpncpy-c strncpy-c \
|
|
|
190885 |
memset-avx2-unaligned-erms \
|
|
|
190885 |
memset-avx512-unaligned-erms \
|
|
|
190885 |
memchr-evex \
|
|
|
190885 |
+ memcmp-evex-movbe \
|
|
|
190885 |
memmove-evex-unaligned-erms \
|
|
|
190885 |
memrchr-evex \
|
|
|
190885 |
memset-evex-unaligned-erms \
|
|
|
190885 |
@@ -81,7 +82,8 @@ sysdep_routines += wmemcmp-sse4 wmemcmp-ssse3 wmemcmp-c \
|
|
|
190885 |
wcsncmp-evex \
|
|
|
190885 |
wcsnlen-evex \
|
|
|
190885 |
wcsrchr-evex \
|
|
|
190885 |
- wmemchr-evex
|
|
|
190885 |
+ wmemchr-evex \
|
|
|
190885 |
+ wmemcmp-evex-movbe
|
|
|
190885 |
endif
|
|
|
190885 |
|
|
|
190885 |
ifeq ($(subdir),debug)
|
|
|
190885 |
diff --git a/sysdeps/x86_64/multiarch/ifunc-impl-list.c b/sysdeps/x86_64/multiarch/ifunc-impl-list.c
|
|
|
190885 |
index 7cf83485..c8da910e 100644
|
|
|
190885 |
--- a/sysdeps/x86_64/multiarch/ifunc-impl-list.c
|
|
|
190885 |
+++ b/sysdeps/x86_64/multiarch/ifunc-impl-list.c
|
|
|
190885 |
@@ -56,6 +56,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
|
|
|
190885 |
(CPU_FEATURE_USABLE (AVX2)
|
|
|
190885 |
&& CPU_FEATURE_USABLE (MOVBE)),
|
|
|
190885 |
__memcmp_avx2_movbe)
|
|
|
190885 |
+ IFUNC_IMPL_ADD (array, i, memcmp,
|
|
|
190885 |
+ (CPU_FEATURE_USABLE (AVX512VL)
|
|
|
190885 |
+ && CPU_FEATURE_USABLE (AVX512BW)
|
|
|
190885 |
+ && CPU_FEATURE_USABLE (MOVBE)),
|
|
|
190885 |
+ __memcmp_evex_movbe)
|
|
|
190885 |
IFUNC_IMPL_ADD (array, i, memcmp, CPU_FEATURE_USABLE (SSE4_1),
|
|
|
190885 |
__memcmp_sse4_1)
|
|
|
190885 |
IFUNC_IMPL_ADD (array, i, memcmp, CPU_FEATURE_USABLE (SSSE3),
|
|
|
190885 |
@@ -558,6 +563,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
|
|
|
190885 |
(CPU_FEATURE_USABLE (AVX2)
|
|
|
190885 |
&& CPU_FEATURE_USABLE (MOVBE)),
|
|
|
190885 |
__wmemcmp_avx2_movbe)
|
|
|
190885 |
+ IFUNC_IMPL_ADD (array, i, wmemcmp,
|
|
|
190885 |
+ (CPU_FEATURE_USABLE (AVX512VL)
|
|
|
190885 |
+ && CPU_FEATURE_USABLE (AVX512BW)
|
|
|
190885 |
+ && CPU_FEATURE_USABLE (MOVBE)),
|
|
|
190885 |
+ __wmemcmp_evex_movbe)
|
|
|
190885 |
IFUNC_IMPL_ADD (array, i, wmemcmp, CPU_FEATURE_USABLE (SSE4_1),
|
|
|
190885 |
__wmemcmp_sse4_1)
|
|
|
190885 |
IFUNC_IMPL_ADD (array, i, wmemcmp, CPU_FEATURE_USABLE (SSSE3),
|
|
|
190885 |
diff --git a/sysdeps/x86_64/multiarch/ifunc-memcmp.h b/sysdeps/x86_64/multiarch/ifunc-memcmp.h
|
|
|
190885 |
index 6c1f3153..3ca1f0a6 100644
|
|
|
190885 |
--- a/sysdeps/x86_64/multiarch/ifunc-memcmp.h
|
|
|
190885 |
+++ b/sysdeps/x86_64/multiarch/ifunc-memcmp.h
|
|
|
190885 |
@@ -23,17 +23,24 @@ extern __typeof (REDIRECT_NAME) OPTIMIZE (sse2) attribute_hidden;
|
|
|
190885 |
extern __typeof (REDIRECT_NAME) OPTIMIZE (ssse3) attribute_hidden;
|
|
|
190885 |
extern __typeof (REDIRECT_NAME) OPTIMIZE (sse4_1) attribute_hidden;
|
|
|
190885 |
extern __typeof (REDIRECT_NAME) OPTIMIZE (avx2_movbe) attribute_hidden;
|
|
|
190885 |
+extern __typeof (REDIRECT_NAME) OPTIMIZE (evex_movbe) attribute_hidden;
|
|
|
190885 |
|
|
|
190885 |
static inline void *
|
|
|
190885 |
IFUNC_SELECTOR (void)
|
|
|
190885 |
{
|
|
|
190885 |
const struct cpu_features* cpu_features = __get_cpu_features ();
|
|
|
190885 |
|
|
|
190885 |
- if (!CPU_FEATURES_ARCH_P (cpu_features, Prefer_No_VZEROUPPER)
|
|
|
190885 |
- && CPU_FEATURE_USABLE_P (cpu_features, AVX2)
|
|
|
190885 |
+ if (CPU_FEATURE_USABLE_P (cpu_features, AVX2)
|
|
|
190885 |
&& CPU_FEATURE_USABLE_P (cpu_features, MOVBE)
|
|
|
190885 |
&& CPU_FEATURES_ARCH_P (cpu_features, AVX_Fast_Unaligned_Load))
|
|
|
190885 |
- return OPTIMIZE (avx2_movbe);
|
|
|
190885 |
+ {
|
|
|
190885 |
+ if (CPU_FEATURE_USABLE_P (cpu_features, AVX512VL)
|
|
|
190885 |
+ && CPU_FEATURE_USABLE_P (cpu_features, AVX512BW))
|
|
|
190885 |
+ return OPTIMIZE (evex_movbe);
|
|
|
190885 |
+
|
|
|
190885 |
+ if (!CPU_FEATURES_ARCH_P (cpu_features, Prefer_No_VZEROUPPER))
|
|
|
190885 |
+ return OPTIMIZE (avx2_movbe);
|
|
|
190885 |
+ }
|
|
|
190885 |
|
|
|
190885 |
if (CPU_FEATURE_USABLE_P (cpu_features, SSE4_1))
|
|
|
190885 |
return OPTIMIZE (sse4_1);
|
|
|
190885 |
diff --git a/sysdeps/x86_64/multiarch/memcmp-evex-movbe.S b/sysdeps/x86_64/multiarch/memcmp-evex-movbe.S
|
|
|
190885 |
new file mode 100644
|
|
|
190885 |
index 00000000..9c093972
|
|
|
190885 |
--- /dev/null
|
|
|
190885 |
+++ b/sysdeps/x86_64/multiarch/memcmp-evex-movbe.S
|
|
|
190885 |
@@ -0,0 +1,440 @@
|
|
|
190885 |
+/* memcmp/wmemcmp optimized with 256-bit EVEX instructions.
|
|
|
190885 |
+ Copyright (C) 2021 Free Software Foundation, Inc.
|
|
|
190885 |
+ This file is part of the GNU C Library.
|
|
|
190885 |
+
|
|
|
190885 |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
190885 |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
190885 |
+ License as published by the Free Software Foundation; either
|
|
|
190885 |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
190885 |
+
|
|
|
190885 |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
190885 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
190885 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
190885 |
+ Lesser General Public License for more details.
|
|
|
190885 |
+
|
|
|
190885 |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
190885 |
+ License along with the GNU C Library; if not, see
|
|
|
190885 |
+ <https://www.gnu.org/licenses/>. */
|
|
|
190885 |
+
|
|
|
190885 |
+#if IS_IN (libc)
|
|
|
190885 |
+
|
|
|
190885 |
+/* memcmp/wmemcmp is implemented as:
|
|
|
190885 |
+ 1. For size from 2 to 7 bytes, load as big endian with movbe and bswap
|
|
|
190885 |
+ to avoid branches.
|
|
|
190885 |
+ 2. Use overlapping compare to avoid branch.
|
|
|
190885 |
+ 3. Use vector compare when size >= 4 bytes for memcmp or size >= 8
|
|
|
190885 |
+ bytes for wmemcmp.
|
|
|
190885 |
+ 4. If size is 8 * VEC_SIZE or less, unroll the loop.
|
|
|
190885 |
+ 5. Compare 4 * VEC_SIZE at a time with the aligned first memory
|
|
|
190885 |
+ area.
|
|
|
190885 |
+ 6. Use 2 vector compares when size is 2 * VEC_SIZE or less.
|
|
|
190885 |
+ 7. Use 4 vector compares when size is 4 * VEC_SIZE or less.
|
|
|
190885 |
+ 8. Use 8 vector compares when size is 8 * VEC_SIZE or less. */
|
|
|
190885 |
+
|
|
|
190885 |
+# include <sysdep.h>
|
|
|
190885 |
+
|
|
|
190885 |
+# ifndef MEMCMP
|
|
|
190885 |
+# define MEMCMP __memcmp_evex_movbe
|
|
|
190885 |
+# endif
|
|
|
190885 |
+
|
|
|
190885 |
+# define VMOVU vmovdqu64
|
|
|
190885 |
+
|
|
|
190885 |
+# ifdef USE_AS_WMEMCMP
|
|
|
190885 |
+# define VPCMPEQ vpcmpeqd
|
|
|
190885 |
+# else
|
|
|
190885 |
+# define VPCMPEQ vpcmpeqb
|
|
|
190885 |
+# endif
|
|
|
190885 |
+
|
|
|
190885 |
+# define XMM1 xmm17
|
|
|
190885 |
+# define XMM2 xmm18
|
|
|
190885 |
+# define YMM1 ymm17
|
|
|
190885 |
+# define YMM2 ymm18
|
|
|
190885 |
+# define YMM3 ymm19
|
|
|
190885 |
+# define YMM4 ymm20
|
|
|
190885 |
+# define YMM5 ymm21
|
|
|
190885 |
+# define YMM6 ymm22
|
|
|
190885 |
+
|
|
|
190885 |
+# define VEC_SIZE 32
|
|
|
190885 |
+# ifdef USE_AS_WMEMCMP
|
|
|
190885 |
+# define VEC_MASK 0xff
|
|
|
190885 |
+# define XMM_MASK 0xf
|
|
|
190885 |
+# else
|
|
|
190885 |
+# define VEC_MASK 0xffffffff
|
|
|
190885 |
+# define XMM_MASK 0xffff
|
|
|
190885 |
+# endif
|
|
|
190885 |
+
|
|
|
190885 |
+/* Warning!
|
|
|
190885 |
+ wmemcmp has to use SIGNED comparison for elements.
|
|
|
190885 |
+ memcmp has to use UNSIGNED comparison for elemnts.
|
|
|
190885 |
+*/
|
|
|
190885 |
+
|
|
|
190885 |
+ .section .text.evex,"ax",@progbits
|
|
|
190885 |
+ENTRY (MEMCMP)
|
|
|
190885 |
+# ifdef USE_AS_WMEMCMP
|
|
|
190885 |
+ shl $2, %RDX_LP
|
|
|
190885 |
+# elif defined __ILP32__
|
|
|
190885 |
+ /* Clear the upper 32 bits. */
|
|
|
190885 |
+ movl %edx, %edx
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ cmp $VEC_SIZE, %RDX_LP
|
|
|
190885 |
+ jb L(less_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ /* From VEC to 2 * VEC. No branch when size == VEC_SIZE. */
|
|
|
190885 |
+ VMOVU (%rsi), %YMM2
|
|
|
190885 |
+ VPCMPEQ (%rdi), %YMM2, %k1
|
|
|
190885 |
+ kmovd %k1, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ cmpq $(VEC_SIZE * 2), %rdx
|
|
|
190885 |
+ jbe L(last_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ /* More than 2 * VEC. */
|
|
|
190885 |
+ cmpq $(VEC_SIZE * 8), %rdx
|
|
|
190885 |
+ ja L(more_8x_vec)
|
|
|
190885 |
+ cmpq $(VEC_SIZE * 4), %rdx
|
|
|
190885 |
+ jb L(last_4x_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ /* From 4 * VEC to 8 * VEC, inclusively. */
|
|
|
190885 |
+ VMOVU (%rsi), %YMM1
|
|
|
190885 |
+ VPCMPEQ (%rdi), %YMM1, %k1
|
|
|
190885 |
+
|
|
|
190885 |
+ VMOVU VEC_SIZE(%rsi), %YMM2
|
|
|
190885 |
+ VPCMPEQ VEC_SIZE(%rdi), %YMM2, %k2
|
|
|
190885 |
+
|
|
|
190885 |
+ VMOVU (VEC_SIZE * 2)(%rsi), %YMM3
|
|
|
190885 |
+ VPCMPEQ (VEC_SIZE * 2)(%rdi), %YMM3, %k3
|
|
|
190885 |
+
|
|
|
190885 |
+ VMOVU (VEC_SIZE * 3)(%rsi), %YMM4
|
|
|
190885 |
+ VPCMPEQ (VEC_SIZE * 3)(%rdi), %YMM4, %k4
|
|
|
190885 |
+
|
|
|
190885 |
+ kandd %k1, %k2, %k5
|
|
|
190885 |
+ kandd %k3, %k4, %k6
|
|
|
190885 |
+ kandd %k5, %k6, %k6
|
|
|
190885 |
+
|
|
|
190885 |
+ kmovd %k6, %eax
|
|
|
190885 |
+ cmpl $VEC_MASK, %eax
|
|
|
190885 |
+ jne L(4x_vec_end)
|
|
|
190885 |
+
|
|
|
190885 |
+ leaq -(4 * VEC_SIZE)(%rdi, %rdx), %rdi
|
|
|
190885 |
+ leaq -(4 * VEC_SIZE)(%rsi, %rdx), %rsi
|
|
|
190885 |
+ VMOVU (%rsi), %YMM1
|
|
|
190885 |
+ VPCMPEQ (%rdi), %YMM1, %k1
|
|
|
190885 |
+
|
|
|
190885 |
+ VMOVU VEC_SIZE(%rsi), %YMM2
|
|
|
190885 |
+ VPCMPEQ VEC_SIZE(%rdi), %YMM2, %k2
|
|
|
190885 |
+ kandd %k1, %k2, %k5
|
|
|
190885 |
+
|
|
|
190885 |
+ VMOVU (VEC_SIZE * 2)(%rsi), %YMM3
|
|
|
190885 |
+ VPCMPEQ (VEC_SIZE * 2)(%rdi), %YMM3, %k3
|
|
|
190885 |
+ kandd %k3, %k5, %k5
|
|
|
190885 |
+
|
|
|
190885 |
+ VMOVU (VEC_SIZE * 3)(%rsi), %YMM4
|
|
|
190885 |
+ VPCMPEQ (VEC_SIZE * 3)(%rdi), %YMM4, %k4
|
|
|
190885 |
+ kandd %k4, %k5, %k5
|
|
|
190885 |
+
|
|
|
190885 |
+ kmovd %k5, %eax
|
|
|
190885 |
+ cmpl $VEC_MASK, %eax
|
|
|
190885 |
+ jne L(4x_vec_end)
|
|
|
190885 |
+ xorl %eax, %eax
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(last_2x_vec):
|
|
|
190885 |
+ /* From VEC to 2 * VEC. No branch when size == VEC_SIZE. */
|
|
|
190885 |
+ VMOVU (%rsi), %YMM2
|
|
|
190885 |
+ VPCMPEQ (%rdi), %YMM2, %k2
|
|
|
190885 |
+ kmovd %k2, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+L(last_vec):
|
|
|
190885 |
+ /* Use overlapping loads to avoid branches. */
|
|
|
190885 |
+ leaq -VEC_SIZE(%rdi, %rdx), %rdi
|
|
|
190885 |
+ leaq -VEC_SIZE(%rsi, %rdx), %rsi
|
|
|
190885 |
+ VMOVU (%rsi), %YMM2
|
|
|
190885 |
+ VPCMPEQ (%rdi), %YMM2, %k2
|
|
|
190885 |
+ kmovd %k2, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(first_vec):
|
|
|
190885 |
+ /* A byte or int32 is different within 16 or 32 bytes. */
|
|
|
190885 |
+ tzcntl %eax, %ecx
|
|
|
190885 |
+# ifdef USE_AS_WMEMCMP
|
|
|
190885 |
+ xorl %eax, %eax
|
|
|
190885 |
+ movl (%rdi, %rcx, 4), %edx
|
|
|
190885 |
+ cmpl (%rsi, %rcx, 4), %edx
|
|
|
190885 |
+L(wmemcmp_return):
|
|
|
190885 |
+ setl %al
|
|
|
190885 |
+ negl %eax
|
|
|
190885 |
+ orl $1, %eax
|
|
|
190885 |
+# else
|
|
|
190885 |
+ movzbl (%rdi, %rcx), %eax
|
|
|
190885 |
+ movzbl (%rsi, %rcx), %edx
|
|
|
190885 |
+ sub %edx, %eax
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+# ifdef USE_AS_WMEMCMP
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(4):
|
|
|
190885 |
+ xorl %eax, %eax
|
|
|
190885 |
+ movl (%rdi), %edx
|
|
|
190885 |
+ cmpl (%rsi), %edx
|
|
|
190885 |
+ jne L(wmemcmp_return)
|
|
|
190885 |
+ ret
|
|
|
190885 |
+# else
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(between_4_7):
|
|
|
190885 |
+ /* Load as big endian with overlapping movbe to avoid branches. */
|
|
|
190885 |
+ movbe (%rdi), %eax
|
|
|
190885 |
+ movbe (%rsi), %ecx
|
|
|
190885 |
+ shlq $32, %rax
|
|
|
190885 |
+ shlq $32, %rcx
|
|
|
190885 |
+ movbe -4(%rdi, %rdx), %edi
|
|
|
190885 |
+ movbe -4(%rsi, %rdx), %esi
|
|
|
190885 |
+ orq %rdi, %rax
|
|
|
190885 |
+ orq %rsi, %rcx
|
|
|
190885 |
+ subq %rcx, %rax
|
|
|
190885 |
+ je L(exit)
|
|
|
190885 |
+ sbbl %eax, %eax
|
|
|
190885 |
+ orl $1, %eax
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(exit):
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(between_2_3):
|
|
|
190885 |
+ /* Load as big endian to avoid branches. */
|
|
|
190885 |
+ movzwl (%rdi), %eax
|
|
|
190885 |
+ movzwl (%rsi), %ecx
|
|
|
190885 |
+ shll $8, %eax
|
|
|
190885 |
+ shll $8, %ecx
|
|
|
190885 |
+ bswap %eax
|
|
|
190885 |
+ bswap %ecx
|
|
|
190885 |
+ movb -1(%rdi, %rdx), %al
|
|
|
190885 |
+ movb -1(%rsi, %rdx), %cl
|
|
|
190885 |
+ /* Subtraction is okay because the upper 8 bits are zero. */
|
|
|
190885 |
+ subl %ecx, %eax
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(1):
|
|
|
190885 |
+ movzbl (%rdi), %eax
|
|
|
190885 |
+ movzbl (%rsi), %ecx
|
|
|
190885 |
+ subl %ecx, %eax
|
|
|
190885 |
+ ret
|
|
|
190885 |
+# endif
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(zero):
|
|
|
190885 |
+ xorl %eax, %eax
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(less_vec):
|
|
|
190885 |
+# ifdef USE_AS_WMEMCMP
|
|
|
190885 |
+ /* It can only be 0, 4, 8, 12, 16, 20, 24, 28 bytes. */
|
|
|
190885 |
+ cmpb $4, %dl
|
|
|
190885 |
+ je L(4)
|
|
|
190885 |
+ jb L(zero)
|
|
|
190885 |
+# else
|
|
|
190885 |
+ cmpb $1, %dl
|
|
|
190885 |
+ je L(1)
|
|
|
190885 |
+ jb L(zero)
|
|
|
190885 |
+ cmpb $4, %dl
|
|
|
190885 |
+ jb L(between_2_3)
|
|
|
190885 |
+ cmpb $8, %dl
|
|
|
190885 |
+ jb L(between_4_7)
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ cmpb $16, %dl
|
|
|
190885 |
+ jae L(between_16_31)
|
|
|
190885 |
+ /* It is between 8 and 15 bytes. */
|
|
|
190885 |
+ vmovq (%rdi), %XMM1
|
|
|
190885 |
+ vmovq (%rsi), %XMM2
|
|
|
190885 |
+ VPCMPEQ %XMM1, %XMM2, %k2
|
|
|
190885 |
+ kmovw %k2, %eax
|
|
|
190885 |
+ subl $XMM_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+ /* Use overlapping loads to avoid branches. */
|
|
|
190885 |
+ leaq -8(%rdi, %rdx), %rdi
|
|
|
190885 |
+ leaq -8(%rsi, %rdx), %rsi
|
|
|
190885 |
+ vmovq (%rdi), %XMM1
|
|
|
190885 |
+ vmovq (%rsi), %XMM2
|
|
|
190885 |
+ VPCMPEQ %XMM1, %XMM2, %k2
|
|
|
190885 |
+ kmovw %k2, %eax
|
|
|
190885 |
+ subl $XMM_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(between_16_31):
|
|
|
190885 |
+ /* From 16 to 31 bytes. No branch when size == 16. */
|
|
|
190885 |
+ VMOVU (%rsi), %XMM2
|
|
|
190885 |
+ VPCMPEQ (%rdi), %XMM2, %k2
|
|
|
190885 |
+ kmovw %k2, %eax
|
|
|
190885 |
+ subl $XMM_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ /* Use overlapping loads to avoid branches. */
|
|
|
190885 |
+ leaq -16(%rdi, %rdx), %rdi
|
|
|
190885 |
+ leaq -16(%rsi, %rdx), %rsi
|
|
|
190885 |
+ VMOVU (%rsi), %XMM2
|
|
|
190885 |
+ VPCMPEQ (%rdi), %XMM2, %k2
|
|
|
190885 |
+ kmovw %k2, %eax
|
|
|
190885 |
+ subl $XMM_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(more_8x_vec):
|
|
|
190885 |
+ /* More than 8 * VEC. Check the first VEC. */
|
|
|
190885 |
+ VMOVU (%rsi), %YMM2
|
|
|
190885 |
+ VPCMPEQ (%rdi), %YMM2, %k2
|
|
|
190885 |
+ kmovd %k2, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ /* Align the first memory area for aligned loads in the loop.
|
|
|
190885 |
+ Compute how much the first memory area is misaligned. */
|
|
|
190885 |
+ movq %rdi, %rcx
|
|
|
190885 |
+ andl $(VEC_SIZE - 1), %ecx
|
|
|
190885 |
+ /* Get the negative of offset for alignment. */
|
|
|
190885 |
+ subq $VEC_SIZE, %rcx
|
|
|
190885 |
+ /* Adjust the second memory area. */
|
|
|
190885 |
+ subq %rcx, %rsi
|
|
|
190885 |
+ /* Adjust the first memory area which should be aligned now. */
|
|
|
190885 |
+ subq %rcx, %rdi
|
|
|
190885 |
+ /* Adjust length. */
|
|
|
190885 |
+ addq %rcx, %rdx
|
|
|
190885 |
+
|
|
|
190885 |
+L(loop_4x_vec):
|
|
|
190885 |
+ /* Compare 4 * VEC at a time forward. */
|
|
|
190885 |
+ VMOVU (%rsi), %YMM1
|
|
|
190885 |
+ VPCMPEQ (%rdi), %YMM1, %k1
|
|
|
190885 |
+
|
|
|
190885 |
+ VMOVU VEC_SIZE(%rsi), %YMM2
|
|
|
190885 |
+ VPCMPEQ VEC_SIZE(%rdi), %YMM2, %k2
|
|
|
190885 |
+ kandd %k2, %k1, %k5
|
|
|
190885 |
+
|
|
|
190885 |
+ VMOVU (VEC_SIZE * 2)(%rsi), %YMM3
|
|
|
190885 |
+ VPCMPEQ (VEC_SIZE * 2)(%rdi), %YMM3, %k3
|
|
|
190885 |
+ kandd %k3, %k5, %k5
|
|
|
190885 |
+
|
|
|
190885 |
+ VMOVU (VEC_SIZE * 3)(%rsi), %YMM4
|
|
|
190885 |
+ VPCMPEQ (VEC_SIZE * 3)(%rdi), %YMM4, %k4
|
|
|
190885 |
+ kandd %k4, %k5, %k5
|
|
|
190885 |
+
|
|
|
190885 |
+ kmovd %k5, %eax
|
|
|
190885 |
+ cmpl $VEC_MASK, %eax
|
|
|
190885 |
+ jne L(4x_vec_end)
|
|
|
190885 |
+
|
|
|
190885 |
+ addq $(VEC_SIZE * 4), %rdi
|
|
|
190885 |
+ addq $(VEC_SIZE * 4), %rsi
|
|
|
190885 |
+
|
|
|
190885 |
+ subq $(VEC_SIZE * 4), %rdx
|
|
|
190885 |
+ cmpq $(VEC_SIZE * 4), %rdx
|
|
|
190885 |
+ jae L(loop_4x_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ /* Less than 4 * VEC. */
|
|
|
190885 |
+ cmpq $VEC_SIZE, %rdx
|
|
|
190885 |
+ jbe L(last_vec)
|
|
|
190885 |
+ cmpq $(VEC_SIZE * 2), %rdx
|
|
|
190885 |
+ jbe L(last_2x_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+L(last_4x_vec):
|
|
|
190885 |
+ /* From 2 * VEC to 4 * VEC. */
|
|
|
190885 |
+ VMOVU (%rsi), %YMM2
|
|
|
190885 |
+ VPCMPEQ (%rdi), %YMM2, %k2
|
|
|
190885 |
+ kmovd %k2, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ addq $VEC_SIZE, %rdi
|
|
|
190885 |
+ addq $VEC_SIZE, %rsi
|
|
|
190885 |
+ VMOVU (%rsi), %YMM2
|
|
|
190885 |
+ VPCMPEQ (%rdi), %YMM2, %k2
|
|
|
190885 |
+ kmovd %k2, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ /* Use overlapping loads to avoid branches. */
|
|
|
190885 |
+ leaq -(3 * VEC_SIZE)(%rdi, %rdx), %rdi
|
|
|
190885 |
+ leaq -(3 * VEC_SIZE)(%rsi, %rdx), %rsi
|
|
|
190885 |
+ VMOVU (%rsi), %YMM2
|
|
|
190885 |
+ VPCMPEQ (%rdi), %YMM2, %k2
|
|
|
190885 |
+ kmovd %k2, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ addq $VEC_SIZE, %rdi
|
|
|
190885 |
+ addq $VEC_SIZE, %rsi
|
|
|
190885 |
+ VMOVU (%rsi), %YMM2
|
|
|
190885 |
+ VPCMPEQ (%rdi), %YMM2, %k2
|
|
|
190885 |
+ kmovd %k2, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(4x_vec_end):
|
|
|
190885 |
+ kmovd %k1, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec)
|
|
|
190885 |
+ kmovd %k2, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec_x1)
|
|
|
190885 |
+ kmovd %k3, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ jnz L(first_vec_x2)
|
|
|
190885 |
+ kmovd %k4, %eax
|
|
|
190885 |
+ subl $VEC_MASK, %eax
|
|
|
190885 |
+ tzcntl %eax, %ecx
|
|
|
190885 |
+# ifdef USE_AS_WMEMCMP
|
|
|
190885 |
+ xorl %eax, %eax
|
|
|
190885 |
+ movl (VEC_SIZE * 3)(%rdi, %rcx, 4), %edx
|
|
|
190885 |
+ cmpl (VEC_SIZE * 3)(%rsi, %rcx, 4), %edx
|
|
|
190885 |
+ jmp L(wmemcmp_return)
|
|
|
190885 |
+# else
|
|
|
190885 |
+ movzbl (VEC_SIZE * 3)(%rdi, %rcx), %eax
|
|
|
190885 |
+ movzbl (VEC_SIZE * 3)(%rsi, %rcx), %edx
|
|
|
190885 |
+ sub %edx, %eax
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(first_vec_x1):
|
|
|
190885 |
+ tzcntl %eax, %ecx
|
|
|
190885 |
+# ifdef USE_AS_WMEMCMP
|
|
|
190885 |
+ xorl %eax, %eax
|
|
|
190885 |
+ movl VEC_SIZE(%rdi, %rcx, 4), %edx
|
|
|
190885 |
+ cmpl VEC_SIZE(%rsi, %rcx, 4), %edx
|
|
|
190885 |
+ jmp L(wmemcmp_return)
|
|
|
190885 |
+# else
|
|
|
190885 |
+ movzbl VEC_SIZE(%rdi, %rcx), %eax
|
|
|
190885 |
+ movzbl VEC_SIZE(%rsi, %rcx), %edx
|
|
|
190885 |
+ sub %edx, %eax
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(first_vec_x2):
|
|
|
190885 |
+ tzcntl %eax, %ecx
|
|
|
190885 |
+# ifdef USE_AS_WMEMCMP
|
|
|
190885 |
+ xorl %eax, %eax
|
|
|
190885 |
+ movl (VEC_SIZE * 2)(%rdi, %rcx, 4), %edx
|
|
|
190885 |
+ cmpl (VEC_SIZE * 2)(%rsi, %rcx, 4), %edx
|
|
|
190885 |
+ jmp L(wmemcmp_return)
|
|
|
190885 |
+# else
|
|
|
190885 |
+ movzbl (VEC_SIZE * 2)(%rdi, %rcx), %eax
|
|
|
190885 |
+ movzbl (VEC_SIZE * 2)(%rsi, %rcx), %edx
|
|
|
190885 |
+ sub %edx, %eax
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ ret
|
|
|
190885 |
+END (MEMCMP)
|
|
|
190885 |
+#endif
|
|
|
190885 |
diff --git a/sysdeps/x86_64/multiarch/wmemcmp-evex-movbe.S b/sysdeps/x86_64/multiarch/wmemcmp-evex-movbe.S
|
|
|
190885 |
new file mode 100644
|
|
|
190885 |
index 00000000..4726d74a
|
|
|
190885 |
--- /dev/null
|
|
|
190885 |
+++ b/sysdeps/x86_64/multiarch/wmemcmp-evex-movbe.S
|
|
|
190885 |
@@ -0,0 +1,4 @@
|
|
|
190885 |
+#define MEMCMP __wmemcmp_evex_movbe
|
|
|
190885 |
+#define USE_AS_WMEMCMP 1
|
|
|
190885 |
+
|
|
|
190885 |
+#include "memcmp-evex-movbe.S"
|
|
|
190885 |
--
|
|
|
190885 |
GitLab
|
|
|
190885 |
|