Skip to content

perf(hevc): shortcut no-refill CABAC decisions - #521

Closed
gunwooterry wants to merge 3 commits into
mainfrom
work/hevc-cabac-mps
Closed

gunwooterry wants to merge 3 commits into
mainfrom
work/hevc-cabac-mps

Conversation

@gunwooterry

@gunwooterry gunwooterry commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

TL;DR

  • Reduce decision overhead in the opt-in x86-64 HEVC decoder while retaining the safe engine for scalar builds and differential checks.

Background

Common most-probable-symbol decisions can finish without consuming another bit, but still pass through the general arithmetic and normalization path. Refs #22.

What changes

Decoded pictures, accepted syntax, errors and caller budgets remain unchanged. Default builds and non-x86-64 decoding are unchanged.

  • Covered: one decoder-private assembly site, checked byte refill, a no-refill decision path, exhaustive arithmetic-state comparisons and a differential fuzz target.
  • Not covered: reconstruction kernels, bypass and termination arithmetic, threading, other architectures' performance or uniform gains across inputs.

After merging: None.

Decisions

  • Keep bin admission, budgets and terminal phases outside assembly. The block uses baseline x86-64 integer instructions and reads only a fixed table at bounded indices; it never reads the byte source or writes memory.
  • Keep one bit position and checked source access. An incomplete refill falls back from the untouched state to preserve partial-read errors; a zero-width decision updates only the range and context state.
  • Retain the safe decision body for short-input fallback and forced-scalar decoding. Compile comparison hooks only for tests or the explicit test-support feature.

Evidence

Verification run: At d362536f3a0ba3a3fd70511878d6a37af3efafd2, formatting, targeted Clippy, the CABAC fuzz-target build and the unsafe-site inventory passed after integrating the newest kernels. The x86 tests cover all 12,501,120 legal range, offset and context combinations, partial refills, invalid contexts and terminal behavior; 258 automatic and 256 scalar tests passed, as did 9,830,892 explicitly fast-versus-safe differential fuzz cases. Decoder-only alternating comparisons against the integrated baseline verified complete pixel and work identity. Complete exact-head conformance/census remains pending. Similarity reported one generic Rust operand/option declaration span, outside the arithmetic templates; a pinned exception and refreshed guard remain pending. No comparison implementation source was read.

Links: entropy design, unsafe-site inventory.

  • Every commit is signed off (git commit -s, DCO).
  • I copied nothing from other implementations.

Open in Capy


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Performance
    • HEVC decoding now uses an optimized CABAC decision engine on supported x86-64 builds. Other builds continue to use the existing decoder.
  • Reliability
    • The optimized engine is checked against the reference decoder across varied inputs, including truncated data and invalid states.

Signed-off-by: Gunwoo Kim <gunwooterry@gmail.com>
Signed-off-by: Gunwoo Kim <gunwooterry@gmail.com>
Signed-off-by: Gunwoo Kim <gunwooterry@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The HEVC decoder adds a table-backed CABAC decision path for non-scalar x86_64 builds, checked bit-window reads, and test-support helpers. Differential tests and a fuzz target compare the fast path with the reference decoder.

Changes: CABAC fast decision path

Layer / File(s) Summary
Checked reads and fast decision engine
crates/coreav-hevc/src/bits.rs, crates/coreav-hevc/src/fast/mod.rs, crates/coreav-hevc/src/cabac.rs, crates/coreav-hevc/src/lib.rs, crates/coreav-hevc/Cargo.toml, docs/design/hevc-entropy.md, docs/unsafe-sites.md
The decoder adds checked CABAC bit-window reads and a table-backed decision implementation for non-scalar x86_64 builds. The crate lint configuration and design documentation describe the unsafe-code scope and decision-path constraints.
Differential validation and fuzz support
crates/coreav-hevc/Cargo.toml, crates/coreav-hevc/src/cabac.rs, crates/coreav-hevc/src/lib.rs, crates/coreav-hevc/fuzz/Cargo.toml, crates/coreav-hevc/fuzz/fuzz_targets/cabac.rs
Test-support helpers compare fast and reference decisions, decoder snapshots, and contexts. Tests and a fuzz target check engine agreement. The fuzz package enables the test-support feature.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@gunwooterry gunwooterry closed this Nov 8, 2026
@capy-ai

capy-ai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Closing because the measured benefit does not justify a permanent assembly site and its maintenance burden.

@gunwooterry gunwooterry mentioned this pull request Nov 8, 2026
13 of 41 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant