Blame SOURCES/ia-imp-wcslen.patch
|
|
513694 |
From ac23759b655ceac1bd18b71f45bb1743826f0bed Mon Sep 17 00:00:00 2001
|
|
|
513694 |
From: Noah Goldstein <goldstein.w.n@gmail.com>
|
|
|
513694 |
Date: Fri, 25 Mar 2022 17:13:33 -0500
|
|
|
513694 |
Subject: [PATCH] x86: Small improvements for wcslen
|
|
|
513694 |
|
|
|
513694 |
Just a few QOL changes.
|
|
|
513694 |
1. Prefer `add` > `lea` as it has high execution units it can run
|
|
|
513694 |
on.
|
|
|
513694 |
2. Don't break macro-fusion between `test` and `jcc`
|
|
|
513694 |
3. Reduce code size by removing gratuitous padding bytes (-90
|
|
|
513694 |
bytes).
|
|
|
513694 |
|
|
|
513694 |
geometric_mean(N=20) of all benchmarks New / Original: 0.959
|
|
|
513694 |
|
|
|
513694 |
All string/memory tests pass.
|
|
|
513694 |
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
|
|
|
513694 |
|
|
|
513694 |
(cherry picked from commit 244b415d386487521882debb845a040a4758cb18)
|
|
|
513694 |
---
|
|
|
513694 |
sysdeps/x86_64/wcslen.S | 86 ++++++++++++++++++++---------------------
|
|
|
513694 |
1 file changed, 41 insertions(+), 45 deletions(-)
|
|
|
513694 |
|
|
|
513694 |
diff --git a/sysdeps/x86_64/wcslen.S b/sysdeps/x86_64/wcslen.S
|
|
|
513694 |
index 9f5f7232..254bb030 100644
|
|
|
513694 |
--- a/sysdeps/x86_64/wcslen.S
|
|
|
513694 |
+++ b/sysdeps/x86_64/wcslen.S
|
|
|
513694 |
@@ -41,82 +41,82 @@ ENTRY (__wcslen)
|
|
|
513694 |
pxor %xmm0, %xmm0
|
|
|
513694 |
|
|
|
513694 |
lea 32(%rdi), %rax
|
|
|
513694 |
- lea 16(%rdi), %rcx
|
|
|
513694 |
+ addq $16, %rdi
|
|
|
513694 |
and $-16, %rax
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm0
|
|
|
513694 |
pmovmskb %xmm0, %edx
|
|
|
513694 |
pxor %xmm1, %xmm1
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm1
|
|
|
513694 |
pmovmskb %xmm1, %edx
|
|
|
513694 |
pxor %xmm2, %xmm2
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm2
|
|
|
513694 |
pmovmskb %xmm2, %edx
|
|
|
513694 |
pxor %xmm3, %xmm3
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm3
|
|
|
513694 |
pmovmskb %xmm3, %edx
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm0
|
|
|
513694 |
pmovmskb %xmm0, %edx
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm1
|
|
|
513694 |
pmovmskb %xmm1, %edx
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm2
|
|
|
513694 |
pmovmskb %xmm2, %edx
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm3
|
|
|
513694 |
pmovmskb %xmm3, %edx
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm0
|
|
|
513694 |
pmovmskb %xmm0, %edx
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm1
|
|
|
513694 |
pmovmskb %xmm1, %edx
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm2
|
|
|
513694 |
pmovmskb %xmm2, %edx
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd (%rax), %xmm3
|
|
|
513694 |
pmovmskb %xmm3, %edx
|
|
|
513694 |
+ addq $16, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 16(%rax), %rax
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
and $-0x40, %rax
|
|
|
513694 |
@@ -133,104 +133,100 @@ L(aligned_64_loop):
|
|
|
513694 |
pminub %xmm0, %xmm2
|
|
|
513694 |
pcmpeqd %xmm3, %xmm2
|
|
|
513694 |
pmovmskb %xmm2, %edx
|
|
|
513694 |
+ addq $64, %rax
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 64(%rax), %rax
|
|
|
513694 |
jz L(aligned_64_loop)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd -64(%rax), %xmm3
|
|
|
513694 |
pmovmskb %xmm3, %edx
|
|
|
513694 |
+ addq $48, %rdi
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea 48(%rcx), %rcx
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd %xmm1, %xmm3
|
|
|
513694 |
pmovmskb %xmm3, %edx
|
|
|
513694 |
+ addq $-16, %rdi
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea -16(%rcx), %rcx
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd -32(%rax), %xmm3
|
|
|
513694 |
pmovmskb %xmm3, %edx
|
|
|
513694 |
+ addq $-16, %rdi
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea -16(%rcx), %rcx
|
|
|
513694 |
jnz L(exit)
|
|
|
513694 |
|
|
|
513694 |
pcmpeqd %xmm6, %xmm3
|
|
|
513694 |
pmovmskb %xmm3, %edx
|
|
|
513694 |
+ addq $-16, %rdi
|
|
|
513694 |
test %edx, %edx
|
|
|
513694 |
- lea -16(%rcx), %rcx
|
|
|
513694 |
- jnz L(exit)
|
|
|
513694 |
-
|
|
|
513694 |
- jmp L(aligned_64_loop)
|
|
|
513694 |
+ jz L(aligned_64_loop)
|
|
|
513694 |
|
|
|
513694 |
.p2align 4
|
|
|
513694 |
L(exit):
|
|
|
513694 |
- sub %rcx, %rax
|
|
|
513694 |
+ sub %rdi, %rax
|
|
|
513694 |
shr $2, %rax
|
|
|
513694 |
test %dl, %dl
|
|
|
513694 |
jz L(exit_high)
|
|
|
513694 |
|
|
|
513694 |
- mov %dl, %cl
|
|
|
513694 |
- and $15, %cl
|
|
|
513694 |
+ andl $15, %edx
|
|
|
513694 |
jz L(exit_1)
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
- .p2align 4
|
|
|
513694 |
+ /* No align here. Naturally aligned % 16 == 1. */
|
|
|
513694 |
L(exit_high):
|
|
|
513694 |
- mov %dh, %ch
|
|
|
513694 |
- and $15, %ch
|
|
|
513694 |
+ andl $(15 << 8), %edx
|
|
|
513694 |
jz L(exit_3)
|
|
|
513694 |
add $2, %rax
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
- .p2align 4
|
|
|
513694 |
+ .p2align 3
|
|
|
513694 |
L(exit_1):
|
|
|
513694 |
add $1, %rax
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
- .p2align 4
|
|
|
513694 |
+ .p2align 3
|
|
|
513694 |
L(exit_3):
|
|
|
513694 |
add $3, %rax
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
- .p2align 4
|
|
|
513694 |
+ .p2align 3
|
|
|
513694 |
L(exit_tail0):
|
|
|
513694 |
- xor %rax, %rax
|
|
|
513694 |
+ xorl %eax, %eax
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
- .p2align 4
|
|
|
513694 |
+ .p2align 3
|
|
|
513694 |
L(exit_tail1):
|
|
|
513694 |
- mov $1, %rax
|
|
|
513694 |
+ movl $1, %eax
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
- .p2align 4
|
|
|
513694 |
+ .p2align 3
|
|
|
513694 |
L(exit_tail2):
|
|
|
513694 |
- mov $2, %rax
|
|
|
513694 |
+ movl $2, %eax
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
- .p2align 4
|
|
|
513694 |
+ .p2align 3
|
|
|
513694 |
L(exit_tail3):
|
|
|
513694 |
- mov $3, %rax
|
|
|
513694 |
+ movl $3, %eax
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
- .p2align 4
|
|
|
513694 |
+ .p2align 3
|
|
|
513694 |
L(exit_tail4):
|
|
|
513694 |
- mov $4, %rax
|
|
|
513694 |
+ movl $4, %eax
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
- .p2align 4
|
|
|
513694 |
+ .p2align 3
|
|
|
513694 |
L(exit_tail5):
|
|
|
513694 |
- mov $5, %rax
|
|
|
513694 |
+ movl $5, %eax
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
- .p2align 4
|
|
|
513694 |
+ .p2align 3
|
|
|
513694 |
L(exit_tail6):
|
|
|
513694 |
- mov $6, %rax
|
|
|
513694 |
+ movl $6, %eax
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
- .p2align 4
|
|
|
513694 |
+ .p2align 3
|
|
|
513694 |
L(exit_tail7):
|
|
|
513694 |
- mov $7, %rax
|
|
|
513694 |
+ movl $7, %eax
|
|
|
513694 |
ret
|
|
|
513694 |
|
|
|
513694 |
END (__wcslen)
|
|
|
513694 |
--
|
|
|
513694 |
GitLab
|
|
|
513694 |
|