Repository navigation
perf(neon): tagged table-lookup hex parse with deferred validation - #61
Merged
Merged
Conversation
📊 Benchmark Comparison Results
➖ 84 benchmarks within noise (click to expand)
Legend: ✅ Faster (>5%) · ⛔ This PR has severe performance regressions (>20% slower). Please investigate before merging. |
mrecachinas
force-pushed
the
perf/neon-hex-lut
branch
from
September 23, 2026 01:54
c70a0db to
178421f
Compare
mrecachinas
force-pushed
the
perf/neon-hex-lut
branch
from
September 23, 2026 02:08
178421f to
104870e
Compare
Parse hex with one vqtbl4q_u8 per 16 chars, indexed by `char - '0'`. Hex digits map to 0x10 | nibble and everything else to 0 (indices past 63, including bytes below '0' after wrapping, also yield 0). XOR of two valid chars cancels the tag, so vcnt of the unpacked XOR is the per-char distance and no nibble packing is needed. Validity is the running lane-wise minimum, checked once per call; the final partial chunk re-reads the last 16 chars and masks the overlap, replacing the 16-char and scalar tails. This takes the steady-state loop from ~50 to ~20 SIMD ops per 32 chars. check_hexstrings_within_dist uses the same parse inside the existing _with_max block structure (eager 32-char blocks, 31-block batches, 16-char chunk, scalar tail). Both parses accept exactly the hex digits and invalid input is still tested before the threshold at every check point, so results are unchanged, including which of "invalid char" and "over max_dist" is reported. The old pack kernel stays as the reference for the tests and hex_hamming_distance_pack. Criterion, "f"*n vs "0"*n (old pack kernel -> new): 32 chars 2.84 -> 2.06 ns 1.38x 64 chars 5.39 -> 3.74 ns 1.44x 128 chars 10.66 -> 7.12 ns 1.50x 254 chars 20.10 -> 13.71 ns 1.47x Interleaved Python A/B (Apple M4 Max, CPython 3.14, previous layer -> this layer): hamming_distance_string/254 46.7 -> 37.3 ns 1.25x hamming_distance_string/1024 106.7 -> 75.4 ns 1.42x hamming_distance_string/4096 378.4 -> 254.9 ns 1.48x hamming_distance_string/63 34.0 -> 28.4 ns 1.19x check_hexstrings_within_dist/254,d=60 38.5 -> 34.0 ns 1.13x Tests: - Exhaustive comparison against the classic kernel at lengths 0..=300 and around the batch boundaries. - Every invalid byte class at every position for lengths 1..=80. - 6000 randomized _with_max cases against the pack kernel. The test asserts that cases decided by precedence occur, both invalid-wins and threshold-wins. - A 60k-case Python differential against the previous layer found no divergences in values or error messages. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: c7edd725-5714-4044-acf4-c9afc6ec8cf8
mrecachinas
force-pushed
the
perf/neon-hex-lut
branch
from
September 23, 2026 11:59
104870e to
cbe0557
Compare
23 tasks
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.
Replaces the NEON arithmetic hex parse with a tagged table lookup: one
vqtbl4q_u8per 16 chars, indexed bychar - '0'.How it works
0x10 | nibble; every other byte maps to 0.vcntof the unpacked XOR is the per-char distance. No nibble packing is needed.Semantics unchanged
check_hexstrings_within_distuses the new parse inside the existing_with_maxblock structure, with the same check points.max_dist" wins.hex_hamming_distance_pack.Criterion,
"f"*nvs"0"*n(old pack kernel → new):Interleaved Python A/B (Apple M4 Max, CPython 3.14, previous layer → this layer):
hamming_distance_string254 charshamming_distance_string1024 charshamming_distance_string4096 charshamming_distance_string63 charscheck_hexstrings_within_dist254 chars, d=60Tests
_with_maxcases against the pack kernel. The test asserts that precedence-deciding cases (invalid-wins and threshold-wins) both occur.