XMA: cache IMDCT rotation tables per subframe size #172

Merged
TG0000 merged 1 commit from upstream-pr/172 into main 2026-11-25 00:18:47 +00:00
TG0000 commented 2026-11-24 01:05:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by TG0000 on 2026-11-24T01:05:36Z.


Summary

Caches the pre/post rotation tables, bit-reversal order, and butterfly twiddle factors once per XMA subframe size (128, 256, and 512 samples) in imdct_half (crates/victory-formats/src/xma.rs) and replaces the per-call heap Vec work buffers with stack arrays.

Why

Previously, imdct_half recomputed sin_cos for every pre- and post-rotation on every subframe call and allocated two fresh Vec buffers per call. Precomputing those tables once per subframe size removes the repeated trig work and per-subframe heap allocations while preserving bit-for-bit identical output (each table value uses the exact same floating-point expression and butterfly recurrence as before).

Measured performance (synthetic release benchmark)

  • 3.2×–4.4× (3.7× overall) faster imdct_half across the 128/256/512 subframe sizes in MSVC release builds.
  • Note: synthetic audio-decoder microbenchmark only; end-to-end retail title frame time was not measured.

Testing

  • Added/ran unit tests in ictory-formats verifying bit-for-bit equivalence against the original implementation across all subframe sizes.
  • cargo clippy (no new warnings) and cargo run -p xtask -- policy passed.

AI-assisted (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572235667 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/172). Originally posted by [TG0000](https://github.com/TG0000) on 2026-11-24T01:05:36Z. --- ### Summary Caches the pre/post rotation tables, bit-reversal order, and butterfly twiddle factors once per XMA subframe size (128, 256, and 512 samples) in imdct_half (crates/victory-formats/src/xma.rs) and replaces the per-call heap Vec work buffers with stack arrays. ### Why Previously, imdct_half recomputed sin_cos for every pre- and post-rotation on every subframe call and allocated two fresh Vec buffers per call. Precomputing those tables once per subframe size removes the repeated trig work and per-subframe heap allocations while preserving bit-for-bit identical output (each table value uses the exact same floating-point expression and butterfly recurrence as before). ### Measured performance (synthetic release benchmark) - ~**3.2×–4.4×** (~**3.7×** overall) faster imdct_half across the 128/256/512 subframe sizes in MSVC release builds. - Note: synthetic audio-decoder microbenchmark only; end-to-end retail title frame time was not measured. ### Testing - Added/ran unit tests in ictory-formats verifying bit-for-bit equivalence against the original implementation across all subframe sizes. - cargo clippy (no new warnings) and cargo run -p xtask -- policy passed. *AI-assisted (Claude Opus 5.5).*
DaviTostes commented 2026-11-24 06:54:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:23:22Z.


Tested 4eb0898 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-formats: 22 passed, 0 failed, 4 ignored (2 test binaries), including the 3 tests this PR adds.

No game data used.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7119051347 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/172#issuecomment-7119051347). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:23:22Z. --- Tested `4eb0898` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-formats`: **22 passed, 0 failed, 4 ignored** (2 test binaries), including the 3 tests this PR adds. No game data used.
upstream-sync closed this pull request 2026-11-25 01:02:53 +00:00
Marvisak commented 2026-11-25 01:07:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:20:46Z.


Automated triage for the maintainers.

Merge candidate. imdct_half in crates/victory-formats/src/xma.rs now builds the pre/post rotations, bit-reversal order and butterfly twiddles once per subframe size (128/256/512, in a OnceLock like the existing windows()) and uses a stack buffer sized by FRAME_SAMPLES instead of two Vecs per call. Each table entry uses the same expression and the same per-stage running product as the old per-call code; other sizes still build tables on the spot, and tabled_imdct_gives_the_same_bits compares the output bit for bit against the old transform for n = 2…2048. The ~3.7x speed-up is for the transform alone; no in-title measurement.

CI: no check runs on the head commit.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148412127 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/172#issuecomment-7148412127). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:20:46Z. --- <!-- victory-triage v1 head=4eb0898b3cbd6d0bbbffad540aca5d7e3531ac58 verdict=merge-candidate at=2026-11-25T00:18:15Z --> Automated triage for the maintainers. **Merge candidate.** `imdct_half` in `crates/victory-formats/src/xma.rs` now builds the pre/post rotations, bit-reversal order and butterfly twiddles once per subframe size (128/256/512, in a `OnceLock` like the existing `windows()`) and uses a stack buffer sized by `FRAME_SAMPLES` instead of two `Vec`s per call. Each table entry uses the same expression and the same per-stage running product as the old per-call code; other sizes still build tables on the spot, and `tabled_imdct_gives_the_same_bits` compares the output bit for bit against the old transform for n = 2…2048. The ~3.7x speed-up is for the transform alone; no in-title measurement. CI: no check runs on the head commit. --- _Generated by [Claude Code](https://claude.ai/code)_
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!172
No description provided.