8000 perf(ll): speed up the arm64 NEON mate-rescue kernel by nh13 · Pull Request #45 · nh13/minibwa · GitHub
[go: up one dir, main page]

Skip to content

perf(ll): speed up the arm64 NEON mate-rescue kernel - #45

Draft
nh13 wants to merge 1 commit into
perf/ll-sse-affine-reassoc-armfrom
perf/ll-neon-v2
Draft

nh13 wants to merge 1 commit into
perf/ll-sse-affine-reassoc-armfrom
perf/ll-neon-v2

Conversation

@nh13
@nh13 nh13 commented Sep 7, 2026
Copy link
Copy Markdown
Owner

What

Speeds up minibwa's #2 short-read hotspot — the Farrar striped mate-rescue Smith-Waterman kernel (ksw_ll_u8_core / ksw_ll_i16_core) — on arm64/NEON only, on top of the existing perf/ll-sse-affine-reassoc-arm feature. Every change is #if defined(__ARM_NEON)-gated; the x86 path is byte-identical to the prior kernel.

  • Hybrid recurrence: E' reads the reduced H' (classic), F' reads max(M,E) — one max off the loop-carried chain.
  • USQADD with an unshifted signed query profile: one saturating op for the match-add instead of uqadd+uqsub. Exact — any divergence is past the score ceiling, where the existing gmax+shift>=255 early exit already fires.
  • Pair-lookahead in the lazy-F correction (F'(j+2) folded), halving that chain, with a cheaper exit test (cmhi/shrn/fmov) and stripe-pair umaxp reduction; the block is skipped when F'(i,slen)==0.
  • Interleaved {H,E} ping-pong buffers, one paired store per stripe (last pair peeled so the next row's diagonal input isn't delayed). The widened ksw_ll_qinit layout that feeds this is gated on __ARM_NEON, so non-ARM builds keep the original allocation.
  • Row max from max(M,E); deferred Hmax copy; hoisted invariants; register carry of H'(i,slen-1) across rows.

The reassociation fast path is gated on gapo>0 (verbatim baseline otherwise), so the gapo>=0 precondition holds by construction — mate rescue calls with gapo=(q+a-1)/a >= 0.

Performance (bwa-bsw-bench, arm64 Graviton4 c8g, best-of-7 ×2)

qlen baseline Mc/s candidate Mc/s wide x
100 3792 5176 1.36×
150 4021 5175 1.29×
250 4002 5174 1.29×

At production-like rescue hit-rates the gain is larger (1.5–1.9×), since the lazy-F work is a smaller share there. x86 (c6a): neutral (1.00×), byte-identical — the guard leaves the x86 path unchanged.

Correctness

  • ./sw_bench --check --mode rescue: PASS — 120,000 pairs identical in score and CIGAR.
  • A differential harness comparing the full ksw_llrst_t (score/te/qe/score2/te2, not just score) between baseline and candidate, both cores, across many gap-parameter sets including o=0 and the pe.c-derived gapo, plus small-slen boundary cases — 0 mismatches.
  • Full-aligner SAM byte-identity vs the baseline kernel on real WGS PE reads (mate-rescue path), on both arm64 and x86.

Note on the standing gate: sw_bench --check --mode rescue currently compares only .score; the qe/te/score2 fields (which pe.c consumes) were verified equal out-of-band as above. Follow-up: extend the sw-kernel-bench rescue adapter to diff those fields so future changes to this kernel are gated on them too.

Draft, feature-labeled review vehicle — installation is the manifest's job, not this PR.

Optimize the Farrar striped mate-rescue kernel (ksw_ll_u8_core / ksw_ll_i16_core)
on arm64, building on the affine-gap reassociation. All changes are arm64-gated and
bit-identical to the baseline; the x86 path is unchanged.

- Hybrid recurrence: E' reads the reduced H' (classic), F' reads max(M,E), dropping
  one max off the loop-carried chain.
- USQADD with an unshifted signed query profile: one saturating op for the match add
  instead of uqadd+uqsub. Exact -- any divergence is past the score ceiling, where the
  existing gmax+shift>=255 early exit already fires.
- Pair-lookahead in the lazy-F correction (F'(j+2) folded), halving that chain, with a
  cheaper exit test (cmhi/shrn/fmov) and stripe-pair umaxp reduction; the block is
  skipped when F'(i,slen)==0.
- Interleaved {H,E} ping-pong buffers with one paired store per stripe (last pair peeled
  so the next row's diagonal input is not delayed). The widened qinit layout that feeds
  this is gated on __ARM_NEON, so non-ARM builds keep the original allocation.
- Row max taken from max(M,E); deferred Hmax copy; hoisted invariants; register carry of
  H'(i,slen-1) across rows.

The reassociation fast path is gated on gapo>0 (verbatim baseline otherwise), so the
gapo>=0 precondition holds by construction (mate rescue calls with gapo=(q+a-1)/a >= 0).

Validated: sw_bench --check --mode rescue PASS (120k pairs); a differential harness over
both cores comparing every ksw_llrst_t field (score/te/qe/score2/te2) across many
gap-parameter sets incl. o=0 and the pe.c-derived gapo, 0 mismatches; full-aligner SAM
byte-identity on real WGS PE reads. +30% on Graviton4 (1.36/1.29/1.29x at qlen
100/150/250; 1.5-1.9x at production rescue hit-rates); neutral/byte-identical on x86.
@nh13 nh13 added feature review vehicle for a manifest feature; never a merge vehicle uninstalled No features.toml block yet; not installed into the distribution (dist). Remove when installed. labels Sep 7, 2026
@coderabbitai
coderabbitai Bot commented Sep 7, 2026 •
Copy link
Copy Markdown

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nh13
nh13 commented Sep 7, 2026
Copy link
Copy Markdown
Owner Author

@coderabbitai pause

@coderabbitai
coderabbitai Bot commented Sep 7, 2026
Copy link
Copy Markdown
✅ Action performed

Reviews paused.

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

Labels

feature review vehicle for a manifest feature; never a merge vehicle uninstalled No features.toml block yet; not installed into the distribution (dist). Remove when installed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0