Repository navigation
av1enc: specialise the inverse transform per size, size the forward tmp buffer - #2396
Conversation
…mp buffer The inverse transform computed its bit-reversal permutations and loop bounds at run time and went through one generic path for every size. inverse_dct, the ADST permutations and inverse_2d are now const generic over the size and inlined, so the permutations fold at compile time. forward_2d zeroed a 4 KiB tmp buffer on every call, even for 4x4. It now dispatches to a fixed-size version for 4, 8 and 16 (tmp is exactly n*n floats); 32 keeps the run-time version, which measured faster than a const 32 variant. The float operation order is unchanged. Output is bit-identical. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Inverse transform specialization crates/av1enc/src/transform.rs |
Inverse DCT and ADST helpers use const-generic sizes. The inverse transform entry points dispatch to size-specific implementations. |
Forward transform specialization crates/av1enc/src/transform.rs |
forward_2d uses fixed-size implementations with sized temporary arrays for 4×4, 8×8, and 16×16 blocks. Other sizes, including 32×32, use the dynamic implementation. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Refactor · Severity of issue fixed: Medium
Possibly related issues
- storytold/effectcraft#2376 — This issue proposes a butterfly forward DCT/ADST implementation. This pull request specializes the existing forward transform by block size.
Suggested reviewers: echelon
Merge Risk: 
Minimal · up to c99b2
-
No merge-blocking risk is established for the transform specialization; normal checks remain appropriate.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Issue
#2372requires inverse-transform specialization by size and a forward-transform temporary buffer sized to the block. The diff adds const-genericinverse_dct_n, ADST permutation helpers, andinverse_2d_ndispatch for sizes 4 through 32.forward_2duses fixed-size buffers for 4×4, 8×8, and 16×16. The 32×32 path remains dynamic, as allowed by the issue proposal and PR description. The optional inverse column pass is not required. The PR reports unchanged output and passing encoder tests.
Full details: Out of Scope Changes check
-
Explanation
The whole-PR diff changes only
crates/av1enc/src/transform.rs. All changes support issue#2372by specializing transform code or sizing the forward temporary buffer. No unrelated behavior or file changes are present.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 16 functions across 1 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
This PR is one of five output-identical speed PRs for the AV1 encoder (
|
…ugh them The strict-clippy split of inverse_dct (storytold#2496) passes n at run time; inlining keeps inverse_dct_n's compile-time sizes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged, thank you @vangel76! It landed on |
Fixes #2372
What
inverse_dct, the ADST permutations andinverse_2dare const generic over the transform size and#[inline(always)], so the bit-reversal permutations and loop bounds fold at compile time (they were about 6 % of the encode by themselves).forward_2dno longer zeroes a 4 KiBtmpon every call: 4x4, 8x8 and 16x16 use a fixed-size version withtmp: [f32; N*N]. 32x32 keeps the run-time version (a const 32 variant measured slower). Float operation order is unchanged.crates/av1enc/src/transform.rschanges.Output is identical
md5 of the encoded stream, base vs this branch, all equal:
cargo test --release -p effectcraft-av1encpasses (roundtrip, ffmpeg/dav1d oracle),cargo fmt --all --checkandcargo clippy -p effectcraft-av1enc --all-targets -- -D warningsare clean.Speed
1080p synthetic sequence, 10 frames, one thread pinned (
taskset -c 1),perf stat -e instructions:u,cycles:u, base and branch alternating, median of 5 rounds, baseline x86-64 build:Not included: lane-parallel column pass (B6)
The optional second step of the issue (inverse column pass over whole rows) was measured on top of this on the baseline build: instructions another -1.5 % / -1.4 %, but cycles +0.9 % / +1.3 % and wall unchanged (Q76 6.11 s, BR 10.99 s). Without a wider ISA there is no signed 32x32->64 multiply to vectorise with, so there is no measurable gain here and it is left out. It would only pay with
-C target-cpu=x86-64-v3(#2377).🤖 Generated with Claude Code
Summary by CodeRabbit