perf: use SIMD for ASCII scan, lowercase, and UTF transcoding - #86
Open
anonrig wants to merge 4 commits into
Open
perf: use SIMD for ASCII scan, lowercase, and UTF transcoding#86anonrig wants to merge 4 commits into
anonrig wants to merge 4 commits into
Conversation
Apply SSE2/NEON (SWAR fallback) to the IDNA hot paths: is_ascii, ascii_map, forbidden-domain checks, label-dot scan, and UTF-8/UTF-32 ASCII widen/narrow. Keep scalar tails for short strings and big-endian targets such as s390x. Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
anonrig
marked this pull request as ready for review
August 17, 2026 18:51
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
The common to_ascii path was two full scans (is_ascii, then ascii_map). Lowercase in place and test the high bit in one pass, matching ada-url's to_lower_ascii. Drop SIMD that increased instruction count on short domains: forbidden-code-point table stays a 4-way unroll, label-dot scan is scalar again, and UTF widen/pack share a single load. Process 32 bytes per lowercase/is_ascii iteration and accumulate utf8_length_from_utf32 instead of horizontally summing each block. Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
latest-stable is now 3.23 (apk-tools v3). jirutka/setup-alpine still bootstraps the chroot with a static apk 2.14 binary, so apk add fails with "database: file format is invalid" on qemu ppc64le. Pin to v3.22 (last apk v2) and disable fail-fast so one arch does not cancel the rest. Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
Alpine aarch64 GCC 14 rejects vreinterpretq_u8_s8(vcgtq_s8(...)): vcgtq_s8 already returns uint8x16_t, so the reinterpret is a vector-type conversion error under -Wfatal-errors. Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This speeds up the IDNA hot paths with portable SIMD (SSE2 on x86_64, NEON on aarch64) and a SWAR fallback, while keeping the instruction count down on the short-domain path that dominates
to_ascii.Instruction-count reductions
to_asciiused to scan for ASCII, copy, then scan again to lowercase. It now copies once and runsascii_lowercase_is_ascii: in-place A–Z → a–z plus a high-bit test, the same approach as ada-url’sto_lower_ascii.is_ascii, with a single movemask/max at the end of the vector section.utf8_length_from_utf32in a vector and reduce once, instead of a horizontal sum every 4 code points.SIMD that remains
is_ascii(UTF-8): 32-byte OR + SWAR tailascii_map/ ASCIIto_ascii: vector lowercase + high-bit testis_asciiis no longerconstexpr. The old declaration could not be evaluated at compile time from other TUs, and the vector paths cannot be constexpr.Tests
Coverage for SIMD block sizes and tails (15/16/17/32/33 bytes, unaligned views, non-ASCII at first/middle/last),
ascii_mapwidths, forbidden-domain punctuation, and mixed UTF-8/UTF-32 transcoding. Release, pedantic-Werror, and ASan were run locally. The NEON TU was also cross-compiled withaarch64-linux-gnu-g++and the same warning flags as CI.CI
latest-stableis 3.23 (apk-tools v3).setup-alpinestill bootstraps with a static apk 2.14 binary, soapk addfailed on qemu ppc64le withdatabase: file format is invalid. The Alpine workflow now pins v3.22 (last apk v2) and setsfail-fast: false.vreinterpretq_u8_s8(vcgtq_s8(...))becausevcgtq_s8already returnsuint8x16_t(ACLE). The NEON leading-byte count now uses that return type directly.