[libc-commits] [libc] [libc] Implement generic SIMD helper 'simd.h' and implement strlen (PR #152605)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Tue Aug 26 11:10:02 PDT 2025
jhuber6 wrote:
I updated this to provide a more comprehensive header and interface using some of the fixed I've landed in upstream clang. The generated ASM for AVX512 looks like this, so I think it's roughly equivalent to the 'hand-rolled' versions. This one uses the generic version if they are available.
```asm
strlen: # @srlen
.cfi_startproc
# %bb.0: # %entry
movq %rdi, %rax
andq $-64, %rax
vmovdqa64 (%rax), %zmm0
subl %eax, %edi
vptestnmb %zmm0, %zmm0, %k0
kmovq %k0, %rcx
shrxq %rdi, %rcx, %rcx
testq %rcx, %rcx
jne .LBB0_4
# %bb.1: # %for.cond.preheader
addq $64, %rax
.p2align 4
.LBB0_2: # %for.cond
# =>This Inner Loop Header: Depth=1
vmovdqa64 (%rax), %zmm0
addq $64, %rax
vptestnmb %zmm0, %zmm0, %k0
kortestq %k0, %k0
je .LBB0_2
# %bb.3: # %cleanup.thread
kmovq %k0, %rcx
.LBB0_4: # %cleanup35
tzcntq %rcx, %rax
vzeroupper
retq
```
There's some stuff I could add, mostly helpers around shuffling and whatnot, but I'll save that for later.
https://github.com/llvm/llvm-project/pull/152605
More information about the libc-commits
mailing list