forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 68c67bf9b2c11830fc5a391a5d89d4e2e7b16ae2

2026-09-04

perf(av1): the DPB shares one Arc per picture instead of copying it per slotAhmet Kaan Gümüş · 68c67bf
perf(av1): the DPB shares one Arc per picture instead of copying it per slot

`refresh_frame_flags` names up to eight reference slots, and each one took a
full `Picture` copy -- ~25 MB at 4K, so a key frame alone memcpy'd ~200 MB and
every inter frame paid one copy per slot it refreshed. `perf --call-graph fp`
attributes 2.2 of the 5.7% `memmove` self time to `decode_stream`'s own frame
(the slot stores), the rest to the tile decode, `decode_inter_block`, loop
restoration and the per-TU transform buffer.

The slots now hold `Arc<Picture>`: one allocation per decoded frame, pointer
copies per slot, and the shown-frame sink borrows either the grain-synthesised
picture or the stored one instead of moving a copy through `output`.

seg4k 38.59 s -> 37.62 s (medians of 3 interleaved pairs); byte-exact on
seg1080/seg4k/seg4k_lr/palette.
perf(av1): Wiener restoration runs on the motion-compensation kernelsAhmet Kaan Gümüş · 91d30fe
perf(av1): Wiener restoration runs on the motion-compensation kernels

`apply_loop_restoration_plane` was 6.3% of a 4K decode's self time, and
Wiener owns most of it: on the two 4K probe inputs Wiener units cover
82% and 95% of all restored pixels (instrumented, then reverted).

Its two passes ARE `mc.rs`'s: a 7-tap `i16` convolution over contiguous
samples rounded by `Round2(_, 3) == INTER_ROUND_0`, then a 7-tap `i32`
one rounded by `Round2(_, 11) == INTER_ROUND_1`. Zeroing an eighth tap
makes both `mc::hpass_contig`/`mc::vpass_row` calls exactly -- so this
reuses those AVX2/SSE kernels rather than growing a third copy of the
same convolution.

That also removes the horizontal pass's real cost: it called
`lr_sample` (stripe-boundary substitution plus a column clamp) once per
tap, seven times per output. Which buffer and row a sample comes from
depends only on the row, so `lr_sample` is now that resolution
(`lr_src_row`) plus its clamp, and the pass resolves it once per row and
convolves straight over the plane -- only a unit touching the plane's
left or right edge still copies through the clamp.

4K decode 40.6 s -> 35.7 s and the LR-heavy 4K input 40.1 s -> 34.1 s
(interleaved medians of 3 against this lane's base), byte-exact on all
four probe inputs.
perf(av1): AVX2 deblock kernel -- 4K decode 40.6 s -> 38.1 sAhmet Kaan Gümüş · 1332eb0
perf(av1): AVX2 deblock kernel -- 4K decode 40.6 s -> 38.1 s

`filter_edge` was 8.0% of a 4K decode's self time and `edge_params`
another 3.5%; `perf annotate` puts the cost on the per-tap strided
addressing (`leaq`/`movzwl` pairs), not the arithmetic, which is why
lane-perf7's three scalar restructures all measured neutral-to-worse.

This filters 16 edge lines at once in 16-bit AVX2 lanes: the same masks,
the same `filter4` centred-domain clamps and the same `filter6`/`8`/`14`
weighted sums (their weights total 8 or 16, so a sum of 12-bit samples
stays inside `u16` and the rounding shift is the unsigned one). A
horizontal edge's taps are whole row segments, loaded directly; a
vertical edge's are consecutive samples, so 16 rows are loaded as a
16x16 tile and transposed through the unpack ladder.

Both passes now iterate the edge's own direction innermost so four
consecutive 4-sample groups can share one kernel call. The swap is
order-preserving: a group's writes reach only along its own edge, so
the dependence stays on the outer loop's ascending order. Where the
four groups' `edge_params` disagree, or the edge sits too close to a
plane border for the kernel's window, the scalar `filter_edge` still
runs -- it remains the reference, and a property test pins the kernel
to it sample-exact over every bit depth, filter length, level,
sharpness and both directions.

Byte-exact on all four probe inputs (1080p, 4K, 4K+LR, palette).
perf(av1): loop restoration stops re-reading its clamp and re-allocatingAhmet Kaan Gümüş · a88f7f4
perf(av1): loop restoration stops re-reading its clamp and re-allocating

`apply_loop_restoration_plane` is 5.95% of a 4K decode's self time after
the CDEF kernel landed, and two of its costs are pure overhead:

* both stripe kernels read `decode::sample_max()` -- a thread-local plus
  a shift -- once per OUTPUT SAMPLE, to clamp with. The bound is the
  frame's, so it is now resolved once per stripe.
* `apply_wiener_stripe`'s horizontal-pass intermediate and `compute_ab`'s
  two (A, B) grids were freshly allocated per stripe (~70 KB each for a
  64-wide sgrproj unit, two per stripe), so every page also faulted in on
  first touch. Both are reused thread-local scratch buffers now, the way
  lane-perf6 already did for the whole-plane buffers. Every entry of each
  is written before it is read, so the resize fill value never shows.

No arithmetic changed. Byte-exact on all four gate inputs (seg1080,
seg4k, seg4k_lr, palette). Interleaved medians 3x: seg4k_lr 40.47 s ->
39.59 s (-2.2%), seg4k 41.53 -> 41.22 s, 1080p 11.08 -> 10.83 s.
perf(av1): AVX2 CDEF filter -- 4K decode 47.1 s -> 41.2 sAhmet Kaan Gümüş · e2f820e
perf(av1): AVX2 CDEF filter -- 4K decode 47.1 s -> 41.2 s

`cdef_filter_block` was 13.1% of a 4K decode's self time: a scalar loop
doing ~17 bounds-checked window reads, four `constrain` calls and a
min/max clamp per output sample.

The kernel does the same arithmetic 16 samples (two rows) at a time in
16-bit AVX2 lanes -- the same primary/secondary taps, the same
`sign(diff) * clamp(threshold - (|diff| >> shift), 0, |diff|)` (one
`_mm256_sign_epi16` reproduces `signum`, zero included), the same
exclusion of the `CDEF_VERY_LARGE` out-of-frame sentinel from the max
clamp (masking it to 0 cannot win a max seeded with a non-negative
sample), and the same `x + ((8 + sum - (sum < 0)) >> 4)` rounding.
16-bit lanes are exact for every value the filter sees: window samples
are in [0, 0x4000], so a tap difference fits in `i16` and the
tap-weighted sum is bounded by 24 * the threshold (at most 15 << 4).

The scalar form stays the reference (`cdef_filter_block_scalar`, the
only path on non-x86_64 and pre-AVX2 CPUs) and
`cdef_simd_kernel_matches_the_scalar_filter` pins the pair over the
whole domain: both block shapes, all 8 directions, every enable pair,
the 8/10/12-bit strength/damping ranges and windows that mix real
samples with sentinel borders.

Byte-exact on all four gate inputs (seg1080, seg4k, seg4k_lr, palette).
seg4k interleaved medians 3x: 47.08 s -> 41.23 s (-12.4%, 5.78 ->
6.60 fps); 1080p 11.00 -> 10.95 s.
perf(av1): separable box sums in the sgrproj a/b passAhmet Kaan Gümüş · ac194aa
perf(av1): separable box sums in the sgrproj a/b pass

`compute_ab` summed every grid point's own (2r+1)x(2r+1) window from
scratch, so each source sample went through `lr_sample` -- whose
stripe-boundary substitution is the expensive part -- (2r+1) times more
often than necessary. One column-sum pass per grid row reads each sample
once and the point's box is then (2r+1) adds of those i64 column sums;
integer addition is exact and associative, so every total is unchanged.
The per-point bit-depth read is hoisted out with it.

Byte-exact on seg1080/seg4k/seg4k_lr/palette; 4K 59.37 s -> 46.15 s
(1.286x, from 1.252x at the previous step), LR-heavy 4K cut 57.21 s ->
50.47 s (1.134x).
perf(av1): resolve the deblock kernels' bit-depth reads once per callAhmet Kaan Gümüş · 801fe73
perf(av1): resolve the deblock kernels' bit-depth reads once per call

`filter4` runs once per deblocked sample and read the thread-local bit
depth nine times doing it -- once for its centring constant and once
inside each of `sclamp`'s eight calls -- while `filter_edge` re-read it
through `sample_max()` on all fifteen of its stores. Both are constant
for the whole call; same bounds, read once.

Byte-exact on seg1080/seg4k/seg4k_lr/palette; 4K 60.53 s -> 48.33 s
(1.252x, from 1.221x at the previous step), 1080p 10.74 s.
perf(av1): pool the post-filter plane buffers instead of allocating per frameAhmet Kaan Gümüş · 583ed90
perf(av1): pool the post-filter plane buffers instead of allocating per frame

Each frame allocated a pre-CDEF snapshot of all three planes, a
post-deblock snapshot of all three when loop restoration is active, and
one fresh `cdef.to_vec()` destination per restored plane: ~25 MB of
multi-megabyte `Vec`s per frame at 4K, every one of them served by a
fresh `mmap` whose pages then fault in on first touch, and returned to
the allocator at the end of the frame. `PLANE_SCRATCH` hands the same
buffers back out; `apply_loop_restoration_plane` now fills a caller-owned
`out` buffer (refilled from `cdef` on entry, same "never filter in place"
contract) which the caller swaps into the plane and returns to the pool.

Byte-exact on seg1080/seg4k/seg4k_lr/palette; 4K 60.48 s -> 49.55 s
(1.221x, from 1.156x at the previous step), LR-heavy 4K cut 59.95 s ->
54.16 s, 1080p 11.14 s. Peak RSS 417 MB -> 466 MB, the retained pool.
perf(av1): CDEF filters a gathered window with a resolved damping shiftAhmet Kaan Gümüş · 126001f
perf(av1): CDEF filters a gathered window with a resolved damping shift

Every tap read went through a closure that re-derived the frame-bounds
test (four compares plus the stride multiply) for each of a pixel's ~17
reads, and `constrain` recomputed its damping shift -- a `leading_zeros`
and a branch -- twice per tap. `cdef_gather` now lifts a unit's whole
footprint (its samples plus the two-pixel `CDEF_DIRECTIONS` ring) into a
reused scratch window once, contiguously for the interior case, and both
the direction search and `cdef_filter_block` index that; the shift is
resolved once per block by `cdef_constrain_shift`. A unit whose four
strengths are all zero now skips the gather and the direction search
outright -- `dir`/`var` are only ever consumed through a strength.

Byte-exact on seg1080/seg4k/seg4k_lr/palette; 4K 59.40 s -> 51.37 s
against the same-session base (interleaved medians of 3, 1.156x vs the
previous step's 1.140x), 1080p 10.72 s.
perf(av1): snapshot the remaining per-pixel EC_* env readsAhmet Kaan Gümüş · 2baca5a
perf(av1): snapshot the remaining per-pixel EC_* env reads

`restoration.rs`'s three `EC_LR_CALL_DUMP` guards sit inside the sgrproj
per-pixel loops (`compute_ab`, the combine tap) and `warp.rs`'s
`EC_MC_TRACE` on the per-MC-call warp entry; each was a live `getenv` +
`strlen` + `CStr` validation, 17.75% of `decode_probe`'s self time at 4K.
Same predicates, served by `envflags::env_flag!` (one `LazyLock<bool>`
per call site). `motion_field.rs`'s two `EC_TRACE_TPL` reads move with
them. `tile.rs`'s two sites stay: :34 already caches into an atomic and
:3002 is test-only.

Byte-exact on seg1080/seg4k/seg4k_lr/palette; 4K 55.31 s -> 48.53 s
(interleaved medians of 3), 1080p 10.54 s -> 9.83 s.
perf(av1): AVX2 luma film-grain rowAhmet Kaan Gümüş · a620a4d
perf(av1): AVX2 luma film-grain row

`add_noise_to_block` was 7% of a 1080p decode's self time, and its luma arm
is the larger half: one scaling-LUT read, one multiply, a `Round2` and a
clip per sample. AVX2 does eight at a time -- the LUT read is a
`vpgatherdd`, the rest is the same i32 arithmetic -- and every other CPU
runs the scalar loop, which stays the reference. The gather index is
clamped to the LUT's last entry so the load cannot leave the table; the
scalar form indexes unclamped (it would panic), and the LUT spans the whole
sample range the grain bit depth allows, so the two agree wherever the
scalar one does not panic.

Pinned against the scalar row over 8/10/12-bit sample and LUT ranges, every
`grain_scaling_minus_8` shift, restricted and full clip ranges, and row
lengths covering the 8-lane body plus every tail. Interleaved medians,
1080p: 10.51 s -> 10.40 s (11.01 s at the lane's base). Byte-exact on all
three probe inputs.
perf(av1): explicit SIMD for both motion-compensation passesAhmet Kaan Gümüş · 66498f4
perf(av1): explicit SIMD for both motion-compensation passes

The two separable-filter inner loops were 18.7% of a 1080p decode's self
time after lane-perf4 (`vpass_row` 10.4%, `horizontal_pass_unscaled`
8.3%). Both are now hand-vectorised with `std::arch::x86_64` intrinsics
behind a level detected once per process (`OnceLock`): AVX2 where the CPU
has it, SSE4.1 otherwise, and the existing scalar loops everywhere else --
they stay the reference implementation, not a dead fallback.

The horizontal pass's `_mm*_madd_epi16` sums two taps of one output per
lane, so even and odd output columns accumulate separately and are
interleaved back into order (`unpack` + `permute2x128`); 16 outputs per
AVX2 iteration, 8 per SSE2 one, a 4-column tail scalar. The vertical pass
stays i32 (`mullo_epi32` + `add_epi32`), as 12-bit needs. Rounding is
unchanged in both: the same `Round2` add-then-arithmetic-shift.

This is why the crate is now `deny(unsafe_code)` rather than `forbid`:
intrinsics are unsafe by signature. The exception is confined to `mc`'s
`simd` module and its two dispatch sites, each with its own
`#[allow(unsafe_code)]` and documented in the crate header, and every
kernel is pinned lane-for-lane against the scalar function it replaces
over all widths, all 16 phases, both tables of all four filter kinds and
the 8/10/12-bit ranges.

Interleaved medians, 1080p: 11.07 s -> 10.51 s (horizontal pass alone was
11.37 -> 11.24; the vertical pass is where the win is). 4K 57.59 -> 57.12.
Byte-exact on all three probe inputs.
perf(av1): inter reconstruction adds a row at a timeAhmet Kaan Gümüş · 180e079
perf(av1): inter reconstruction adds a row at a time

`PlaneBuf::reconstruct_mc_rect` re-derived `row * side + col` twice and
`(y + row) * self.width + x + col` once per sample, with a bounds check
on each of the three buffers. `side` is the prediction/residual stride
and `self.width` the plane's, so the three row bases are now taken once
per row and the row slices zipped; the arithmetic on each sample
(`clamp(0, sample_max())`) is untouched, as is the bottom/right overhang
truncation above it.

Byte-exact: EC_PROBE_OUT16 sha256 unchanged on a 1080p and a 4K segment
and on `palette_screen_witness.obu`. Interleaved medians against the
parent build alone (3 pairs, 1080p): 11.17 s -> 11.06 s.
perf(av1): film grain chroma noise walks contiguous rowsAhmet Kaan Gümüş · 8567ed5
perf(av1): film grain chroma noise walks contiguous rows

`add_noise_to_block`'s chroma half recomputed `(ly * y_stride + lx)`,
`(cy0 + i) * c_stride + (cx0 + j)` and the grain index per sample, and
indexed four planes with a bounds check each time. Every one of those
operands is contiguous along a row, so the loop now slices one row of
luma, U, V and both grain planes per `i` and zips them: the 4:2:0 average
(spec 7.18.3.5) is exactly `chunks_exact(2)` over the block's own luma
row, `(l[0] + l[1] + 1) >> 1` as before. The whole loop is skipped when
neither chroma plane takes noise.

Byte-exact: EC_PROBE_OUT16 sha256 unchanged on a 1080p and a 4K segment
and on `palette_screen_witness.obu`. Interleaved medians vs the tip
before this lane (3 pairs 1080p, one pair 4K): 11.96 s -> 11.39 s at
1080p, 60.71 s -> 58.87 s at 4K.
perf(av1): intra DC edge extension without allocation; pre-CDEF planes cloned only when loop restoration runsAhmet Kaan Gümüş · bea828c
perf(av1): intra DC edge extension without allocation; pre-CDEF planes cloned only when loop restoration runs

Two allocation sites the 1080p profile put at ~1.3% of self time between
them, neither of which any pixel depends on:

* `intra::dc` built one `Vec<u16>` per existing edge per intra block only
  to sum it. The replication libaom's `build_intra_predictors` performs is
  never indexed here, so the extended edge becomes a sum:
  `sum(samples[..n]) + last * (want - n)`, the same integers in the same
  order of magnitude, and the square/rect divisors come from `bw`/`bh`
  directly rather than from the (equal) vector lengths.
* Both frame paths cloned all three planes before CDEF as the loop
  restoration source, and `apply_loop_restoration_plane` then copied each
  plane again to return it unchanged when its restoration type is `None`.
  The clone is now taken only when some plane's type is not `None` with a
  non-zero unit size, i.e. exactly when a restored sample can differ.

Byte-exact: EC_PROBE_OUT16 sha256 unchanged on a 1080p and a 4K segment
and on `palette_screen_witness.obu`. Interleaved medians (3 pairs 1080p,
one pair 4K): 11.82 s -> 11.65 s at 1080p, 64.91 s -> 60.86 s at 4K.
fix(av1): superres upscales between CDEF and loop restoration, not after LRAhmet Kaan Gümüş · 08a2542
fix(av1): superres upscales between CDEF and loop restoration, not after LR

Spec 7.16 (libaom `superres_post_decode`, called in `decodeframe.c` between
`av1_cdef_frame` and `av1_loop_restoration_filter_frame`): the horizontal
upscale runs after CDEF and BEFORE loop restoration. This decoder ran the
whole filter chain on the downscaled frame and upscaled last, in `stream.rs`,
so under superres loop restoration filtered downscaled pixels through a unit
grid sized from the downscaled width.

Three widths were wrong, all in the same class (`wrong-stage-width`: each
plane width in the filter chain is either the downscaled one -- deblock, CDEF
and the mi grid -- or the upscaled one -- everything loop restoration does):

* `RestorationGrid::new` sized its unit counts from `frame_width`; libaom
  sizes them with `av1_get_upsampled_plane_size` (upscaled width).
* `read_lr`'s unit corners divided downscaled mi columns by the unit size;
  `av1_loop_restoration_corners_in_sb` scales by `superres_denom /
  SCALE_NUMERATOR` (`mi_to_num_x`/`denom_x`) when the frame is scaled.
* The pixel filters ran on downscaled planes. Both the post-CDEF frame and
  the post-deblock frame LR substitutes at stripe boundaries are now upscaled
  first (libaom's `save_deblock_boundary_lines` runs
  `av1_upscale_normative_rows` over its saved rows when the frame is scaled).

`decode::set_superres` carries the state per frame, like `set_bit_depth`, and
the reconstruction buffer's own real columns past `frame_width` stay the
upscale's right margin -- the `take_last_frame_wide_margin` hand-off to
`stream.rs` is gone with the late upscale it fed.

Gate: `fixtures/superres_kf_cdef_lr_64x64.obu`, a real aomenc key frame with
CDEF and loop restoration under `--superres-denominator=12`, was 1873 wrong
samples (max 7) and is now byte-exact against ffmpeg.

Residual, pinned ignored: `fixtures/superres_alltools_sb128_320x180.obu` (10
frames, all tools, sb128, cpu-used=4) went from 37315 wrong samples/max 171
to 1620/max 11 -- what is left is CHROMA ONLY (luma exact in all 10 frames)
and survives `--enable-cdef=0 --enable-restoration=0`, so it is a
scaled-reference chroma prediction defect, not filtering.
feat(av1): all three scaled-reference (superres) refusals lifted -- 8x8 leaf, sub-8x8, warpAhmet Kaan Gümüş · 421ae92
feat(av1): all three scaled-reference (superres) refusals lifted -- 8x8 leaf, sub-8x8, warp

The 8x8-leaf guard's own comment blamed a below-8x8 desync ("a 4th symbol
out of a 3-symbol alphabet"). That premise was stale: deleting the guard
decodes the pinned --superres-denominator=12 stream straight through to the
NEXT refusal. One wrong alphabet was behind all three.

Root cause (class wrong-alphabet-same-value / branch-dropped-as-unreachable):
decode_inter_block8 read the 3-symbol motion_mode row under a SCALED
reference, where libaom motion_mode_allowed makes WARPED_CAUSAL eligible
only if (num_proj_ref >= 1 && (allow_warped_motion && !av1_is_scaled(sf))) --
so the alphabet shrinks to the 2-symbol obmc one (with OBMC off, no symbol
at all). The 16x16+ path already had `&& !ref_is_scaled`; the leaf's own
comment asked whoever lifted the refusal to add it, and nobody could reach
the code to notice. First-bad without it: 96x96 denom-12 warped stream,
decode-order frame 3, luma (15,54), 7652 samples wrong, max 155.

Lifted, each byte-exact vs ffmpeg with its own hit counter:
* "an 8x8 partition leaf under a scaled reference"
* "a sub-8x8 inter block under a scaled reference" (both sub8 readers)
* "warp prediction with a scaled reference" -- its translational fallback
  was already implemented and the refusal sat in FRONT of it (class
  refusal-short-circuits-its-own-code); the r1 mismatch that kept it alive
  was the strip chroma piece below, not the fallback.

Same-shape sweep of "every caller that computes a scaled start position":
* mc::predict_maybe_scaled -- the one dispatch the sub-8x8 luma/chroma
  callers now share instead of hardcoding the unscaled walk.
* the 16x4/4x16 strip's sub-8x8 chroma piece was SKIPPED entirely under a
  scaled reference (silent wrong pixels, no refusal); it now rebuilds from
  the PREVIOUS strip's own reference and that reference's own scale factor.
* allow_warp's scale bail-out was missing at the 8x8-leaf single-ref warp
  and at both compound warp sites (PER SLOT: one tap can be scaled while
  its sibling still warps).

Gate: real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact --
two 96x96 denom-12 streams, every unrelated tool off, pixel-exact vs ffmpeg;
arm A hard-asserts scaled leaf8 + sub8 hits, arm B asserts a WARPED_CAUSAL
eligibility was suppressed by scale. The r27 census now asserts none of the
three strings can come back. Inventory rows removed.
test(av1): four more refusals proven -- empty ref slot, segmentation overrides, OBMC filter band, superres 8x8 leafAhmet Kaan Gümüş · baa89bd
test(av1): four more refusals proven -- empty ref slot, segmentation overrides, OBMC filter band, superres 8x8 leaf

Round 27 of the refusal-proving lane. 25 -> 29 proven of 40.

* "a reference frame selected with no picture at this frame's own
  ref_frame_idx slot for it": negative gate on `ref_planes` over all six
  non-LAST references. No stream-level witness exists with this crate's
  writers -- a shown key frame refreshes all eight slots and nothing
  clears one, and a stream opening on an inter frame is stopped one
  guard earlier ("an inter frame with no key frame before it"). The
  reachable premise is a HIDDEN key frame with a partial
  refresh_frame_flags, which write_frame_header cannot write; that is
  the open half, recorded in the inventory.
* "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV":
  negative gate (written key frame, three features x three segment ids,
  refused by name with 0 pictures) plus a census of what aomenc emits.
  Measured: --aq-mode=1/2 and --deltaq-mode=1 reproduce the baseline
  stream byte for byte at this recipe (the flags change nothing);
  --aq-mode=3 does code segment_id symbols (133 at cq40, 444 at cq10)
  and never enables any of the three. No capability gap here.
* "an OBMC neighbour whose switchable interp filter was never recorded":
  structural audit -- record_inter_rect_mi is the band's single writer
  and no call site stamps the [3, 3] sentinel on an INTER cell (each
  site's arguments tokenised, never substring-matched) -- plus a witness
  gate on two real --enable-obmc --enable-dual-filter streams: 237 band
  reads over ~115 OBMC blocks each, refusal 0x. --cpu-used=0 is
  load-bearing: at speed 4 aomenc settles on a frame-level fixed filter
  and the band is never read (0 reads, measured).
* superres trio census, six real streams: the four fixed-denominator
  --superres-mode=1 encodes (denoms 10/12/16, warp + OBMC on) ALL stop
  at "an 8x8 partition leaf under a scaled reference", and the two
  --superres-mode=3 auto encodes pick denominator 8 and carry no scaling
  at all (0 scaled MC blocks). The warp and sub-8x8 scaled refusals
  never fire: the 8x8-leaf guard sits in front of them, so they stay
  unproven until that gap is lifted. All three are real capability gaps.
perf(av1): refill the arithmetic decoder a field at a time, not a bit at a timeAhmet Kaan Gümüş · bea686b
perf(av1): refill the arithmetic decoder a field at a time, not a bit at a time

`SymbolDecoder::symbol_fixed` was 6.8% self time after the transform work,
and most of what it does per symbol beyond the alphabet walk is `f(n)` --
the renormalisation refill, which looped once per bit, fetching, masking and
shifting a byte each time. Five bytes cover any 32-bit field at any bit
offset, so the whole field is now one assemble-and-shift; a byte past the end
of the payload still reads as zero, exactly as the per-bit `unwrap_or(0)`
did. The alphabet walk also hoists `range >> 8`, which cannot move until the
symbol is chosen.

`bulk_bit_reads_match_the_per_bit_form` checks the new `f` against the loop
it replaced at every start offset over a 40-byte payload, every width from 0
to 32, and 16 bits past the end.

Byte-exact: `EC_PROBE_OUT16` dumps hash-identical to the lane's baseline
binary on 1080p 10-bit, 2160p HDR and the 8-bit palette fixture. Interleaved
medians against the previous commit: 1080p 12.35 s -> 12.07 s, 4K 64.44 s ->
63.94 s.
test(av1): four more refusals proven -- mi grid, ref height, primary_ref CDFs, intra modeAhmet Kaan Gümüş · 367c38e
test(av1): four more refusals proven -- mi grid, ref height, primary_ref CDFs, intra mode

Two enumerations and two negative gates, taking the inventory's numerator
from 21 to 25 of 40:

* "a frame with no mode-info grid": `compute_image_size` (spec 5.9.9) is
  zero only for a zero frame width/height, and no path that sets one can
  produce that -- `frame_size()` is `+1`-coded, `superres_params()`
  divides by 9..=16 with rounding (enumerated over the whole 16-bit
  upscaled domain, minimum 1), and `show_existing_frame` /
  `frame_size_with_refs` copy a slot. Swept per axis through the REAL
  header reader over every size this crate's writers can express.
* "a reference picture whose height does not match this frame's own true
  size": negative gate, a written 64x64 key frame followed by a 64x32
  inter frame (`frame_size_override_flag` with error resilience on, the
  one combination the writer expresses) -- refused by name, one picture
  out.
* "a frame naming primary_ref_frame at a reference slot with no saved CDF
  state": the picture and CDF slots are written by exactly two loops over
  the same refresh mask (enumerated from the source, so no slot holds a
  picture without CDFs), and the reachable case is a slot nothing has
  refreshed -- a stream opening on a non-error-resilient inter frame,
  gated at all eight slots. This refusal, not the missing-key-frame one,
  is what such a stream reaches: the CDF load happens in the header path.
* "an intra mode this decoder does not code (round 2)": all three guards
  refuse `mode >= 13` on a symbol read from the 13-symbol `y_mode` CDF;
  the test finds each site by the refusal in its own body, resolves the
  CDF the symbol came from, and fails if a wider alphabet (`uv_mode_cfl`
  is 14) ever feeds one.
perf(av1): tabulate the film-grain scaling curve once per frameAhmet Kaan Gümüş · 6081769
perf(av1): tabulate the film-grain scaling curve once per frame

`add_noise_to_block` (9.0% self time) evaluated `scale_lut` per sample -- a
shift, a branch on the bit depth, two table loads and an interpolation --
once per luma sample and once per chroma sample per plane. The scaling LUT is
fixed for the frame and `scale_lut` is a pure function of the sample value, so
its whole index domain (1024 entries at 10 bit, 256 at 8) is now tabulated
once per frame by `expand_scaling_lut`, which calls `scale_lut` itself: the
spec function stays the source of truth and the per-sample work becomes one
load.

The luma loop also walks the picture row and the grain row as slices rather
than recomputing `row * stride + col` per sample.

Byte-exact: `EC_PROBE_OUT16` dumps cmp IDENTICAL against the lane's baseline
binary on 1080p 10-bit, 2160p HDR and the 8-bit palette fixture. Interleaved
medians against the previous commit: 1080p 12.76 s -> 12.40 s, 4K 65.47 s ->
65.12 s (the 4K run is the noisiest on this box; five 1080p pairs are the
readable number).
test(av1): three more refusals proven -- empty tile group, empty show_existing slot, key-less inter frameAhmet Kaan Gümüş · 2eab33d
test(av1): three more refusals proven -- empty tile group, empty show_existing slot, key-less inter frame

* "a frame OBU with no tile group" -- ENUMERATION. `parse_tile_group` is the
  only producer of the `tiles` vector `decode_stream` tests, and its success
  path pushes one `Tile` per member of the inclusive range `tg_start..=tg_end`,
  which is never empty. A real frame OBU's tile payload truncated from empty
  upwards confirms it: every OBU that parses carries a tile, and none of them
  reaches the refusal. An empty payload parses into ONE zero-byte tile, not
  none, which is why the charter's "payload ends after the frame header"
  fixture cannot reach the string.
* "a show_existing_frame header naming an empty reference slot" -- NEGATIVE
  GATE over all 8 slots. The header OBU is hand-written (spec 5.9.2 codes only
  show_existing_frame + frame_to_show_map_idx here) because the frame header
  writer writes shown key/inter frames only. A shown key frame refreshes every
  slot, so a stream that opens on this header is the only reachable shape --
  the charter's "key frame with the bit clear" cannot be written.
* "an inter frame with no key frame before it" -- NEGATIVE GATE, built from
  this crate's own writers (a shown inter frame is writable) instead of a
  stripped aomenc stream: no external tool, byte-identical every run.

Both gates assert the refusal by name AND that the sink saw no picture.
test(av1): enumerate the motion_mode CDF row map over every shape that reads oneAhmet Kaan Gümüş · ff81ea8
test(av1): enumerate the motion_mode CDF row map over every shape that reads one

`is_motion_variation_allowed_bsize` (libaom blockd.h:1455, mirrored by
`motion_mode_eligible`'s `min(write_w, write_h) >= 8` clause) is the only gate
in front of the motion_mode/obmc row lookup, so the reachable domain of that
lookup is exactly the 17 `BLOCK_SIZES_ALL` footprints with a min side of 8 or
more. Each maps to a distinct row of the 17-row table, so the refusal "a
motion_mode symbol for a block shape with no CDF row here" names a shape no
conformant block can present -- no gap, nothing to witness.

The inline `match` is now `motion_mode_cdf_row`, which is what the enumeration
can call; the refusal stays at its own site.
perf(av1): dequantize into a reused buffer, with the loop invariants hoistedAhmet Kaan Gümüş · 32f9ae5
perf(av1): dequantize into a reused buffer, with the loop invariants hoisted

`dequant_wh` was a `map`/`collect` building a fresh `Vec<i32>` per transform
unit (7.8% self time, the third-hottest symbol in the decode profile), and
inside it every coefficient repeated the whole per-coefficient spec function:
two quantizer-table lookups with their own clamps, the area denominator's
match, and the bound shift -- all of which depend on the transform, not on
the coefficient.

`dequant_wh_into` hoists them and writes a caller-owned buffer, which the
one hot caller (`dequant_and_inverse_typed_wh`) keeps thread-local. A zero
level dequantizes to zero for every parameter set, so the all-but-EOB tail
of a grid now costs a compare rather than a 64-bit multiply and divide. The
arithmetic on a non-zero level is untouched; `dequant_wh` keeps its `Vec`
signature for the other callers.

`buffered_dequant_matches_the_per_coefficient_form` checks the buffered form
against `dequant_coeff_wh` over six transform shapes, three bit depths, three
quantizer/delta sets and both level signs.

Byte-exact: `EC_PROBE_OUT16` dumps cmp IDENTICAL against the lane's baseline
binary on 1080p 10-bit, 2160p HDR and the 8-bit palette fixture. Interleaved
medians against the previous commit: 1080p 13.46 s -> 12.15 s, 4K 67.11 s ->
63.38 s.
test(av1): enumerate read_golomb over the whole value domain spec 5.11.40 writesAhmet Kaan Gümüş · d55c549
test(av1): enumerate read_golomb over the whole value domain spec 5.11.40 writes

"a Golomb tail longer than this decoder reads" was a bound with nothing
measuring it. Spec 5.11.40 counts the unary prefix and breaks at
length == 20, and 5.11.39 masks the level it feeds with 0xFFFFF, so the
largest tail a conformant stream carries is (1 << 20) - 2 -- and this walks
both ends of every prefix length 1..=20 (plus the small values real streams
use) out through write_golomb and back through read_golomb, so the refusal
is proved to sit outside the value domain rather than inside it. The residue
is a bit pattern, not a value: the spec's break makes the 20th prefix bit a
don't-care, and a 20-zero prefix is still refused (asserted, so the refusal
is not dead code). The cap itself stays where it is -- lifting it is blocked
on the desync it currently masks. Mutation-checked (cap at 10 fails on tail
1023).
perf(av1): inverse transform without per-call allocation or runtime bit-reversalAhmet Kaan Gümüş · ee4e975
perf(av1): inverse transform without per-call allocation or runtime bit-reversal

`perf annotate` of `inverse_dct` (12.3% self time) opened every call with a
`malloc`/`memcpy` pair -- `permute`'s `Vec` -- and then spent its hottest
single instruction in the inlined `brev` bit-fold, recomputed per butterfly
index. `cos128` was a four-way branch per butterfly, and the 2D driver
(7.6% self) allocated two more `Vec`s per transform unit while looking up
`row_shift_wh` through a match once per output sample.

All four are now compile-time or loop-invariant: `brev` and the whole-circle
cosine are const tables, `permute` copies into a stack array, the row pass
writes a thread-local scratch it fully overwrites, and the shift is hoisted.
The row and column passes also skip an all-zero vector, which is exact rather
than approximate -- every butterfly and Hadamard of zeros is zero and
`Round2(0, n)` is zero at every `n` -- and is what makes rows 32..64 of a
64-point transform, and the tail of any EOB-limited block, free.
`a_zero_vector_transforms_to_zero` pins that property per 1D transform and
end to end.

Byte-exact: `EC_PROBE_OUT16` dumps cmp IDENTICAL against the pre-change
binary on a 299-frame 1080p 10-bit segment, a 4 s 2160p HDR segment and the
8-bit palette fixture. Interleaved medians: 1080p 16.72 s -> 13.74 s
(17.9 -> 21.8 fps), 4K 78.74 s -> 70.05 s.
test(av1): enumerate every tx_type CDF width against its own inverse setAhmet Kaan Gümüş · d8a578a
test(av1): enumerate every tx_type CDF width against its own inverse set

"a tx_type symbol outside its CDF's own set" guards two readers that each
picked the set by the CDF row's width in their own copy of the same match.
Both now call one `tx_type_from_symbol(cdf_len, t)`, and the new enumeration
walks every width declared for a tx_type table in cdf_state.rs (the scan
fails if a new table brings a width the mapping does not name) times every
symbol that width can code -- `0..len - 1`, all a symbol read can return --
asserting each maps to a transform type and that the members of one set are
distinct, so no width has silently lost a member of the spec's
Tx_Type_*_Inv_Set*. Mutation-checked (pointing width 8 at the five-type
order fails on symbol 5).
test(av1): enumerate the inter 16x16 partition chain's branch conditionsAhmet Kaan Gümüş · 5f52cbd
test(av1): enumerate the inter 16x16 partition chain's branch conditions

"an inter 16x16-level partition value outside NONE/HORZ/VERT/SPLIT/AB/1:4"
sits in the second-to-last branch of an if/else ladder rather than a match
fallback, so the arm enumerator could not see it. This adds the chain form:
find the refusing branch, walk up its chain collecting each branch's own
condition (multi-line conditions joined to the brace that opens the body),
tokenise the PARTITION_* constants and inclusive ranges out of them, and
require the union to cover the ten-value partition_w16 alphabet -- with the
final `else` required (it takes PARTITION_SPLIT, the value the refusing
branch excludes) and any `&&` in a condition rejected, since a conditionally
handled value would overstate the coverage. NAMES/covered are now shared
helpers between both enumerators. Mutation-checked (dropping PARTITION_VERT
from its branch fails the test by name).
test(av1): enumerate the superblock-root partition alphabet against its armsAhmet Kaan Gümüş · 00c1b3f
test(av1): enumerate the superblock-root partition alphabet against its arms

The key-frame superblock root's `match part` carries the refusal "a
superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4"
in its fallback arm. `part` is either a `partition_w64` symbol (ten values,
`symbol` cannot return more) or, at a frame edge, one of the three gathered
outcomes HORZ/VERT/SPLIT -- all inside that same alphabet. The existing
arm enumerator already walks matches keyed by their own fallback string, so
this is one entry: the match has an arm for all ten values, and the refusal
is dead. Mutation-checked (dropping PARTITION_VERT_4 from its arm fails the
test by name).
docs(av1): census the 128-root screen-content strip refusal (site B, r23)Ahmet Kaan Gümüş · f79247a
docs(av1): census the 128-root screen-content strip refusal (site B, r23)

Its premise is already false by the spec -- 5.11.46 codes palette only for
`Block_Width <= 64 && Block_Height <= 64`, so a 128x64/64x128 half consumes no
palette syntax and `allow_screen_content_tools` changes nothing about it -- but
6 aomenc encodes at `--sb-size=128 --tune-content=screen` (704x320, the
edge-forced size r18 proved for the non-screen twin; screen cell content at cq
10/20/40 and r18's own panning-texture-plus-fresh-ramp shape) code ZERO
128-root halves of any kind, so there is nothing to gate a lift with and the
refusal stays with its census written down.
feat(av1): reconstruct palette blocks on 8x8 leaves inside inter framesAhmet Kaan Gümüş · cdef95e
feat(av1): reconstruct palette blocks on 8x8 leaves inside inter frames

`decode_inter_block8`'s intra arm read `palette_y_mode`/`palette_uv_mode` off
hardcoded CDF row 0 and refused the moment either said "yes". It now reads the
whole `read_palette_mode_info` syntax with this leaf's REAL
`av1_get_palette_mode_ctx` and colour cache, decodes both colour-index maps
after the mode info (`av1_visit_palette`) and predicts from them through the
existing PALETTE_PRED slot, per transform unit when the leaf's `tx_depth`
splits -- the same shape the >=16 intra-in-inter block already ran.

A palette block on an 8x8 leaf also made a pre-existing hole in the palette
neighbour bands reachable: a sub-8x8 group published nothing, so the row's
`left_palette_size` kept an earlier 8x8 palette block's size and
`av1_get_palette_mode_ctx` read 1 where libaom gathers 0 (decode-order frame
1, mi(30,30): palette size decoded as 8 instead of 2). All three sub-8x8
tails now publish the all-zero state, as does `decode_inter_block8`'s own
compound early return (class early-return-skips-tail). New rung `EC_PALPUB=1`
prints every publication into those bands, which is what named the gap.

Gate `a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact`:
15 frames pixel-exact on every plane vs ffmpeg, 25 palette-Y and 12
palette-UV 8x8 leaves inside inter frames -- exactly the 25 `bsize=BLOCK_8X8
palette_size>0` blocks aomdec's `EC_PALSYN` counts past the key frame.

The `(UV)` refusal string is gone from the decoder entirely (this leaf was its
only site); the `(Y)` one survives only as the defensive `palette.is_none()`
guard no caller can reach.
feat(av1): reconstruct palette blocks inside inter frames, and fix the palette colour-index CDF counter resetAhmet Kaan Gümüş · 6a16223
feat(av1): reconstruct palette blocks inside inter frames, and fix the palette colour-index CDF counter reset

An intra block in an inter frame refused by name the moment it actually used
a palette ("reconstruction is out of scope"), at both the square
(`decode_inter_block`) and the rect (`decode_intra_rect_in_inter`) path. Both
now read the real syntax -- mode/size/colours off this block's own
`av1_get_palette_mode_ctx` context and `av1_get_palette_cache` colour cache,
the two colour-index maps deferred past `filter_intra` exactly as
`av1_visit_palette` runs them -- and predict from the map (per transform unit
where the luma transform splits), the same machinery the key-frame paths use.
Every block of an inter frame now also stamps its palette state (all-zero for
an inter block) into the mi-granular neighbour bands, which is what libaom's
mode-info grid holds and what the next block's cache and mode context read.

The witness then desynced at the FIRST inter-frame palette block's colour
index map, third symbol: the two palette colour-index tables are this
decoder's only variable-alphabet CDFs (the reader takes `[..=n]` of a
`[u16; 9]` row, so `update_cdf`'s symbol counter lives at index `n`), and
`Cdfs::reset_counts` zeroed the array's last slot instead. Every colour-index
row therefore crossed a frame boundary with a saturated count and adapted at
rate 6 where libaom, counting from zero, adapts at 4 (class
cdf-counter-not-reset). Swept: those two are the only `[..=n]` readers here.

Also lifted, as a stale premise: the 16x4/4x16 arm of "a HORZ/VERT intra strip
in a screen-content frame (palette syntax is consumed for square blocks
only)" -- that arm routes through `decode_rect4_16_strip`, which takes
`allow_screen_content_tools` and reads the whole palette syntax already. The
128-root arm keeps the refusal (its body reads none, and no --sb-size=128
screen witness exists).

Gates (aomenc --tune-content=screen --enable-palette=1 --enable-intrabc=0
--sb-size=64, 15 frames, key + inter, 8-bit and 10-bit twins):
a_real_aomenc_screen_stream_with_palette_blocks_decodes_pixel_exact and
a_screen_stream_with_16x4_intra_strips_in_inter_frames_decodes_pixel_exact --
all 15 frames byte-exact vs ffmpeg on every plane, with inter-frame palette
counters y/uv > 0 so neither gate is vacuous.
perf(av1): whole-pel axes skip the pass they do not needAhmet Kaan Gümüş · c8bf4a0
perf(av1): whole-pel axes skip the pass they do not need

A motion vector with a whole-pel component still ran the full two-pass
filter. Fraction 0 is the identity tap, so each axis has an exact shortcut:
Round2(128 * s, InterRound0) == 16 * s horizontally, and vertically
Round2(128 * a, InterRound1) == Round2(a, InterRound1 - 7) (== a for the
compound round), which also means the 3 rows above and 4 below the block
never have to be filtered -- a 4-tall chroma block drops from 11 horizontal
rows to 4.

Byte-exact: 1080p 10-bit and 2160p HDR EC_PROBE_OUT16 dumps both cmp
identical to the pre-lane binary. Interleaved medians on the 1080p segment,
6 pairs against the previous commit: 19.08 s -> 17.42 s (faster in 5 of 6).
perf(av1): horizontal MC taps multiply at 16 bitsAhmet Kaan Gümüş · dcac6b3
perf(av1): horizontal MC taps multiply at 16 bits

The interior horizontal row had auto-vectorised, but into pmuludq/pshufd
chains: an i32 x i32 lane multiply is three instructions on SSE2. A tap is
|x| <= 128 and a sample is bounded by the bit depth (<= 4095 at 12-bit), so
narrowing both factors to i16 before the widening multiply gives exactly the
same products and one instruction per pair.

Byte-exact: 1080p 10-bit and 2160p HDR EC_PROBE_OUT16 dumps both cmp
identical to the pre-lane binary. Interleaved medians on the 1080p segment:
22.25 s base -> 16.64 s.