Commit 7c0d053
perf(strnlen): widen scan_c_string bounded NUL scan 8B SWAR -> 32B portable-SIMD
strnlen rode the 8-byte SWAR bounded path of scan_c_string while strlen has a
dedicated 64-lane SIMD dispatch — leaving strnlen ~1.79x slower than glibc's
strnlen. Added a 32-byte portable-SIMD NUL scan at the top of the bounded loop:
bounded mode guarantees `limit` readable bytes, so a Simd<u8,32> load is in-bounds
whenever i+32 <= limit (no page check needed). NUL-free panels advance 32; a panel
containing a NUL breaks to the existing 8-byte SWAR / scalar tail, which returns
the exact NUL index — so the result is identical (isomorphic by construction).
This also accelerates the bounded/repair-path length scans of strcmp/strcasecmp/
strncmp/strncasecmp that share scan_c_string.
Before/after (strnlen 4K, ratio = fl / glibc): 1.79x -> 1.26x.
Isomorphism + golden: conformance_diff_strnlen_simd runs 300000 random
(buffer, NUL-position, n) triples — n straddling the 32-byte panel, NULs at every
offset — with 0 divergences vs host glibc strnlen and a pinned sha256 of the
length stream.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 7f1fdb0 commit 7c0d053
2 files changed
Lines changed: 73 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
960 | 960 | | |
961 | 961 | | |
962 | 962 | | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
963 | 979 | | |
964 | 980 | | |
965 | 981 | | |
| |||
Lines changed: 57 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
0 commit comments