Skip to content

GPU: AVX2 fast-path with skip-unchanged for merge_piece - #1

Closed
altuux wants to merge 1 commit into
rorodev6:full-build-2026-11-25from
altuux:perf/avx2-merge-piece
Closed

altuux wants to merge 1 commit into
rorodev6:full-build-2026-11-25from
altuux:perf/avx2-merge-piece

Conversation

@altuux

@altuux altuux commented Nov 25, 2026

Copy link
Copy Markdown

Summary

Adds a runtime-dispatched AVX2 (32 bytes/iter) fast path to merge_piece in crates/victory-gpu/src/shadow.rs (zero new dependencies, existing scalar fallback preserved):

  • Skip-unchanged fast path: When now[i..i+32] == held[i..i+32] (_mm256_movemask_epi8(eq) == -1), skips reading/writing title and avoids dirtying held cachelines — reducing DRAM traffic from 5 streams to 2 streams on untouched 32-byte blocks.
  • Unit test: Added merge_piece_matches_scalar_across_lengths verifying bit-for-bit agreement with merge_piece_scalar across lengths 0..4096.

Benchmark (i5-12400, 64 MiB = 1024 × 64 KiB pieces)

@altuux

altuux commented Nov 25, 2026

Copy link
Copy Markdown
Author

Closing this PR after re-benchmarking merge_piece on dense [first..=last] spans: because the scalar loop is branchless and LLVM already auto-vectorizes it with SSE2, the branchy skip-unchanged AVX2 path only wins on mostly-unchanged spans and can be slightly slower (~10%) when 50% of 32-byte blocks are modified. (Also, the Belobug#123 speedup cited earlier came from merge_gpu_writes* avoiding redundant writes into mapped D3D12 host memory, which merge_piece does not do.) Keeping the repo clean rather than leaving a questionable micro-opt PR open!

@altuux altuux closed this Nov 25, 2026
Nereziel added a commit to Nereziel/victory that referenced this pull request Nov 25, 2026
Adapt rorodev6#1; preserve scalar default for A/B comparisons.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant