Repository navigation
Conversation
|
Reviewed at eabd204 by Claude Opus 5.5, with a second opinion from Codex Medium and muse-spark-1.3-contributor (via pi, thinking high). The AVX2 kernel produces exactly the scalar xoshiro256++ stream, detection keeps it off CPUs without AVX2, and the output is byte-identical to Sequence identity. Run on a disposable VM worker (AMD Ryzen 9 9955HX, Zen 5, which has AVX-512). I forced each kernel on an CPUs without AVX2. Output parity. All 37 effects, 3 seeds, framed and Test gap (Claude and both reviewers). Stale SAFETY comments (Codex). The comments on both arms say The fix, not pushed. I could not push to this branch from here, so it is below for you to apply. It is one commit to - // SAFETY: `lanes` is only recorded when AVX-512F is available.
+ // SAFETY: `avx512` is only set when AVX-512F is available.
Some(lanes) if self.avx512 => unsafe { self.refill_lanes(lanes) },
#[cfg(target_arch = "x86_64")]
- // SAFETY: `lanes` is only recorded when AVX2 is available.
+ // SAFETY: `avx2` is only set when AVX2 is available.
Some(lanes) if self.avx2 => unsafe { self.refill_lanes_avx2(lanes) },
@@ fn batches_follow_the_stream
- // several batches, so the lane path (when available) runs too
- let mut rng = Rng::seeded(99);
- let mut s = Rng::seeded(99).s;
- for _ in 0..3 * BATCH + 17 {
- assert_eq!(rng.next_u64(), scalar_step(&mut s));
+ // several batches, so the lane paths run too: every kernel the CPU
+ // has, since refill only ever picks the widest
+ for (avx512, avx2) in [(false, false), (false, true), (true, true)] {
+ let mut rng = Rng::seeded(99);
+ rng.avx512 &= avx512;
+ rng.avx2 &= avx2;
+ let mut s = Rng::seeded(99).s;
+ for _ in 0..3 * BATCH + 17 {
+ assert_eq!(rng.next_u64(), scalar_step(&mut s));
+ }
}Performance, measured rather than taken from the description. This worker has AVX-512, so on it this branch changes nothing natively: matrix and decrypt land within noise in both orders. I simulated an AVX2-only CPU with Consider (not a defect in this branch). Second opinion. Both reviewers traced the kernel by hand and found it exact: the state update order, the 23/41 and 45/19 rotate pairs, the jump mask including bit 63, the per-128-bit-lane unpack, and the 0x20/0x31 permutes. That agrees with what the worker showed. They could read this review's working notes, so their agreement is not guaranteed independent. The stale SAFETY comments were Codex's alone. Next. This waits on you, @ashveikin, to apply the test change above or make your own. It also waits on the maintainer: CI on this branch is waiting for workflow approval and has not run. |
|
Closing this because the speedup it is for didn't reproduce. On a Ryzen 9 9955HX worker, with AVX-512 turned off so the AVX2 kernel is the one in use ( |
Adds AVX2 optimisation alongside already existing AVX-512 for
src/utils/rng.rsWhy?
The Steam Hardware & Software Survey 2026 shows that AVX2 support is vastly more prevalent (around 95.4%) compared to AVX-512 support (around 23.9%), meaning that having an AVX2 fallback is going to cover more CPUs, thus making the optimisations available to more people on older CPUs.
How it fits in
src/utils/rng.rsVerification
All effects pass all available tiers (up to AVX2 for my machine) (
oracle-simd.sh quick)cargo test --releasepassesPerformance
Measured on Intel i7-10850H (12) with
python3 tools/tests/bench_compare.py /tmp/ttfx-before target/release/ttfx --size 200x50 --repeats 31 --warmups 2 --cpu 8The only reliable speedup was ~1.1–1.2x on matrix effect, every other effect ramained the same.
The same matrix animation (virtual clock, pacing off) completes ~1.1–1.2x faster using the test above - under the real clock that translates to better frame-rate.