Repository navigation
Vectorize and fuse the med/low piggyback kernels - #45
Merged
Merged
Conversation
None of the piggyback kernels vectorized in the linked binary, including the per-component passes split out for that purpose: LLVM turned each choice between two loaded values into a load from a selected address (a gather), which stops vectorization. (With lto = true the crate's own --emit asm is the pre-link pipeline and doesn't show this.) - Choose between loaded values with a mask blend, so both are loaded. - Fuse affine and affine2p into one loop each, as C does (M from this cell's I/D, in registers), instead of 6 and 12 passes. - Put each loop in an #[inline(never)] function taking every array as a separate slice (noalias), including edit/indel/linear. All five kernels now vectorize. Tie order is unchanged (I1, I2, D1, D2, then misms; later wins), and output is identical to C and main: the differential harness is clean (only the 20 known #22 cases differ). med/low is 0.52-0.83x its previous time on Apple M2 Pro and now faster than C (indel med/low was 1.12-1.34x C). Part of #31. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 15, 2026
Open
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.
Part of #31. This speeds up the
med/lowmemory modes (piggyback backtrace) with no change in output.Cause
None of the piggyback kernels vectorized in the linked binary, including the per-component passes that had been split out to make them vectorize. LLVM rewrote each
if c { a[i] } else { b[i] }, a choice between two loaded values, into a load from a selected address. That is a gather, and it blocks vectorization (the old linear kernel compiles tocsel x25, x11, x25, eq; ldr w25, [x25, x8]).Inspecting the crate's own
--emit asmhides this whenlto = true: that output comes from the pre-link pipeline, which skips loop vectorization. The linked binary (objdump -d) shows what actually runs.Changes (
src/compute/piggyback.rs)(a & m) | (b & !m), so both values are always loaded.wavefront_compute_affine*_idm_piggyback). M is computed from this cell's I/D, which stay in registers. Before, they took 6 and 12 passes.#[inline(never)]function that takes each array as a separate slice parameter, so LLVM knows nothing aliases. linear reuses the edit kernel, since the cell update is the same.All five kernels now vectorize: NEON on this machine, and AVX2 with
target-cpu=nativeon x86.Results
Apple M2 Pro, best of 3, CIGAR, ms.
m1k_5is 20k × 1 kb at 5%;m1k_20is 5k × 1 kb at 20%. C is3282f83.main's time and 0.32–0.83× C's. Before, indel med/low was 1.12–1.34× slower than C.mainin every case above.cargo test, clippy and rustfmt pass.Still to check on x86
The quick sweep on the EPYC 7713, run before this change, had med/low at 1.3–1.9× slower than C built with
-march=native, where GCC vectorizes C's fused loops with AVX2. Re-runningbench/sweep.py --filter ' (med|low)$'onhpcbioamd/hpcbiowith this branch will show whether that gap is closed.🤖 Generated with Claude Code