|
|
190885 |
From 417f10b43cd3a0bc5c67b0b5151e92b722bdd8d7 Mon Sep 17 00:00:00 2001
|
|
|
190885 |
From: Noah Goldstein <goldstein.w.n@gmail.com>
|
|
|
190885 |
Date: Mon, 19 Apr 2021 19:36:06 -0400
|
|
|
190885 |
Subject: [PATCH] x86: Optimize strlen-evex.S
|
|
|
190885 |
|
|
|
190885 |
No bug. This commit optimizes strlen-evex.S. The
|
|
|
190885 |
optimizations are mostly small things but they add up to roughly
|
|
|
190885 |
10-30% performance improvement for strlen. The results for strnlen are
|
|
|
190885 |
bit more ambiguous. test-strlen, test-strnlen, test-wcslen, and
|
|
|
190885 |
test-wcsnlen are all passing.
|
|
|
190885 |
|
|
|
190885 |
Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
|
|
|
190885 |
(cherry picked from commit 4ba65586847751372520a36757c17f114588794e)
|
|
|
190885 |
---
|
|
|
190885 |
sysdeps/x86_64/multiarch/strlen-evex.S | 581 ++++++++++++++-----------
|
|
|
190885 |
1 file changed, 317 insertions(+), 264 deletions(-)
|
|
|
190885 |
|
|
|
190885 |
diff --git a/sysdeps/x86_64/multiarch/strlen-evex.S b/sysdeps/x86_64/multiarch/strlen-evex.S
|
|
|
190885 |
index 05838190..4bf6874b 100644
|
|
|
190885 |
--- a/sysdeps/x86_64/multiarch/strlen-evex.S
|
|
|
190885 |
+++ b/sysdeps/x86_64/multiarch/strlen-evex.S
|
|
|
190885 |
@@ -29,11 +29,13 @@
|
|
|
190885 |
# ifdef USE_AS_WCSLEN
|
|
|
190885 |
# define VPCMP vpcmpd
|
|
|
190885 |
# define VPMINU vpminud
|
|
|
190885 |
-# define SHIFT_REG r9d
|
|
|
190885 |
+# define SHIFT_REG ecx
|
|
|
190885 |
+# define CHAR_SIZE 4
|
|
|
190885 |
# else
|
|
|
190885 |
# define VPCMP vpcmpb
|
|
|
190885 |
# define VPMINU vpminub
|
|
|
190885 |
-# define SHIFT_REG ecx
|
|
|
190885 |
+# define SHIFT_REG edx
|
|
|
190885 |
+# define CHAR_SIZE 1
|
|
|
190885 |
# endif
|
|
|
190885 |
|
|
|
190885 |
# define XMMZERO xmm16
|
|
|
190885 |
@@ -46,132 +48,165 @@
|
|
|
190885 |
# define YMM6 ymm22
|
|
|
190885 |
|
|
|
190885 |
# define VEC_SIZE 32
|
|
|
190885 |
+# define PAGE_SIZE 4096
|
|
|
190885 |
+# define CHAR_PER_VEC (VEC_SIZE / CHAR_SIZE)
|
|
|
190885 |
|
|
|
190885 |
.section .text.evex,"ax",@progbits
|
|
|
190885 |
ENTRY (STRLEN)
|
|
|
190885 |
# ifdef USE_AS_STRNLEN
|
|
|
190885 |
- /* Check for zero length. */
|
|
|
190885 |
+ /* Check zero length. */
|
|
|
190885 |
test %RSI_LP, %RSI_LP
|
|
|
190885 |
jz L(zero)
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shl $2, %RSI_LP
|
|
|
190885 |
-# elif defined __ILP32__
|
|
|
190885 |
+# ifdef __ILP32__
|
|
|
190885 |
/* Clear the upper 32 bits. */
|
|
|
190885 |
movl %esi, %esi
|
|
|
190885 |
# endif
|
|
|
190885 |
mov %RSI_LP, %R8_LP
|
|
|
190885 |
# endif
|
|
|
190885 |
- movl %edi, %ecx
|
|
|
190885 |
- movq %rdi, %rdx
|
|
|
190885 |
+ movl %edi, %eax
|
|
|
190885 |
vpxorq %XMMZERO, %XMMZERO, %XMMZERO
|
|
|
190885 |
-
|
|
|
190885 |
+ /* Clear high bits from edi. Only keeping bits relevant to page
|
|
|
190885 |
+ cross check. */
|
|
|
190885 |
+ andl $(PAGE_SIZE - 1), %eax
|
|
|
190885 |
/* Check if we may cross page boundary with one vector load. */
|
|
|
190885 |
- andl $(2 * VEC_SIZE - 1), %ecx
|
|
|
190885 |
- cmpl $VEC_SIZE, %ecx
|
|
|
190885 |
- ja L(cros_page_boundary)
|
|
|
190885 |
+ cmpl $(PAGE_SIZE - VEC_SIZE), %eax
|
|
|
190885 |
+ ja L(cross_page_boundary)
|
|
|
190885 |
|
|
|
190885 |
/* Check the first VEC_SIZE bytes. Each bit in K0 represents a
|
|
|
190885 |
null byte. */
|
|
|
190885 |
VPCMP $0, (%rdi), %YMMZERO, %k0
|
|
|
190885 |
kmovd %k0, %eax
|
|
|
190885 |
- testl %eax, %eax
|
|
|
190885 |
-
|
|
|
190885 |
# ifdef USE_AS_STRNLEN
|
|
|
190885 |
- jnz L(first_vec_x0_check)
|
|
|
190885 |
- /* Adjust length and check the end of data. */
|
|
|
190885 |
- subq $VEC_SIZE, %rsi
|
|
|
190885 |
- jbe L(max)
|
|
|
190885 |
-# else
|
|
|
190885 |
- jnz L(first_vec_x0)
|
|
|
190885 |
+ /* If length < CHAR_PER_VEC handle special. */
|
|
|
190885 |
+ cmpq $CHAR_PER_VEC, %rsi
|
|
|
190885 |
+ jbe L(first_vec_x0)
|
|
|
190885 |
# endif
|
|
|
190885 |
-
|
|
|
190885 |
- /* Align data for aligned loads in the loop. */
|
|
|
190885 |
- addq $VEC_SIZE, %rdi
|
|
|
190885 |
- andl $(VEC_SIZE - 1), %ecx
|
|
|
190885 |
- andq $-VEC_SIZE, %rdi
|
|
|
190885 |
-
|
|
|
190885 |
+ testl %eax, %eax
|
|
|
190885 |
+ jz L(aligned_more)
|
|
|
190885 |
+ tzcntl %eax, %eax
|
|
|
190885 |
+ ret
|
|
|
190885 |
# ifdef USE_AS_STRNLEN
|
|
|
190885 |
- /* Adjust length. */
|
|
|
190885 |
- addq %rcx, %rsi
|
|
|
190885 |
+L(zero):
|
|
|
190885 |
+ xorl %eax, %eax
|
|
|
190885 |
+ ret
|
|
|
190885 |
|
|
|
190885 |
- subq $(VEC_SIZE * 4), %rsi
|
|
|
190885 |
- jbe L(last_4x_vec_or_less)
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(first_vec_x0):
|
|
|
190885 |
+ /* Set bit for max len so that tzcnt will return min of max len
|
|
|
190885 |
+ and position of first match. */
|
|
|
190885 |
+ btsq %rsi, %rax
|
|
|
190885 |
+ tzcntl %eax, %eax
|
|
|
190885 |
+ ret
|
|
|
190885 |
# endif
|
|
|
190885 |
- jmp L(more_4x_vec)
|
|
|
190885 |
|
|
|
190885 |
.p2align 4
|
|
|
190885 |
-L(cros_page_boundary):
|
|
|
190885 |
- andl $(VEC_SIZE - 1), %ecx
|
|
|
190885 |
- andq $-VEC_SIZE, %rdi
|
|
|
190885 |
-
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- /* NB: Divide shift count by 4 since each bit in K0 represent 4
|
|
|
190885 |
- bytes. */
|
|
|
190885 |
- movl %ecx, %SHIFT_REG
|
|
|
190885 |
- sarl $2, %SHIFT_REG
|
|
|
190885 |
+L(first_vec_x1):
|
|
|
190885 |
+ tzcntl %eax, %eax
|
|
|
190885 |
+ /* Safe to use 32 bit instructions as these are only called for
|
|
|
190885 |
+ size = [1, 159]. */
|
|
|
190885 |
+# ifdef USE_AS_STRNLEN
|
|
|
190885 |
+ /* Use ecx which was computed earlier to compute correct value.
|
|
|
190885 |
+ */
|
|
|
190885 |
+ leal -(CHAR_PER_VEC * 4 + 1)(%rcx, %rax), %eax
|
|
|
190885 |
+# else
|
|
|
190885 |
+ subl %edx, %edi
|
|
|
190885 |
+# ifdef USE_AS_WCSLEN
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarl $2, %edi
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ leal CHAR_PER_VEC(%rdi, %rax), %eax
|
|
|
190885 |
# endif
|
|
|
190885 |
- VPCMP $0, (%rdi), %YMMZERO, %k0
|
|
|
190885 |
- kmovd %k0, %eax
|
|
|
190885 |
+ ret
|
|
|
190885 |
|
|
|
190885 |
- /* Remove the leading bytes. */
|
|
|
190885 |
- sarxl %SHIFT_REG, %eax, %eax
|
|
|
190885 |
- testl %eax, %eax
|
|
|
190885 |
- jz L(aligned_more)
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(first_vec_x2):
|
|
|
190885 |
tzcntl %eax, %eax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- /* NB: Multiply wchar_t count by 4 to get the number of bytes. */
|
|
|
190885 |
- sall $2, %eax
|
|
|
190885 |
-# endif
|
|
|
190885 |
+ /* Safe to use 32 bit instructions as these are only called for
|
|
|
190885 |
+ size = [1, 159]. */
|
|
|
190885 |
# ifdef USE_AS_STRNLEN
|
|
|
190885 |
- /* Check the end of data. */
|
|
|
190885 |
- cmpq %rax, %rsi
|
|
|
190885 |
- jbe L(max)
|
|
|
190885 |
-# endif
|
|
|
190885 |
- addq %rdi, %rax
|
|
|
190885 |
- addq %rcx, %rax
|
|
|
190885 |
- subq %rdx, %rax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
+ /* Use ecx which was computed earlier to compute correct value.
|
|
|
190885 |
+ */
|
|
|
190885 |
+ leal -(CHAR_PER_VEC * 3 + 1)(%rcx, %rax), %eax
|
|
|
190885 |
+# else
|
|
|
190885 |
+ subl %edx, %edi
|
|
|
190885 |
+# ifdef USE_AS_WCSLEN
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarl $2, %edi
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ leal (CHAR_PER_VEC * 2)(%rdi, %rax), %eax
|
|
|
190885 |
# endif
|
|
|
190885 |
ret
|
|
|
190885 |
|
|
|
190885 |
.p2align 4
|
|
|
190885 |
-L(aligned_more):
|
|
|
190885 |
+L(first_vec_x3):
|
|
|
190885 |
+ tzcntl %eax, %eax
|
|
|
190885 |
+ /* Safe to use 32 bit instructions as these are only called for
|
|
|
190885 |
+ size = [1, 159]. */
|
|
|
190885 |
# ifdef USE_AS_STRNLEN
|
|
|
190885 |
- /* "rcx" is less than VEC_SIZE. Calculate "rdx + rcx - VEC_SIZE"
|
|
|
190885 |
- with "rdx - (VEC_SIZE - rcx)" instead of "(rdx + rcx) - VEC_SIZE"
|
|
|
190885 |
- to void possible addition overflow. */
|
|
|
190885 |
- negq %rcx
|
|
|
190885 |
- addq $VEC_SIZE, %rcx
|
|
|
190885 |
-
|
|
|
190885 |
- /* Check the end of data. */
|
|
|
190885 |
- subq %rcx, %rsi
|
|
|
190885 |
- jbe L(max)
|
|
|
190885 |
+ /* Use ecx which was computed earlier to compute correct value.
|
|
|
190885 |
+ */
|
|
|
190885 |
+ leal -(CHAR_PER_VEC * 2 + 1)(%rcx, %rax), %eax
|
|
|
190885 |
+# else
|
|
|
190885 |
+ subl %edx, %edi
|
|
|
190885 |
+# ifdef USE_AS_WCSLEN
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarl $2, %edi
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ leal (CHAR_PER_VEC * 3)(%rdi, %rax), %eax
|
|
|
190885 |
# endif
|
|
|
190885 |
+ ret
|
|
|
190885 |
|
|
|
190885 |
- addq $VEC_SIZE, %rdi
|
|
|
190885 |
-
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(first_vec_x4):
|
|
|
190885 |
+ tzcntl %eax, %eax
|
|
|
190885 |
+ /* Safe to use 32 bit instructions as these are only called for
|
|
|
190885 |
+ size = [1, 159]. */
|
|
|
190885 |
# ifdef USE_AS_STRNLEN
|
|
|
190885 |
- subq $(VEC_SIZE * 4), %rsi
|
|
|
190885 |
- jbe L(last_4x_vec_or_less)
|
|
|
190885 |
+ /* Use ecx which was computed earlier to compute correct value.
|
|
|
190885 |
+ */
|
|
|
190885 |
+ leal -(CHAR_PER_VEC + 1)(%rcx, %rax), %eax
|
|
|
190885 |
+# else
|
|
|
190885 |
+ subl %edx, %edi
|
|
|
190885 |
+# ifdef USE_AS_WCSLEN
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarl $2, %edi
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ leal (CHAR_PER_VEC * 4)(%rdi, %rax), %eax
|
|
|
190885 |
# endif
|
|
|
190885 |
+ ret
|
|
|
190885 |
|
|
|
190885 |
-L(more_4x_vec):
|
|
|
190885 |
+ .p2align 5
|
|
|
190885 |
+L(aligned_more):
|
|
|
190885 |
+ movq %rdi, %rdx
|
|
|
190885 |
+ /* Align data to VEC_SIZE. */
|
|
|
190885 |
+ andq $-(VEC_SIZE), %rdi
|
|
|
190885 |
+L(cross_page_continue):
|
|
|
190885 |
/* Check the first 4 * VEC_SIZE. Only one VEC_SIZE at a time
|
|
|
190885 |
since data is only aligned to VEC_SIZE. */
|
|
|
190885 |
- VPCMP $0, (%rdi), %YMMZERO, %k0
|
|
|
190885 |
- kmovd %k0, %eax
|
|
|
190885 |
- testl %eax, %eax
|
|
|
190885 |
- jnz L(first_vec_x0)
|
|
|
190885 |
-
|
|
|
190885 |
+# ifdef USE_AS_STRNLEN
|
|
|
190885 |
+ /* + CHAR_SIZE because it simplies the logic in
|
|
|
190885 |
+ last_4x_vec_or_less. */
|
|
|
190885 |
+ leaq (VEC_SIZE * 5 + CHAR_SIZE)(%rdi), %rcx
|
|
|
190885 |
+ subq %rdx, %rcx
|
|
|
190885 |
+# ifdef USE_AS_WCSLEN
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarl $2, %ecx
|
|
|
190885 |
+# endif
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ /* Load first VEC regardless. */
|
|
|
190885 |
VPCMP $0, VEC_SIZE(%rdi), %YMMZERO, %k0
|
|
|
190885 |
+# ifdef USE_AS_STRNLEN
|
|
|
190885 |
+ /* Adjust length. If near end handle specially. */
|
|
|
190885 |
+ subq %rcx, %rsi
|
|
|
190885 |
+ jb L(last_4x_vec_or_less)
|
|
|
190885 |
+# endif
|
|
|
190885 |
kmovd %k0, %eax
|
|
|
190885 |
testl %eax, %eax
|
|
|
190885 |
jnz L(first_vec_x1)
|
|
|
190885 |
|
|
|
190885 |
VPCMP $0, (VEC_SIZE * 2)(%rdi), %YMMZERO, %k0
|
|
|
190885 |
kmovd %k0, %eax
|
|
|
190885 |
- testl %eax, %eax
|
|
|
190885 |
+ test %eax, %eax
|
|
|
190885 |
jnz L(first_vec_x2)
|
|
|
190885 |
|
|
|
190885 |
VPCMP $0, (VEC_SIZE * 3)(%rdi), %YMMZERO, %k0
|
|
|
190885 |
@@ -179,258 +214,276 @@ L(more_4x_vec):
|
|
|
190885 |
testl %eax, %eax
|
|
|
190885 |
jnz L(first_vec_x3)
|
|
|
190885 |
|
|
|
190885 |
- addq $(VEC_SIZE * 4), %rdi
|
|
|
190885 |
-
|
|
|
190885 |
-# ifdef USE_AS_STRNLEN
|
|
|
190885 |
- subq $(VEC_SIZE * 4), %rsi
|
|
|
190885 |
- jbe L(last_4x_vec_or_less)
|
|
|
190885 |
-# endif
|
|
|
190885 |
-
|
|
|
190885 |
- /* Align data to 4 * VEC_SIZE. */
|
|
|
190885 |
- movq %rdi, %rcx
|
|
|
190885 |
- andl $(4 * VEC_SIZE - 1), %ecx
|
|
|
190885 |
- andq $-(4 * VEC_SIZE), %rdi
|
|
|
190885 |
+ VPCMP $0, (VEC_SIZE * 4)(%rdi), %YMMZERO, %k0
|
|
|
190885 |
+ kmovd %k0, %eax
|
|
|
190885 |
+ testl %eax, %eax
|
|
|
190885 |
+ jnz L(first_vec_x4)
|
|
|
190885 |
|
|
|
190885 |
+ addq $VEC_SIZE, %rdi
|
|
|
190885 |
# ifdef USE_AS_STRNLEN
|
|
|
190885 |
- /* Adjust length. */
|
|
|
190885 |
+ /* Check if at last VEC_SIZE * 4 length. */
|
|
|
190885 |
+ cmpq $(CHAR_PER_VEC * 4 - 1), %rsi
|
|
|
190885 |
+ jbe L(last_4x_vec_or_less_load)
|
|
|
190885 |
+ movl %edi, %ecx
|
|
|
190885 |
+ andl $(VEC_SIZE * 4 - 1), %ecx
|
|
|
190885 |
+# ifdef USE_AS_WCSLEN
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarl $2, %ecx
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ /* Readjust length. */
|
|
|
190885 |
addq %rcx, %rsi
|
|
|
190885 |
# endif
|
|
|
190885 |
+ /* Align data to VEC_SIZE * 4. */
|
|
|
190885 |
+ andq $-(VEC_SIZE * 4), %rdi
|
|
|
190885 |
|
|
|
190885 |
+ /* Compare 4 * VEC at a time forward. */
|
|
|
190885 |
.p2align 4
|
|
|
190885 |
L(loop_4x_vec):
|
|
|
190885 |
- /* Compare 4 * VEC at a time forward. */
|
|
|
190885 |
- VMOVA (%rdi), %YMM1
|
|
|
190885 |
- VMOVA VEC_SIZE(%rdi), %YMM2
|
|
|
190885 |
- VMOVA (VEC_SIZE * 2)(%rdi), %YMM3
|
|
|
190885 |
- VMOVA (VEC_SIZE * 3)(%rdi), %YMM4
|
|
|
190885 |
-
|
|
|
190885 |
- VPMINU %YMM1, %YMM2, %YMM5
|
|
|
190885 |
- VPMINU %YMM3, %YMM4, %YMM6
|
|
|
190885 |
+ /* Load first VEC regardless. */
|
|
|
190885 |
+ VMOVA (VEC_SIZE * 4)(%rdi), %YMM1
|
|
|
190885 |
+# ifdef USE_AS_STRNLEN
|
|
|
190885 |
+ /* Break if at end of length. */
|
|
|
190885 |
+ subq $(CHAR_PER_VEC * 4), %rsi
|
|
|
190885 |
+ jb L(last_4x_vec_or_less_cmpeq)
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ /* Save some code size by microfusing VPMINU with the load. Since
|
|
|
190885 |
+ the matches in ymm2/ymm4 can only be returned if there where no
|
|
|
190885 |
+ matches in ymm1/ymm3 respectively there is no issue with overlap.
|
|
|
190885 |
+ */
|
|
|
190885 |
+ VPMINU (VEC_SIZE * 5)(%rdi), %YMM1, %YMM2
|
|
|
190885 |
+ VMOVA (VEC_SIZE * 6)(%rdi), %YMM3
|
|
|
190885 |
+ VPMINU (VEC_SIZE * 7)(%rdi), %YMM3, %YMM4
|
|
|
190885 |
+
|
|
|
190885 |
+ VPCMP $0, %YMM2, %YMMZERO, %k0
|
|
|
190885 |
+ VPCMP $0, %YMM4, %YMMZERO, %k1
|
|
|
190885 |
+ subq $-(VEC_SIZE * 4), %rdi
|
|
|
190885 |
+ kortestd %k0, %k1
|
|
|
190885 |
+ jz L(loop_4x_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ /* Check if end was in first half. */
|
|
|
190885 |
+ kmovd %k0, %eax
|
|
|
190885 |
+ subq %rdx, %rdi
|
|
|
190885 |
+# ifdef USE_AS_WCSLEN
|
|
|
190885 |
+ shrq $2, %rdi
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ testl %eax, %eax
|
|
|
190885 |
+ jz L(second_vec_return)
|
|
|
190885 |
|
|
|
190885 |
- VPMINU %YMM5, %YMM6, %YMM5
|
|
|
190885 |
- VPCMP $0, %YMM5, %YMMZERO, %k0
|
|
|
190885 |
- ktestd %k0, %k0
|
|
|
190885 |
- jnz L(4x_vec_end)
|
|
|
190885 |
+ VPCMP $0, %YMM1, %YMMZERO, %k2
|
|
|
190885 |
+ kmovd %k2, %edx
|
|
|
190885 |
+ /* Combine VEC1 matches (edx) with VEC2 matches (eax). */
|
|
|
190885 |
+# ifdef USE_AS_WCSLEN
|
|
|
190885 |
+ sall $CHAR_PER_VEC, %eax
|
|
|
190885 |
+ orl %edx, %eax
|
|
|
190885 |
+ tzcntl %eax, %eax
|
|
|
190885 |
+# else
|
|
|
190885 |
+ salq $CHAR_PER_VEC, %rax
|
|
|
190885 |
+ orq %rdx, %rax
|
|
|
190885 |
+ tzcntq %rax, %rax
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ addq %rdi, %rax
|
|
|
190885 |
+ ret
|
|
|
190885 |
|
|
|
190885 |
- addq $(VEC_SIZE * 4), %rdi
|
|
|
190885 |
|
|
|
190885 |
-# ifndef USE_AS_STRNLEN
|
|
|
190885 |
- jmp L(loop_4x_vec)
|
|
|
190885 |
-# else
|
|
|
190885 |
- subq $(VEC_SIZE * 4), %rsi
|
|
|
190885 |
- ja L(loop_4x_vec)
|
|
|
190885 |
+# ifdef USE_AS_STRNLEN
|
|
|
190885 |
|
|
|
190885 |
+L(last_4x_vec_or_less_load):
|
|
|
190885 |
+ /* Depending on entry adjust rdi / prepare first VEC in YMM1. */
|
|
|
190885 |
+ VMOVA (VEC_SIZE * 4)(%rdi), %YMM1
|
|
|
190885 |
+L(last_4x_vec_or_less_cmpeq):
|
|
|
190885 |
+ VPCMP $0, %YMM1, %YMMZERO, %k0
|
|
|
190885 |
+ addq $(VEC_SIZE * 3), %rdi
|
|
|
190885 |
L(last_4x_vec_or_less):
|
|
|
190885 |
- /* Less than 4 * VEC and aligned to VEC_SIZE. */
|
|
|
190885 |
- addl $(VEC_SIZE * 2), %esi
|
|
|
190885 |
- jle L(last_2x_vec)
|
|
|
190885 |
-
|
|
|
190885 |
- VPCMP $0, (%rdi), %YMMZERO, %k0
|
|
|
190885 |
kmovd %k0, %eax
|
|
|
190885 |
+ /* If remaining length > VEC_SIZE * 2. This works if esi is off by
|
|
|
190885 |
+ VEC_SIZE * 4. */
|
|
|
190885 |
+ testl $(CHAR_PER_VEC * 2), %esi
|
|
|
190885 |
+ jnz L(last_4x_vec)
|
|
|
190885 |
+
|
|
|
190885 |
+ /* length may have been negative or positive by an offset of
|
|
|
190885 |
+ CHAR_PER_VEC * 4 depending on where this was called from. This
|
|
|
190885 |
+ fixes that. */
|
|
|
190885 |
+ andl $(CHAR_PER_VEC * 4 - 1), %esi
|
|
|
190885 |
testl %eax, %eax
|
|
|
190885 |
- jnz L(first_vec_x0)
|
|
|
190885 |
+ jnz L(last_vec_x1_check)
|
|
|
190885 |
|
|
|
190885 |
- VPCMP $0, VEC_SIZE(%rdi), %YMMZERO, %k0
|
|
|
190885 |
- kmovd %k0, %eax
|
|
|
190885 |
- testl %eax, %eax
|
|
|
190885 |
- jnz L(first_vec_x1)
|
|
|
190885 |
+ /* Check the end of data. */
|
|
|
190885 |
+ subl $CHAR_PER_VEC, %esi
|
|
|
190885 |
+ jb L(max)
|
|
|
190885 |
|
|
|
190885 |
VPCMP $0, (VEC_SIZE * 2)(%rdi), %YMMZERO, %k0
|
|
|
190885 |
kmovd %k0, %eax
|
|
|
190885 |
- testl %eax, %eax
|
|
|
190885 |
- jnz L(first_vec_x2_check)
|
|
|
190885 |
- subl $VEC_SIZE, %esi
|
|
|
190885 |
- jle L(max)
|
|
|
190885 |
+ tzcntl %eax, %eax
|
|
|
190885 |
+ /* Check the end of data. */
|
|
|
190885 |
+ cmpl %eax, %esi
|
|
|
190885 |
+ jb L(max)
|
|
|
190885 |
|
|
|
190885 |
- VPCMP $0, (VEC_SIZE * 3)(%rdi), %YMMZERO, %k0
|
|
|
190885 |
- kmovd %k0, %eax
|
|
|
190885 |
- testl %eax, %eax
|
|
|
190885 |
- jnz L(first_vec_x3_check)
|
|
|
190885 |
+ subq %rdx, %rdi
|
|
|
190885 |
+# ifdef USE_AS_WCSLEN
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarq $2, %rdi
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ leaq (CHAR_PER_VEC * 2)(%rdi, %rax), %rax
|
|
|
190885 |
+ ret
|
|
|
190885 |
+L(max):
|
|
|
190885 |
movq %r8, %rax
|
|
|
190885 |
+ ret
|
|
|
190885 |
+# endif
|
|
|
190885 |
+
|
|
|
190885 |
+ /* Placed here in strnlen so that the jcc L(last_4x_vec_or_less)
|
|
|
190885 |
+ in the 4x VEC loop can use 2 byte encoding. */
|
|
|
190885 |
+ .p2align 4
|
|
|
190885 |
+L(second_vec_return):
|
|
|
190885 |
+ VPCMP $0, %YMM3, %YMMZERO, %k0
|
|
|
190885 |
+ /* Combine YMM3 matches (k0) with YMM4 matches (k1). */
|
|
|
190885 |
+# ifdef USE_AS_WCSLEN
|
|
|
190885 |
+ kunpckbw %k0, %k1, %k0
|
|
|
190885 |
+ kmovd %k0, %eax
|
|
|
190885 |
+ tzcntl %eax, %eax
|
|
|
190885 |
+# else
|
|
|
190885 |
+ kunpckdq %k0, %k1, %k0
|
|
|
190885 |
+ kmovq %k0, %rax
|
|
|
190885 |
+ tzcntq %rax, %rax
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ leaq (CHAR_PER_VEC * 2)(%rdi, %rax), %rax
|
|
|
190885 |
+ ret
|
|
|
190885 |
+
|
|
|
190885 |
+
|
|
|
190885 |
+# ifdef USE_AS_STRNLEN
|
|
|
190885 |
+L(last_vec_x1_check):
|
|
|
190885 |
+ tzcntl %eax, %eax
|
|
|
190885 |
+ /* Check the end of data. */
|
|
|
190885 |
+ cmpl %eax, %esi
|
|
|
190885 |
+ jb L(max)
|
|
|
190885 |
+ subq %rdx, %rdi
|
|
|
190885 |
# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarq $2, %rdi
|
|
|
190885 |
# endif
|
|
|
190885 |
+ leaq (CHAR_PER_VEC)(%rdi, %rax), %rax
|
|
|
190885 |
ret
|
|
|
190885 |
|
|
|
190885 |
.p2align 4
|
|
|
190885 |
-L(last_2x_vec):
|
|
|
190885 |
- addl $(VEC_SIZE * 2), %esi
|
|
|
190885 |
+L(last_4x_vec):
|
|
|
190885 |
+ /* Test first 2x VEC normally. */
|
|
|
190885 |
+ testl %eax, %eax
|
|
|
190885 |
+ jnz L(last_vec_x1)
|
|
|
190885 |
|
|
|
190885 |
- VPCMP $0, (%rdi), %YMMZERO, %k0
|
|
|
190885 |
+ VPCMP $0, (VEC_SIZE * 2)(%rdi), %YMMZERO, %k0
|
|
|
190885 |
kmovd %k0, %eax
|
|
|
190885 |
testl %eax, %eax
|
|
|
190885 |
- jnz L(first_vec_x0_check)
|
|
|
190885 |
- subl $VEC_SIZE, %esi
|
|
|
190885 |
- jle L(max)
|
|
|
190885 |
+ jnz L(last_vec_x2)
|
|
|
190885 |
|
|
|
190885 |
- VPCMP $0, VEC_SIZE(%rdi), %YMMZERO, %k0
|
|
|
190885 |
+ /* Normalize length. */
|
|
|
190885 |
+ andl $(CHAR_PER_VEC * 4 - 1), %esi
|
|
|
190885 |
+ VPCMP $0, (VEC_SIZE * 3)(%rdi), %YMMZERO, %k0
|
|
|
190885 |
kmovd %k0, %eax
|
|
|
190885 |
testl %eax, %eax
|
|
|
190885 |
- jnz L(first_vec_x1_check)
|
|
|
190885 |
- movq %r8, %rax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
-# endif
|
|
|
190885 |
- ret
|
|
|
190885 |
+ jnz L(last_vec_x3)
|
|
|
190885 |
|
|
|
190885 |
- .p2align 4
|
|
|
190885 |
-L(first_vec_x0_check):
|
|
|
190885 |
+ /* Check the end of data. */
|
|
|
190885 |
+ subl $(CHAR_PER_VEC * 3), %esi
|
|
|
190885 |
+ jb L(max)
|
|
|
190885 |
+
|
|
|
190885 |
+ VPCMP $0, (VEC_SIZE * 4)(%rdi), %YMMZERO, %k0
|
|
|
190885 |
+ kmovd %k0, %eax
|
|
|
190885 |
tzcntl %eax, %eax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- /* NB: Multiply wchar_t count by 4 to get the number of bytes. */
|
|
|
190885 |
- sall $2, %eax
|
|
|
190885 |
-# endif
|
|
|
190885 |
/* Check the end of data. */
|
|
|
190885 |
- cmpq %rax, %rsi
|
|
|
190885 |
- jbe L(max)
|
|
|
190885 |
- addq %rdi, %rax
|
|
|
190885 |
- subq %rdx, %rax
|
|
|
190885 |
+ cmpl %eax, %esi
|
|
|
190885 |
+ jb L(max_end)
|
|
|
190885 |
+
|
|
|
190885 |
+ subq %rdx, %rdi
|
|
|
190885 |
# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarq $2, %rdi
|
|
|
190885 |
# endif
|
|
|
190885 |
+ leaq (CHAR_PER_VEC * 4)(%rdi, %rax), %rax
|
|
|
190885 |
ret
|
|
|
190885 |
|
|
|
190885 |
.p2align 4
|
|
|
190885 |
-L(first_vec_x1_check):
|
|
|
190885 |
+L(last_vec_x1):
|
|
|
190885 |
tzcntl %eax, %eax
|
|
|
190885 |
+ subq %rdx, %rdi
|
|
|
190885 |
# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- /* NB: Multiply wchar_t count by 4 to get the number of bytes. */
|
|
|
190885 |
- sall $2, %eax
|
|
|
190885 |
-# endif
|
|
|
190885 |
- /* Check the end of data. */
|
|
|
190885 |
- cmpq %rax, %rsi
|
|
|
190885 |
- jbe L(max)
|
|
|
190885 |
- addq $VEC_SIZE, %rax
|
|
|
190885 |
- addq %rdi, %rax
|
|
|
190885 |
- subq %rdx, %rax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarq $2, %rdi
|
|
|
190885 |
# endif
|
|
|
190885 |
+ leaq (CHAR_PER_VEC)(%rdi, %rax), %rax
|
|
|
190885 |
ret
|
|
|
190885 |
|
|
|
190885 |
.p2align 4
|
|
|
190885 |
-L(first_vec_x2_check):
|
|
|
190885 |
+L(last_vec_x2):
|
|
|
190885 |
tzcntl %eax, %eax
|
|
|
190885 |
+ subq %rdx, %rdi
|
|
|
190885 |
# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- /* NB: Multiply wchar_t count by 4 to get the number of bytes. */
|
|
|
190885 |
- sall $2, %eax
|
|
|
190885 |
-# endif
|
|
|
190885 |
- /* Check the end of data. */
|
|
|
190885 |
- cmpq %rax, %rsi
|
|
|
190885 |
- jbe L(max)
|
|
|
190885 |
- addq $(VEC_SIZE * 2), %rax
|
|
|
190885 |
- addq %rdi, %rax
|
|
|
190885 |
- subq %rdx, %rax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarq $2, %rdi
|
|
|
190885 |
# endif
|
|
|
190885 |
+ leaq (CHAR_PER_VEC * 2)(%rdi, %rax), %rax
|
|
|
190885 |
ret
|
|
|
190885 |
|
|
|
190885 |
.p2align 4
|
|
|
190885 |
-L(first_vec_x3_check):
|
|
|
190885 |
+L(last_vec_x3):
|
|
|
190885 |
tzcntl %eax, %eax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- /* NB: Multiply wchar_t count by 4 to get the number of bytes. */
|
|
|
190885 |
- sall $2, %eax
|
|
|
190885 |
-# endif
|
|
|
190885 |
+ subl $(CHAR_PER_VEC * 2), %esi
|
|
|
190885 |
/* Check the end of data. */
|
|
|
190885 |
- cmpq %rax, %rsi
|
|
|
190885 |
- jbe L(max)
|
|
|
190885 |
- addq $(VEC_SIZE * 3), %rax
|
|
|
190885 |
- addq %rdi, %rax
|
|
|
190885 |
- subq %rdx, %rax
|
|
|
190885 |
+ cmpl %eax, %esi
|
|
|
190885 |
+ jb L(max_end)
|
|
|
190885 |
+ subq %rdx, %rdi
|
|
|
190885 |
# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
+ /* NB: Divide bytes by 4 to get the wchar_t count. */
|
|
|
190885 |
+ sarq $2, %rdi
|
|
|
190885 |
# endif
|
|
|
190885 |
+ leaq (CHAR_PER_VEC * 3)(%rdi, %rax), %rax
|
|
|
190885 |
ret
|
|
|
190885 |
-
|
|
|
190885 |
- .p2align 4
|
|
|
190885 |
-L(max):
|
|
|
190885 |
+L(max_end):
|
|
|
190885 |
movq %r8, %rax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
-# endif
|
|
|
190885 |
- ret
|
|
|
190885 |
-
|
|
|
190885 |
- .p2align 4
|
|
|
190885 |
-L(zero):
|
|
|
190885 |
- xorl %eax, %eax
|
|
|
190885 |
ret
|
|
|
190885 |
# endif
|
|
|
190885 |
|
|
|
190885 |
+ /* Cold case for crossing page with first load. */
|
|
|
190885 |
.p2align 4
|
|
|
190885 |
-L(first_vec_x0):
|
|
|
190885 |
- tzcntl %eax, %eax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- /* NB: Multiply wchar_t count by 4 to get the number of bytes. */
|
|
|
190885 |
- sall $2, %eax
|
|
|
190885 |
-# endif
|
|
|
190885 |
- addq %rdi, %rax
|
|
|
190885 |
- subq %rdx, %rax
|
|
|
190885 |
+L(cross_page_boundary):
|
|
|
190885 |
+ movq %rdi, %rdx
|
|
|
190885 |
+ /* Align data to VEC_SIZE. */
|
|
|
190885 |
+ andq $-VEC_SIZE, %rdi
|
|
|
190885 |
+ VPCMP $0, (%rdi), %YMMZERO, %k0
|
|
|
190885 |
+ kmovd %k0, %eax
|
|
|
190885 |
+ /* Remove the leading bytes. */
|
|
|
190885 |
# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
+ /* NB: Divide shift count by 4 since each bit in K0 represent 4
|
|
|
190885 |
+ bytes. */
|
|
|
190885 |
+ movl %edx, %ecx
|
|
|
190885 |
+ shrl $2, %ecx
|
|
|
190885 |
+ andl $(CHAR_PER_VEC - 1), %ecx
|
|
|
190885 |
# endif
|
|
|
190885 |
- ret
|
|
|
190885 |
-
|
|
|
190885 |
- .p2align 4
|
|
|
190885 |
-L(first_vec_x1):
|
|
|
190885 |
+ /* SHIFT_REG is ecx for USE_AS_WCSLEN and edx otherwise. */
|
|
|
190885 |
+ sarxl %SHIFT_REG, %eax, %eax
|
|
|
190885 |
+ testl %eax, %eax
|
|
|
190885 |
+# ifndef USE_AS_STRNLEN
|
|
|
190885 |
+ jz L(cross_page_continue)
|
|
|
190885 |
tzcntl %eax, %eax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- /* NB: Multiply wchar_t count by 4 to get the number of bytes. */
|
|
|
190885 |
- sall $2, %eax
|
|
|
190885 |
-# endif
|
|
|
190885 |
- addq $VEC_SIZE, %rax
|
|
|
190885 |
- addq %rdi, %rax
|
|
|
190885 |
- subq %rdx, %rax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
-# endif
|
|
|
190885 |
ret
|
|
|
190885 |
-
|
|
|
190885 |
- .p2align 4
|
|
|
190885 |
-L(first_vec_x2):
|
|
|
190885 |
- tzcntl %eax, %eax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- /* NB: Multiply wchar_t count by 4 to get the number of bytes. */
|
|
|
190885 |
- sall $2, %eax
|
|
|
190885 |
-# endif
|
|
|
190885 |
- addq $(VEC_SIZE * 2), %rax
|
|
|
190885 |
- addq %rdi, %rax
|
|
|
190885 |
- subq %rdx, %rax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
-# endif
|
|
|
190885 |
+# else
|
|
|
190885 |
+ jnz L(cross_page_less_vec)
|
|
|
190885 |
+# ifndef USE_AS_WCSLEN
|
|
|
190885 |
+ movl %edx, %ecx
|
|
|
190885 |
+ andl $(CHAR_PER_VEC - 1), %ecx
|
|
|
190885 |
+# endif
|
|
|
190885 |
+ movl $CHAR_PER_VEC, %eax
|
|
|
190885 |
+ subl %ecx, %eax
|
|
|
190885 |
+ /* Check the end of data. */
|
|
|
190885 |
+ cmpq %rax, %rsi
|
|
|
190885 |
+ ja L(cross_page_continue)
|
|
|
190885 |
+ movl %esi, %eax
|
|
|
190885 |
ret
|
|
|
190885 |
-
|
|
|
190885 |
- .p2align 4
|
|
|
190885 |
-L(4x_vec_end):
|
|
|
190885 |
- VPCMP $0, %YMM1, %YMMZERO, %k0
|
|
|
190885 |
- kmovd %k0, %eax
|
|
|
190885 |
- testl %eax, %eax
|
|
|
190885 |
- jnz L(first_vec_x0)
|
|
|
190885 |
- VPCMP $0, %YMM2, %YMMZERO, %k1
|
|
|
190885 |
- kmovd %k1, %eax
|
|
|
190885 |
- testl %eax, %eax
|
|
|
190885 |
- jnz L(first_vec_x1)
|
|
|
190885 |
- VPCMP $0, %YMM3, %YMMZERO, %k2
|
|
|
190885 |
- kmovd %k2, %eax
|
|
|
190885 |
- testl %eax, %eax
|
|
|
190885 |
- jnz L(first_vec_x2)
|
|
|
190885 |
- VPCMP $0, %YMM4, %YMMZERO, %k3
|
|
|
190885 |
- kmovd %k3, %eax
|
|
|
190885 |
-L(first_vec_x3):
|
|
|
190885 |
+L(cross_page_less_vec):
|
|
|
190885 |
tzcntl %eax, %eax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- /* NB: Multiply wchar_t count by 4 to get the number of bytes. */
|
|
|
190885 |
- sall $2, %eax
|
|
|
190885 |
-# endif
|
|
|
190885 |
- addq $(VEC_SIZE * 3), %rax
|
|
|
190885 |
- addq %rdi, %rax
|
|
|
190885 |
- subq %rdx, %rax
|
|
|
190885 |
-# ifdef USE_AS_WCSLEN
|
|
|
190885 |
- shrq $2, %rax
|
|
|
190885 |
-# endif
|
|
|
190885 |
+ /* Select min of length and position of first null. */
|
|
|
190885 |
+ cmpq %rax, %rsi
|
|
|
190885 |
+ cmovb %esi, %eax
|
|
|
190885 |
ret
|
|
|
190885 |
+# endif
|
|
|
190885 |
|
|
|
190885 |
END (STRLEN)
|
|
|
190885 |
#endif
|
|
|
190885 |
--
|
|
|
190885 |
GitLab
|
|
|
190885 |
|