Precompute the XMA inverse MDCT's sine/cosine tables #35
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!35
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-35"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@romainhedouin on GitHub · 2026-11-25 12:33 UTC · original
romainhedouin:perf/xma-imdct-twiddles→main· +69 −5 · 1 files · 1 commits · closed without mergingFor every audio subframe, the XMA decoder computed n sine/cosine pairs that depend only on the size n (128, 256 or 512), and allocated two vectors. The pairs are now computed once per size and kept, and the work buffers live on the stack. The output is bit-for-bit identical: a new test (
cached_twiddles_give_the_same_bits) compares it with the old function on random input for every size.imdct_half, release mode, on a Macsin_coscalls / allocations per callcargo test -p victory-formatspasses; clippy for Windows reports no new warnings.🤖 Generated with Claude Code
@KernelSmoker on GitHub · 2026-11-25 18:14 UTC · original
Release XMA IMDCT comparison at PR #35 (
8851e3d), Intel i9-11900K, Bazzite 45, Rust 1.98.1. The existing bit-equivalence test passed for all 150 synthetic inputs across the three sizes. A local timing harness called the PR's uncached reference and cached implementation in alternating order. Both used the same synthetic input and preallocated output. Median ns per call across eight batches of 2,000 calls each, with the cached table warm:Apply timing.patch to the indicated revision and run cargo test --release --locked -p victory-formats compare_imdct_timings -- --ignored --nocapture. These timings cover the transform only.
Timing harness:
github.com/KernelSmoker/VIctory-Belobug-AMD@1bd2782648/benchmarks/pr35/timing.patch@lcg007xd-c on GitHub · 2026-11-25 21:29 UTC · original · approved these changes
Verified on Linux (Rust 1.98.1)
cargo test -p victory-formats --libon8851e3d: 25 passed, 0 failed, 4 ignored. That includescached_twiddles_give_the_same_bitsand the existingfast_imdct_matches_the_direct_sum. The same with the PR merged into current main (--no-commit).cargo clippy -p victory-formats --target x86_64-pc-windows-msvc: 0 warnings, same as main.git merge --no-commit --no-ffinto main: clean. It also merges cleanly after each of the other openvictory-formatsPRs I looked at (#7, #21, #37, #181).Review notes
sin_cosexpressions, evaluated the same way, so the per-call values are unchanged. The new test confirms this on 150 random inputs.imdct_twiddles()[log2(n) as usize - 7]and theFRAME_SAMPLES / 2stack buffers are safe today. The only caller (xma.rs:965) passessubframe_len, andsubframe_length()(xma.rs:585-597) limits that toFRAME_SAMPLES >> {0,1,2}= 512/256/128, with aMIN_SUBFRAMEcheck.- 7and[Twiddles; 3]silently encodeMIN_SUBFRAME = 128andFRAME_SAMPLES = 512. If either constant changes, for example to 64-sample subframes, this becomes ausizeunderflow or an out-of-bounds panic in the audio thread instead of a decode error. Adebug_assert!(n.is_power_of_two() && (MIN_SUBFRAME..=FRAME_SAMPLES).contains(&n)), or an index computed aslog2(n / MIN_SUBFRAME)with the table size derived from the two constants, would tie them together.I found no defects.
Not verified
walks_saved_streams/matches_a_reference_decodertests need data from outside the repository) and timing on Windows.Reviewed with Claude Code.
@romainhedouin on GitHub · 2026-11-26 22:25 UTC · original
Closing:
a-publieralready has this and more inade1da1. It caches the rotations, bit reversal and butterfly twiddles per subframe size (static ROTATIONS, xma.rs:483) with a bit-identity test (tabled_imdct_gives_the_same_bits). Its lookup falls back to building the table when the index doesn't match, which also covers lcg007xd-c's underflow concern. Thanks for the review and the timings.VICTORY_RECORD,replay --imagesand--retranslate,shaders --listskipensure_outside_repo#510Pull request closed