Skip to content

GPU: AVX2 fast-path for merge_piece, first_difference, and last_difference - #1

Open
altuux wants to merge 1 commit into
DexNom:mainfrom
altuux:perf/avx2-shadow-merge-diff
Open

altuux wants to merge 1 commit into
DexNom:mainfrom
altuux:perf/avx2-shadow-merge-diff

Conversation

@altuux

@altuux altuux commented Nov 25, 2026

Copy link
Copy Markdown

Summary

Adds runtime-dispatched AVX2 (32 bytes/iter) fast paths to merge_piece, first_difference, and last_difference in crates/victory-gpu/src/shadow.rs (with zero new dependencies and the existing scalar/u64 implementations preserved as fallbacks):

  1. merge_piece (AVX2 + 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.
  2. first_difference & last_difference (AVX2 32 B/iter): Scans 32 bytes per iteration via _mm256_cmpeq_epi8 + _mm256_movemask_epi8 + trailing_zeros/leading_zeros.
  3. Unit tests: Extended difference_tests to cover 31/32/33/64/65/97-byte boundaries and added merge_piece_matches_scalar_across_lengths verifying bit-for-bit agreement with the scalar implementation.

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

  • merge_piece: 13.64 ms → 6.94 ms (1.97× faster, 4.58 → 9.01 GB/s single-thread)
  • first_difference: 4.42 ms → 3.04 ms (1.46× faster, 14.13 → 20.57 GB/s)

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