Skip to content

Vectorize altchars - #1

Open
TkTech wants to merge 2 commits into
simdutf:mainfrom
TkTech:vectorize-altchars
Open

TkTech wants to merge 2 commits into
simdutf:mainfrom
TkTech:vectorize-altchars

Conversation

@TkTech

@TkTech TkTech commented Oct 17, 2026

Copy link
Copy Markdown

Small change to replace conditional byte stores with unconditional selection, allowing GCC to vectorize the substitution loop. Faster altchars is quite useful for things like older IMAP servers and boto, since cloudfront requires two altchars - https://github.com/boto/botocore/blob/develop/botocore/signers.py#L491. I reliably see a 10x improvement.

64 KiB custom encoding: 78.43 us to 6.15 us (12.8x faster) on Ryzen 5800X, GCC 16.2.1, -O3.

Disassembly excerpts:

Before: scalar load and per-byte branches.

12292: movzbl (%rax),%ecx
12295: cmp    $0x2b,%cl
12298: jne    1227d
1229a: mov    %bl,(%rax)
1229c: jmp    12285

After: 16-byte loads, SIMD comparisons and masked selection.

122d1: movdqu 0x20(%rax),%xmm6
122d6: movdqa %xmm1,%xmm7
122da: add    $0x10,%rax
122de: movdqa %xmm6,%xmm3
122e2: movdqa %xmm6,%xmm2
122e6: pcmpeqb %xmm4,%xmm3
122ea: pcmpeqb %xmm5,%xmm2
122ee: pand   %xmm3,%xmm7
122f2: pandn  %xmm6,%xmm3
122f6: movdqa %xmm0,%xmm6
122fa: por    %xmm7,%xmm3
122fe: pand   %xmm2,%xmm6
12302: pandn  %xmm3,%xmm2
12306: por    %xmm6,%xmm2
1230a: movups %xmm2,0x10(%rax)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant