Formats/XMA: add 10-bit VLC lookup table, u64 bit-peek, and quant-factor LUT #2663

Open
github-bot wants to merge 1 commit from github-bot/gh-2663 into main AGit
Owner

@⁠RVZO6 on GitHub · 2026-11-25 17:44 UTC · original
RVZO6:rvzo/xma-hot-luts → main · +212 −2 · 1 files · 1 commits · open

Claimed in #1633: #1633

Summary

Speeds up hot XMA2 frame decoding paths in crates/victory-formats/src/xma.rs (+212/-2) with bit-for-bit identical decoded output:

  1. Bits::peek32: reads a single unaligned u64::from_be_bytes word on the hot path (>= 8 bytes remaining) with a 5-byte tail fallback.
  2. Vlc 10-bit primary table: precomputes a Box<[(i32, u8); 1024]> table in Vlc::new resolving >99% of Huffman symbols in O(1), falling back to prefix-bounded binary search for codes > 10 bits.
  3. quant_factor LUT: caches 10.0_f32.powf(exp as f32 / 16.0) in a bit-exact OnceLock<[f32; 384]> table for exp in -128..256 (verified via .to_bits() equality across the full range).

Measured (--release xma::tests::vlc_and_quant_throughput)

Operation Before (main) After Speedup
VLC coef0 28.09 ns/sym 6.30 ns/sym 4.46×
VLC coef1 23.47 ns/sym 5.86 ns/sym 4.00×
VLC vec4 23.76 ns/sym 5.58 ns/sym 4.26×
quant_factor 10.69 ns/op 1.18 ns/op 9.05×

Not a duplicate of

  • Checked open PRs and #1633; no open PR or claim touches crates/victory-formats/src/xma.rs.

Verification

  • Verified on windows-latest MSVC + WARP SM 6.6 CI (both clippy -D warnings profiles, xtask policy 6/6, victory-formats 41/41 including exhaustive bit-exact equivalence tests for peek32, Vlc, and quant_factor): https://github.com/RVZO6/VIctory/actions/runs/45666985023
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon)

**@⁠RVZO6** on GitHub · 2026-11-25 17:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2663) `RVZO6:rvzo/xma-hot-luts` → `main` · +212 −2 · 1 files · 1 commits · open Claimed in #1633: https://git.gtahub.st/github/Marvisak--VIctory/issues/1633 ### Summary Speeds up hot XMA2 frame decoding paths in `crates/victory-formats/src/xma.rs` (`+212/-2`) with bit-for-bit identical decoded output: 1. **`Bits::peek32`:** reads a single unaligned `u64::from_be_bytes` word on the hot path (`>= 8` bytes remaining) with a 5-byte tail fallback. 2. **`Vlc` 10-bit primary table:** precomputes a `Box<[(i32, u8); 1024]>` table in `Vlc::new` resolving >99% of Huffman symbols in O(1), falling back to prefix-bounded binary search for codes > 10 bits. 3. **`quant_factor` LUT:** caches `10.0_f32.powf(exp as f32 / 16.0)` in a bit-exact `OnceLock<[f32; 384]>` table for `exp in -128..256` (verified via `.to_bits()` equality across the full range). ### Measured (`--release xma::tests::vlc_and_quant_throughput`) | Operation | Before (`main`) | After | Speedup | |---|---:|---:|---:| | VLC `coef0` | `28.09 ns/sym` | `6.30 ns/sym` | **4.46×** | | VLC `coef1` | `23.47 ns/sym` | `5.86 ns/sym` | **4.00×** | | VLC `vec4` | `23.76 ns/sym` | `5.58 ns/sym` | **4.26×** | | `quant_factor` | `10.69 ns/op` | `1.18 ns/op` | **9.05×** | ### Not a duplicate of - Checked open PRs and #1633; no open PR or claim touches `crates/victory-formats/src/xma.rs`. ### Verification - Verified on `windows-latest` MSVC + WARP SM 6.6 CI (both clippy `-D warnings` profiles, `xtask` policy 6/6, `victory-formats` 41/41 including exhaustive bit-exact equivalence tests for `peek32`, `Vlc`, and `quant_factor`): https://github.com/RVZO6/VIctory/actions/runs/45666985023 - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon)
Speed up XMA2 frame decoding without changing decoded bits:
- Bits::peek32 reads a single unaligned u64::from_be_bytes word on the hot
  path (>= 8 bytes left) with a 5-byte tail fallback.
- Vlc::new builds a 10-bit primary lookup table (Box<[(i32, u8); 1024]>)
  covering >99% of Huffman symbols in O(1), falling back to a prefix-bounded
  binary search for codes longer than 10 bits.
- quant_factor caches 10^(exp / 16) in a bit-exact OnceLock<[f32; 384]> LUT
  for exp in -128..256 (matching 10.0_f32.powf(exp as f32 / 16.0) to_bits).

Measured (--release vlc_and_quant_throughput):
- vlc coef0: 28.09 -> 6.30 ns/sym (4.46x)
- vlc coef1: 23.47 -> 5.86 ns/sym (4.00x)
- vlc vec4:  23.76 -> 5.58 ns/sym (4.26x)
- quant:     10.69 -> 1.18 ns/op  (9.05x)

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:11:30 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:57 UTC · original

Reviewed: the 10-bit direct lookup is the standard ff_vlc optimization — prefix span fill for len ≤ FAST_BITS, else first-encountered fallback index; peek32's u64 big-endian read covers bit offsets 0–7 for a full 32-bit window, tail path preserved for the last 8 bytes. CI green.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2663#issuecomment-7170229153) Reviewed: the 10-bit direct lookup is the standard ff_vlc optimization — prefix span fill for len ≤ FAST_BITS, else first-encountered fallback index; `peek32`'s u64 big-endian read covers bit offsets 0–7 for a full 32-bit window, tail path preserved for the last 8 bytes. CI green.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 18:22 UTC · original

Independent verification of #2663 (XMA: 10-bit VLC lookup, u64 bit-peek, quant-factor LUT)

PR head 485fb82b4dcf0c8075677b9d5006a3bb3b4c8f12, merges cleanly onto origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca.

Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1, CPU only (VICTORY_WARP=1 / VICTORY_D3D12_WARP=1 still set; this crate touches no GPU), cargo ... -j 4 --locked.

Tests/clippy vs baseline. origin/main: cargo test -p victory-formats --lib --locked = 38 passed, 0 failed, 5 ignored. With #2663: 41 passed, 0 failed, 6 ignored (+3 tests, +1 ignored benchmark). cargo clippy -p victory-formats --all-targets --locked: 0 warnings on both.

Equivalence. Full diff read. peek32: the 8-byte path reads bits pos..pos+32 from one u64 (at most 7+32 bits) and falls back to the old zero-padding loop whenever fewer than 8 bytes remain, so reads past the buffer still see zeros as before. VLC: codes are contiguous, so the first code with a given 10-bit prefix starts that prefix's region; prefixes with no code (the unused tail of an incomplete table) fall back to a search from index 0, which reproduces the old "last code <= v". quant_factor is the same powf evaluated once at startup, so it is bit-exact within a build, with a powf fallback outside [-128, 256). Tests added: peek32 vs the byte loop at every position for lengths 0-24; all 7 Huffman tables vs binary search at each code's first and last value plus a 4 KiB random stream; quant_factor bits vs powf for -200..300.

Perf (release, in-PR benchmark). VLC read 21.5-24.6 -> 4.1-4.3 ns/symbol (5.3-5.7x) on the coef0/coef1/vec4 tables; quant factor 8.63 -> 0.74 ns (11.6x). Synthetic random bitstreams.

Findings: no bugs. Observation: each Vlc now owns an 8 KiB lookup table (7 tables), negligible.

Limits: no game files, so no real XMA streams were decoded; coverage is synthetic (exhaustive at code boundaries plus random streams).

AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.

**@⁠oni-swr** on GitHub · 2026-11-25 18:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2663#issuecomment-7170831525) **Independent verification of #2663** (XMA: 10-bit VLC lookup, u64 bit-peek, quant-factor LUT) PR head `485fb82b4dcf0c8075677b9d5006a3bb3b4c8f12`, merges cleanly onto `origin/main` `13f91caee25f2fdf2c062be5f7a27f058e51cbca`. **Environment:** Windows 11 Pro 10.0.26200, rustc 1.98.1, CPU only (`VICTORY_WARP=1` / `VICTORY_D3D12_WARP=1` still set; this crate touches no GPU), `cargo ... -j 4 --locked`. **Tests/clippy vs baseline.** `origin/main`: `cargo test -p victory-formats --lib --locked` = 38 passed, 0 failed, 5 ignored. With #2663: **41 passed, 0 failed, 6 ignored** (+3 tests, +1 ignored benchmark). `cargo clippy -p victory-formats --all-targets --locked`: 0 warnings on both. **Equivalence.** Full diff read. `peek32`: the 8-byte path reads bits `pos..pos+32` from one `u64` (at most 7+32 bits) and falls back to the old zero-padding loop whenever fewer than 8 bytes remain, so reads past the buffer still see zeros as before. VLC: codes are contiguous, so the first code with a given 10-bit prefix starts that prefix's region; prefixes with no code (the unused tail of an incomplete table) fall back to a search from index 0, which reproduces the old "last code <= v". `quant_factor` is the same `powf` evaluated once at startup, so it is bit-exact within a build, with a `powf` fallback outside [-128, 256). Tests added: `peek32` vs the byte loop at every position for lengths 0-24; all 7 Huffman tables vs binary search at each code's first and last value plus a 4 KiB random stream; `quant_factor` bits vs `powf` for -200..300. **Perf (release, in-PR benchmark).** VLC read 21.5-24.6 -> 4.1-4.3 ns/symbol (5.3-5.7x) on the coef0/coef1/vec4 tables; quant factor 8.63 -> 0.74 ns (11.6x). Synthetic random bitstreams. **Findings:** no bugs. Observation: each `Vlc` now owns an 8 KiB lookup table (7 tables), negligible. **Limits:** no game files, so no real XMA streams were decoded; coverage is synthetic (exhaustive at code boundaries plus random streams). AI-assisted: independent verification by Claude Code / Claude Sonnet 5.5, run on behalf of oni-swr. Claims for #1633.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:22 UTC · original

Automated triage for the maintainers.

Merge candidate (performance, same output). In crates/victory-formats/src/xma.rs:

  • Bits::peek32 reads one big-endian u64 when 8 bytes remain and otherwise falls back to the old loop.
  • Vlc gains a 10-bit direct lookup table, with the old binary search kept for longer codes.
  • quant_factor caches 10^(exp/20) for exponents in [-128, 256), computed once with the same powf.

I checked that codes are handed out contiguously, so a 10-bit region holds either one short code or long codes starting at the region's start. The slow-path search from that index therefore cannot underflow, and the empty tail falls back to a full search, as before. The tests compare against the old paths at every code boundary, at every bit position and for exponents -200..300. The "title" (XMA) data path is unchanged in semantics; the LUT memory is about 8 KiB per table. It merges cleanly; CI check: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2663#issuecomment-7176276956) <!-- victory-triage v1 head=485fb82b4dcf0c8075677b9d5006a3bb3b4c8f12 verdict=merge-candidate at=2026-11-25T22:25:30Z --> Automated triage for the maintainers. **Merge candidate** (performance, same output). In `crates/victory-formats/src/xma.rs`: - `Bits::peek32` reads one big-endian u64 when 8 bytes remain and otherwise falls back to the old loop. - `Vlc` gains a 10-bit direct lookup table, with the old binary search kept for longer codes. - `quant_factor` caches `10^(exp/20)` for exponents in [-128, 256), computed once with the same `powf`. I checked that codes are handed out contiguously, so a 10-bit region holds either one short code or long codes starting at the region's start. The slow-path search from that index therefore cannot underflow, and the empty tail falls back to a full search, as before. The tests compare against the old paths at every code boundary, at every bit position and for exponents -200..300. The "title" (XMA) data path is unchanged in semantics; the LUT memory is about 8 KiB per table. It merges cleanly; CI `check`: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:50 UTC · original

Code review and Windows 11 release benchmark verification at head 485fb82b4dcf merged cleanly onto main (63bcca43c6a0):

  • Code & boundary audit (crates/victory-formats/src/xma.rs):
    • Bits::peek32 (xma.rs:203-210): takes the u64::from_be_bytes fast path only when self.data.get(byte..byte + 8) is Some, falling back safely to peek32_tail() near stream end; bit shifts match across all bit offsets (fast_peek32_matches_byte_loop checks len in 0..=24, pos in 0..=(len*8 + 16)).
    • 10-bit VLC table (xma.rs:258-306): fills 1 << (10 - len) prefix slots for len <= 10, stores the first sorted-table index (idx, 0) for len > 10 falling back to #[cold] read_slow (partition_point(|c| c.0 <= v) - 1; since codes[0].0 == 0 <= v, partition_point >= 1 never underflows). Verified across all 7 XMA2 Huffman tables.
    • Quant-factor LUT (xma.rs:320-338, line 1169): OnceLock 384-entry table for exp in [-128, 256) with single unsigned range check via wrapping_sub, falling back to 10f32.powf(...) out of range; quant_table_matches_powf_bits verifies exact bit equality across -200..=300.
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy -p victory-formats --all-targets -- -D warnings: 0 warnings
    • cargo test --locked -p victory-formats --all-targets: 49/49 passed (6 ignored)
    • --release xma::tests::vlc_and_quant_throughput:
      • vlc coef0: 21.13 -> 3.45 ns/sym (6.12x)
      • vlc coef1: 18.60 -> 3.15 ns/sym (5.90x)
      • vlc vec4: 16.66 -> 3.00 ns/sym (5.55x)
      • quant: 4.84 -> 0.42 ns/op (11.56x)

Clean, bit-exact, and a huge speedup; LGTM.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2663#issuecomment-7179170214) Code review and Windows 11 release benchmark verification at head `485fb82b4dcf` merged cleanly onto `main` (`63bcca43c6a0`): - **Code & boundary audit (`crates/victory-formats/src/xma.rs`)**: - `Bits::peek32` (`xma.rs:203-210`): takes the `u64::from_be_bytes` fast path only when `self.data.get(byte..byte + 8)` is `Some`, falling back safely to `peek32_tail()` near stream end; bit shifts match across all bit offsets (`fast_peek32_matches_byte_loop` checks `len in 0..=24`, `pos in 0..=(len*8 + 16)`). - 10-bit VLC table (`xma.rs:258-306`): fills `1 << (10 - len)` prefix slots for `len <= 10`, stores the first sorted-table index `(idx, 0)` for `len > 10` falling back to `#[cold] read_slow` (`partition_point(|c| c.0 <= v) - 1`; since `codes[0].0 == 0 <= v`, `partition_point >= 1` never underflows). Verified across all 7 XMA2 Huffman tables. - Quant-factor LUT (`xma.rs:320-338`, line 1169): `OnceLock` 384-entry table for `exp in [-128, 256)` with single unsigned range check via `wrapping_sub`, falling back to `10f32.powf(...)` out of range; `quant_table_matches_powf_bits` verifies exact bit equality across `-200..=300`. - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy -p victory-formats --all-targets -- -D warnings`: 0 warnings - `cargo test --locked -p victory-formats --all-targets`: **49/49 passed** (6 ignored) - `--release` `xma::tests::vlc_and_quant_throughput`: - `vlc coef0`: `21.13 -> 3.45 ns/sym` (**6.12x**) - `vlc coef1`: `18.60 -> 3.15 ns/sym` (**5.90x**) - `vlc vec4`: `16.66 -> 3.00 ns/sym` (**5.55x**) - `quant`: `4.84 -> 0.42 ns/op` (**11.56x**) Clean, bit-exact, and a huge speedup; LGTM.
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 04:31 UTC · original · approved these changes

Tested merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-formats --lib xma::: 23 passed, 0 failed, 4 ignored (including new fast_peek32_matches_byte_loop, quant_table_matches_powf_bits, and tabled_vlc_matches_binary_search).
  • cargo clippy -p victory-formats --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 04:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2663#pullrequestreview-6068577919) · **approved these changes** Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-formats --lib xma::`: **23 passed, 0 failed, 4 ignored** (including new `fast_peek32_matches_byte_loop`, `quant_table_matches_powf_bits`, and `tabled_vlc_matches_binary_search`). - `cargo clippy -p victory-formats --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 11:40 UTC · original

NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head 485fb82 (on its base 13f91ca).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 776 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: fast_peek32_matches_byte_loop, tabled_vlc_matches_binary_search, quant_table_matches_powf_bits.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 11:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2663#issuecomment-7191032242) NVIDIA full-suite run, to go with the reports above by Dukestar69, fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head `485fb82` (on its base `13f91ca`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **776 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `fast_peek32_matches_byte_loop`, `tabled_vlc_matches_binary_search`, `quant_table_matches_powf_bits`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 12:10 UTC · original · approved these changes

Reviewed and verified 485fb82b against origin/main (63bcca43; clean git merge-tree):

  • Bits::peek32 (crates/victory-formats/src/xma.rs:203-218) extracts identical bits to the 5-byte tail path across all bit alignments, short buffers, and past physical EOF without byte + 8 overflow.
  • For valid canonical aligned VLC tables, any 10-bit bucket holding codes > 10 bits starts at prefix << 22 <= v and empty buckets fall back to index 0, so partition_point(|c| c.0 <= v) - 1 in Vlc::read_slow (xma.rs:300-306) cannot underflow; documenting or asserting that invariant in Vlc::new would make the safety contract explicit.
  • quant_factor (xma.rs:323-338, 1169) matches baseline's exp / 20.0 across [-128, 255] and falls back cleanly outside that range.

Minor non-blocking notes: the PR description says / 16.0 whereas both the baseline and LUT use / 20.0, and cargo fmt flags line wrapping in the new test lines (xma.rs:1460..1554).

Local verification on Windows 11 (Ryzen 9 9950X):

  • xtask policy (184 files ok) and cargo clippy -p victory-formats --all-targets -- -D warnings (default and --all-features): clean.
  • cargo test -p victory-formats --locked (both debug and --release): 41 passed; 0 failed; 6 ignored.
  • --release vlc_and_quant_throughput: coef0 5.85x (19.89 -> 3.40 ns/sym), coef1 5.83x (18.04 -> 3.10 ns/sym), vec4 5.58x (16.15 -> 2.90 ns/sym), quant 12.48x (4.64 -> 0.37 ns/op).
**@⁠fuzeofficlal** on GitHub · 2026-11-26 12:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2663#pullrequestreview-6073904752) · **approved these changes** Reviewed and verified `485fb82b` against `origin/main` (`63bcca43`; clean `git merge-tree`): - `Bits::peek32` (`crates/victory-formats/src/xma.rs:203-218`) extracts identical bits to the 5-byte tail path across all bit alignments, short buffers, and past physical EOF without `byte + 8` overflow. - For valid canonical aligned VLC tables, any 10-bit bucket holding codes > 10 bits starts at `prefix << 22 <= v` and empty buckets fall back to index `0`, so `partition_point(|c| c.0 <= v) - 1` in `Vlc::read_slow` (`xma.rs:300-306`) cannot underflow; documenting or asserting that invariant in `Vlc::new` would make the safety contract explicit. - `quant_factor` (`xma.rs:323-338, 1169`) matches baseline's `exp / 20.0` across `[-128, 255]` and falls back cleanly outside that range. Minor non-blocking notes: the PR description says `/ 16.0` whereas both the baseline and LUT use `/ 20.0`, and `cargo fmt` flags line wrapping in the new test lines (`xma.rs:1460..1554`). Local verification on Windows 11 (Ryzen 9 9950X): - `xtask policy` (`184 files ok`) and `cargo clippy -p victory-formats --all-targets -- -D warnings` (default and `--all-features`): clean. - `cargo test -p victory-formats --locked` (both debug and `--release`): `41 passed; 0 failed; 6 ignored`. - `--release vlc_and_quant_throughput`: `coef0` **5.85x** (`19.89 -> 3.40 ns/sym`), `coef1` **5.83x** (`18.04 -> 3.10 ns/sym`), `vec4` **5.58x** (`16.15 -> 2.90 ns/sym`), `quant` **12.48x** (`4.64 -> 0.37 ns/op`).
Author
Owner

@⁠rezioliver-collab on GitHub · 2026-11-26 18:00 UTC · original

The speedup from the 10-bit lookup on Apple M1 depended on how many symbols reached the fallback. I compared 485fb82b with its base 13f91cae using identical synthetic bitstreams.

Codes longer than 10 bits coef0 speedup coef1 speedup vec4 speedup
0% 7.73× 7.18× 6.44×
50% 1.79× 1.69× 1.60×
100% 1.02× 0.97× 0.92×

With all-long codes, vec4 went from 33.40 to 36.35 ns/symbol. A fresh build reproduced that result (33.94 to 36.90 ns/symbol). The long-code fractions were chosen explicitly to measure fallback cost.

Each cell used 5,000 deterministic symbols encoded with the corresponding table. I checked every decoded symbol and its ending bit position against the encoder’s record. All 45,000 matched on both revisions. The factors are median base/PR ratios from 12 paired release runs with alternating order, macOS 14.7, Rust 1.98.1.

**@⁠rezioliver-collab** on GitHub · 2026-11-26 18:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2663#issuecomment-7199955356) The speedup from the 10-bit lookup on Apple M1 depended on how many symbols reached the fallback. I compared `485fb82b` with its base `13f91cae` using identical synthetic bitstreams. | Codes longer than 10 bits | `coef0` speedup | `coef1` speedup | `vec4` speedup | |---:|---:|---:|---:| | 0% | 7.73× | 7.18× | 6.44× | | 50% | 1.79× | 1.69× | 1.60× | | 100% | 1.02× | 0.97× | 0.92× | With all-long codes, `vec4` went from **33.40 to 36.35 ns/symbol**. A fresh build reproduced that result (33.94 to 36.90 ns/symbol). The long-code fractions were chosen explicitly to measure fallback cost. Each cell used 5,000 deterministic symbols encoded with the corresponding table. I checked every decoded symbol and its ending bit position against the encoder’s record. All 45,000 matched on both revisions. The factors are median base/PR ratios from 12 paired release runs with alternating order, macOS 14.7, Rust 1.98.1.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2663/head:github-bot/gh-2663'
git switch 'github-bot/gh-2663'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2663'
git switch 'github-bot/gh-2663'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2663'
git switch 'github-bot/gh-2663'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2663'
git switch 'main'
git merge --squash 'github-bot/gh-2663'
git switch 'main'
git merge --ff-only 'github-bot/gh-2663'
git switch 'main'
git merge 'github-bot/gh-2663'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2663
No description provided.