forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

counters.rs4459 lines, 203.9 KiBHistoryRawDownload
1//! Hit and census counters of the decode path: thread-local tallies bumped by the
2//! `hit!` instrumentation and read back by the gate tests. Moved out of `decode/mod.rs`
3//! by name (av1split D3); the items are unchanged except for `pub(super)` visibility.
4
5use super::*;
6
7// How many real 128-level partition symbols this decoder has read, and how
8// many superblocks resolved to `PARTITION_SPLIT` (coded or forced) -- the
9// gate's proof a `--sb-size=128` stream exercised the 128 partition root.
10thread_local! {
11 pub(super) static PART128_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
12}
13
14/// Current value of [`PART128_SPLIT_HITS`].
15#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
16pub(crate) fn part128_split_hits() -> usize {
17 PART128_SPLIT_HITS.with(|c| c.get())
18}
19
20// How many `use_filter_intra` symbols this decoder has read as `1`, across
21// every call on the current thread -- the cheap counter [`filter_intra_hits`] gate
22// tests read (before/after, not the absolute value) to prove a stream
23// actually exercised the filter-intra predictor rather than silently
24// skipping it.
25thread_local! {
26 pub(super) static FILTER_INTRA_HITS: std::cell::Cell<usize> =
27 const { std::cell::Cell::new(0) };
28}
29
30/// Current value of [`FILTER_INTRA_HITS`].
31#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
32pub(crate) fn filter_intra_hits() -> usize {
33 FILTER_INTRA_HITS.with(|c| c.get())
34}
35
36// lane-fiinter r1: how many of those `use_filter_intra == 1` symbols belonged
37// to an INTRA block inside an INTER frame (`read_intra_block_mode_info`'s own
38// `read_filter_intra_mode_info` call), which no gate exercised before this
39// round -- every inter gate recipe passed `--enable-filter-intra=0`.
40thread_local! {
41 pub(super) static INTRA_IN_INTER_FILTER_INTRA_HITS: std::cell::Cell<usize> =
42 const { std::cell::Cell::new(0) };
43}
44
45/// Current value of [`INTRA_IN_INTER_FILTER_INTRA_HITS`].
46#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
47pub(crate) fn intra_in_inter_filter_intra_hits() -> usize {
48 INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.get())
49}
50
51// lane-angleinter r1: how many INTRA blocks inside an INTER frame carried a
52// nonzero `angle_delta_y` / `angle_delta_uv` (`read_intra_angle_info`). Both
53// arms refused a nonzero luma delta before this round, and no inter gate
54// enabled `--enable-angle-delta` (aomenc's own default is 1).
55thread_local! {
56 pub(super) static INTRA_IN_INTER_ANGLE_DELTA_Y_HITS: std::cell::Cell<usize> =
57 const { std::cell::Cell::new(0) };
58 pub(super) static INTRA_IN_INTER_ANGLE_DELTA_UV_HITS: std::cell::Cell<usize> =
59 const { std::cell::Cell::new(0) };
60}
61
62/// Current value of [`INTRA_IN_INTER_ANGLE_DELTA_Y_HITS`].
63#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
64pub(crate) fn intra_in_inter_angle_delta_y_hits() -> usize {
65 INTRA_IN_INTER_ANGLE_DELTA_Y_HITS.with(|c| c.get())
66}
67
68/// Current value of [`INTRA_IN_INTER_ANGLE_DELTA_UV_HITS`].
69#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
70pub(crate) fn intra_in_inter_angle_delta_uv_hits() -> usize {
71 INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|c| c.get())
72}
73
74// lane-uv8 r1: the three non-DC chroma mode classes an INTRA 8x8 leaf inside
75// an INTER frame ([`decode_inter_block8`]'s intra arm) can carry -- the arm
76// read `uv_mode` and then refused everything but `DC_PRED`. Counted here and
77// nowhere else so the gate's assert cannot be satisfied by a >=16x16 block.
78thread_local! {
79 pub(super) static INTRA_IN_INTER8_UV_DIR_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
80 pub(super) static INTRA_IN_INTER8_UV_SMOOTH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
81 pub(super) static INTRA_IN_INTER8_UV_CFL_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
82}
83
84thread_local! {
85 pub(super) static INTRA_IN_INTER8_ANGLE_DELTA_Y_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
86}
87
88/// Nonzero luma angle deltas coded by an intra 8x8 leaf inside an inter frame
89/// (lane-leaf8tx r1) -- counted only in [`decode_inter_block8`]'s intra arm.
90#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
91pub(crate) fn intra_in_inter8_angle_delta_y_hits() -> usize {
92 INTRA_IN_INTER8_ANGLE_DELTA_Y_HITS.with(|c| c.get())
93}
94
95/// `(directional, smooth/paeth, CfL)` chroma modes coded by an intra 8x8 leaf
96/// inside an inter frame -- see [`INTRA_IN_INTER8_UV_DIR_HITS`].
97#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
98pub(crate) fn intra_in_inter8_uv_hits() -> (usize, usize, usize) {
99 (
100 INTRA_IN_INTER8_UV_DIR_HITS.with(|c| c.get()),
101 INTRA_IN_INTER8_UV_SMOOTH_HITS.with(|c| c.get()),
102 INTRA_IN_INTER8_UV_CFL_HITS.with(|c| c.get()),
103 )
104}
105
106// Whether this superblock's single CDEF unit (this decoder has no 128x128
107// SB, so the SB IS the CDEF unit) has already had its `cdef_idx` literal
108// read -- reset to `false` at the top of each superblock in the two tile
109// loops, spec `read_cdef`'s `cdef_transmitted[index]`.
110// Number of superblock columns in the current tile's grid, so
111// [`maybe_read_cdef_idx`] can turn an `(mi_r, mi_c)` into a flat index into
112// [`CDEF_IDX_GRID`].
113// One resolved `cdef_idx` per superblock, read by [`apply_cdef`] to select
114// which of the header's `1 << cdef.bits` strength pairs applies to that
115// superblock's samples.
116// How many real (`cdef.bits > 0`) `cdef_idx` literals [`maybe_read_cdef_idx`]
117// has read, across every call on the current thread -- the gate's proof that a
118// `cdef_bits > 0` stream actually reached the new reader rather than every
119// superblock coincidentally being all-skip.
120thread_local! {
121 pub(super) static CDEF_IDX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
122}
123
124// How many times a warp was suppressed for one PLANE because that plane's own
125// block is narrower or shorter than 8 (`av1_init_warp_params`'s own bail-out,
126// reconinter.c) -- the gate's proof that a stream really carries the shape,
127// since the square `side`/`chroma_side` can be 8 or more while the plane's
128// true block is 4 wide (an 8x16 luma block's 4x8 chroma).
129thread_local! {
130 pub(super) static WARP_PLANE_SUPPRESS_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
131}
132
133/// Current value of [`WARP_PLANE_SUPPRESS_HITS`].
134#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
135pub(crate) fn warp_plane_suppress_hits() -> usize {
136 WARP_PLANE_SUPPRESS_HITS.with(|c| c.get())
137}
138
139/// Current value of [`CDEF_IDX_HITS`].
140#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
141pub(crate) fn cdef_idx_hits() -> usize {
142 CDEF_IDX_HITS.with(|c| c.get())
143}
144
145// lane-t900 r6: gate proof for the three r2-r4 root causes that shipped with no
146// counter -- the in-inter tx-depth context (`tx_size_context_txfm_rect`), the
147// non-chroma-reference block that must LEAVE its neighbours' chroma coefficient
148// contexts alone, and the intra-edge filter neighbour pair taken mi-exact
149// instead of from the coarse 16x16 cell.
150thread_local! {
151 pub(super) static INTRA_IN_INTER_TXCTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
152 pub(super) static NON_CHROMA_REF_CTX_SKIP_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
153 pub(super) static EDGE_FILTER_MI_FIX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
154}
155
156/// Current value of [`INTRA_IN_INTER_TXCTX_HITS`].
157#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
158pub(crate) fn intra_in_inter_txctx_hits() -> usize {
159 INTRA_IN_INTER_TXCTX_HITS.with(|c| c.get())
160}
161
162/// Current value of [`NON_CHROMA_REF_CTX_SKIP_HITS`].
163#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
164pub(crate) fn non_chroma_ref_ctx_skip_hits() -> usize {
165 NON_CHROMA_REF_CTX_SKIP_HITS.with(|c| c.get())
166}
167
168/// Current value of [`EDGE_FILTER_MI_FIX_HITS`].
169#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
170pub(crate) fn edge_filter_mi_fix_hits() -> usize {
171 EDGE_FILTER_MI_FIX_HITS.with(|c| c.get())
172}
173
174// lane-realworld r4: this frame's `delta.q_present` (spec 5.9.17) and its
175// actual step (`1 << delta.q_res`, already the real multiplier, not the raw
176// 2-bit field). `false`/`1` (the defaults) make [`maybe_read_delta_q`] a
177// true no-op, matching every existing gate stream's `delta_q_present == 0`
178// behaviour exactly, the same corner-cut [`CDEF_BITS`] takes above.
179// The running quantizer index (spec `CurrentQIndex`, libaom
180// `xd->current_base_qindex`) -- reset to the frame's own `base_q_idx` at the
181// top of every tile (spec `decode_tile`), carried across superblocks within
182// that tile, and mutated only by [`maybe_read_delta_q`]. Read back at the
183// dequantization call sites instead of the frame-constant `base_q_idx`.
184// This frame's own per-plane DC/AC quantizer-index deltas (lane-sbpart r11,
185// spec 5.9.12/7.12.2, [`crate::quant::QuantDeltas`]) -- frame-constant (not
186// per-superblock like [`CURRENT_Q_IDX`]), set once per frame decode and read
187// back at every dequantization call site keyed on which plane it is doing.
188// How many real `delta_q_present` symbol groups [`maybe_read_delta_q`] has
189// read, across every call on the current thread -- the gate's proof that a
190// `delta_q_present` stream actually reached the new reader.
191thread_local! {
192 pub(super) static DELTA_Q_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
193}
194
195/// Current value of [`DELTA_Q_HITS`].
196#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
197pub(crate) fn delta_q_hits() -> usize {
198 DELTA_Q_HITS.with(|c| c.get())
199}
200
201// lane-realworld r5: this frame's `delta.lf_present`/`lf_res`/`lf_multi`
202// (spec 5.9.18) -- same no-op-by-default corner-cut as `DELTA_Q_PRESENT`.
203// The running per-plane/direction loop-filter delta (spec `DeltaLF[i]`,
204// `i` in `0..FRAME_LF_COUNT`) -- reset to `[0; 4]` at the top of every tile,
205// mutated only by [`maybe_read_delta_lf`]. `!delta_lf_multi` mode only ever
206// updates index 0 and every reader treats that as the value for all 4
207// indices (spec `read_delta_lf_params`'s own single-cdf branch).
208// How many real `delta_lf_present` symbol groups [`maybe_read_delta_lf`] has
209// read -- the gate's proof the reader fired, mirroring [`DELTA_Q_HITS`].
210thread_local! {
211 pub(super) static DELTA_LF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
212}
213
214/// Current value of [`DELTA_LF_HITS`].
215#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
216pub(crate) fn delta_lf_hits() -> usize {
217 DELTA_LF_HITS.with(|c| c.get())
218}
219
220// ---------------------------------------------------------------------------
221// lane-seg: segmentation. Header (spec 5.9.14) is parsed by `ec-av1-syntax`;
222// this block is the per-block `segment_id` reader (spec 5.11.7-5.11.9) plus
223// the two consumers a real stream exercises: the per-segment quantizer index
224// (spec 7.12.2 `get_qindex`) and the per-segment loop-filter level
225// (spec 7.14.4). Shapes follow libaom `decodemv.c:read_segment_id`/
226// `read_intra_segment_id`/`read_inter_segment_id` and
227// `pred_common.h:av1_get_spatial_seg_pred` -- note libaom returns the SPATIAL
228// PREDICTION (not 0) from `read_segment_id` when the block is `skip`, which
229// is what the oracle every gate here compares against actually does.
230thread_local! {
231 /// `CurrentSegmentIds`: this frame's own map, `mi_rows * mi_cols` entries
232 /// with stride `mi_cols` (NOT the padded `Neighbours` grid stride).
233 /// `PrevSegmentIds`: the primary reference frame's saved map, empty when
234 /// this frame has no primary reference (spec `load_previous_segment_ids`).
235 /// `(mi_rows, mi_cols)` for both maps above.
236 /// `AboveSegPredContext` (per mi column) / `LeftSegPredContext` (per mi
237 /// row) -- spec 5.11.9's own `seg_id_predicted` neighbour state, which
238 /// libaom keeps on the neighbouring `mbmi->seg_id_predicted` instead.
239 /// The block currently being decoded -- read back by [`block_q_idx`].
240 /// The tile's own top-left mi position, for `AvailU`/`AvailL`.
241 /// How many real `segment_id` symbols were read, and the set of segment
242 /// ids any block ended up with -- the gate's proof the feature fired.
243 pub(super) static SEG_ID_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
244 /// How many `seg_id_predicted` symbols were read (temporal update).
245 pub(super) static SEG_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
246}
247
248/// How many `segment_id` symbols have been read (never reset per frame).
249#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
250pub(crate) fn segment_id_hits() -> usize {
251 SEG_ID_HITS.with(|c| c.get())
252}
253
254/// How many `seg_id_predicted` symbols have been read (temporal update).
255#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
256pub(crate) fn segment_pred_hits() -> usize {
257 SEG_PRED_HITS.with(|c| c.get())
258}
259
260/// Resets the segmentation hit counters (gate setup).
261#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
262pub(crate) fn reset_segment_hits() {
263 SEG_ID_HITS.with(|c| c.set(0));
264 SEG_IDS_SEEN.with(|c| c.set(0));
265 SEG_PRED_HITS.with(|c| c.set(0));
266 BLOCK_Q_SPAN.with(|c| c.set((i32::MAX, i32::MIN)));
267}
268
269// How many key-frame luma blocks resolved `smooth_neighbor` (spec
270// `get_intra_edge_filter_type`) to `true` -- lane-chroma r2's own before/after
271// counter, proving a stream actually put a directional block next to a
272// smooth-predicted neighbour rather than every block reading the (previously
273// hardcoded `false`) edge-filter strength bucket unchanged.
274thread_local! {
275 pub(super) static SMOOTH_LUMA_HITS: std::cell::Cell<usize> =
276 const { std::cell::Cell::new(0) };
277}
278
279/// Current value of [`SMOOTH_LUMA_HITS`].
280#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
281pub(crate) fn smooth_luma_hits() -> usize {
282 SMOOTH_LUMA_HITS.with(|c| c.get())
283}
284
285thread_local! {
286 /// lane-band46 r1: how many split-transform units answered their intra
287 /// reach DIFFERENTLY under libaom's per-unit rules ([`Reach::of_tu`], the
288 /// palette2 r12 fix) than the standalone-block lookup this decoder used to
289 /// apply to them (class reach-is-per-transform-unit). Every hit is a
290 /// transform unit whose above-right / below-left reference samples would
291 /// be wrong without that fix.
292 pub(super) static SPLIT_TU_REACH_FIX_HITS: std::cell::Cell<usize> =
293 const { std::cell::Cell::new(0) };
294}
295
296/// Current value of [`SPLIT_TU_REACH_FIX_HITS`].
297#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
298pub(crate) fn split_tu_reach_fix_hits() -> usize {
299 SPLIT_TU_REACH_FIX_HITS.with(|c| c.get())
300}
301
302// How many `uv_mode` reads resolved to `SMOOTH_PRED..=PAETH_PRED` (9..=12),
303// across every call on the current thread -- lane-chroma r3's own before/after
304// counter, proving a stream actually exercised chroma's smooth/paeth
305// predictor (the previously-refused round-2 gap) rather than every block
306// landing on DC/CFL/directional.
307thread_local! {
308 pub(super) static SMOOTH_UV_HITS: std::cell::Cell<usize> =
309 const { std::cell::Cell::new(0) };
310}
311
312/// Current value of [`SMOOTH_UV_HITS`].
313#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
314pub(crate) fn smooth_uv_hits() -> usize {
315 SMOOTH_UV_HITS.with(|c| c.get())
316}
317
318// How many tiles [`decode_key_frame_tile_with_cdfs`] has actually decoded a
319// full superblock walk over, across every call on the current thread --
320// lane-tiles r2's own gate-blind-to-feature guard: a gate over a
321// multi-tile stream must prove more than one tile actually fired, not just
322// that the stream carried tile_info.cols > 1.
323thread_local! {
324 pub(super) static TILE_HITS: std::cell::Cell<usize> =
325 const { std::cell::Cell::new(0) };
326}
327
328/// Current value of [`TILE_HITS`].
329#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
330pub(crate) fn tile_hits() -> usize {
331 TILE_HITS.with(|c| c.get())
332}
333
334// How many 4-pixel deblocking edge groups [`edge_params`] has actually
335// selected for filtering, across every call on the current thread -- the same
336// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
337// exercised `apply_deblock` rather than every edge landing on level 0.
338thread_local! {
339 pub(super) static DEBLOCK_HITS: std::cell::Cell<usize> =
340 const { std::cell::Cell::new(0) };
341}
342
343/// Current value of [`DEBLOCK_HITS`].
344#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
345pub(crate) fn deblock_hits() -> usize {
346 DEBLOCK_HITS.with(|c| c.get())
347}
348
349// lane-defon r1: how many COMPOUND_REFERENCE blocks read a
350// `UNIDIR_COMP_REFERENCE` pair (both references on the same temporal side,
351// spec 5.11.25 `comp_reference_type == 0`) -- the gate's proof that a
352// stream built with `--enable-onesided-comp=1` really exercised the
353// `uni_comp_ref` alphabet rather than only bidirectional pairs.
354thread_local! {
355 pub(super) static UNI_COMP_HITS: std::cell::Cell<usize> =
356 const { std::cell::Cell::new(0) };
357}
358
359/// Current value of [`UNI_COMP_HITS`].
360#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
361pub(crate) fn uni_comp_hits() -> usize {
362 UNI_COMP_HITS.with(|c| c.get())
363}
364
365// lane-defon r1: how many blocks blended through a `COMPOUND_DIFFWTD` mask
366// (`mc::diffwtd_mask`) -- the narrower half of `MASKED_COMPOUND_HITS`, the
367// gate's proof that `--enable-diff-wtd-comp=1` reached the difference-weighted
368// blend and not only the wedge arm.
369thread_local! {
370 pub(super) static DIFFWTD_HITS: std::cell::Cell<usize> =
371 const { std::cell::Cell::new(0) };
372}
373
374/// Current value of [`DIFFWTD_HITS`].
375#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
376pub(crate) fn diffwtd_hits() -> usize {
377 DIFFWTD_HITS.with(|c| c.get())
378}
379
380// lane-mcomp64 r1: how many blocks took the INFERRED `COMPOUND_DIFFWTD` arm --
381// a block size where `av1_is_wedge_used` is false (64x64 is the only such size
382// this decoder's square inter path reaches), so no `compound_type` symbol is
383// coded at all. Strictly narrower than `DIFFWTD_HITS`, which also counts the
384// coded-symbol DIFFWTD blocks at 8x8/16x16/32x32.
385thread_local! {
386 pub(super) static DIFFWTD_INFERRED_HITS: std::cell::Cell<usize> =
387 const { std::cell::Cell::new(0) };
388}
389
390/// Current value of [`DIFFWTD_INFERRED_HITS`].
391#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
392pub(crate) fn diffwtd_inferred_hits() -> usize {
393 DIFFWTD_INFERRED_HITS.with(|c| c.get())
394}
395
396// lane-defon r1: how many FORWARD KEYFRAMES were decoded -- a KEY frame coded
397// with `show_frame == 0`, output later by a `show_existing_frame` header
398// (aomenc `--enable-fwd-kf=1 --fwd-kf-dist=N`). Counted from
399// `stream::decode_stream`, which is where the frame header is consumed; the
400// gate's proof that the on-value really reached the bitstream rather than
401// being dropped by the rate control.
402thread_local! {
403 pub(super) static FWD_KF_HITS: std::cell::Cell<usize> =
404 const { std::cell::Cell::new(0) };
405}
406
407/// Current value of [`FWD_KF_HITS`].
408#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
409pub(crate) fn fwd_kf_hits() -> usize {
410 FWD_KF_HITS.with(|c| c.get())
411}
412
413// How many [`read_tx_size`] reads resolved a `tx_depth` strictly less than
414// the block's own side, across every call on the current thread -- the same
415// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
416// actually exercised a *split* transform under `TxMode::Select` rather than
417// every block coincidentally resolving `depth=0` (indistinguishable from
418// `TxMode::Largest` pixel-wise).
419thread_local! {
420 pub(super) static TX_DEPTH_HITS: std::cell::Cell<usize> =
421 const { std::cell::Cell::new(0) };
422}
423
424// How many plain SQUARE intra blocks (lane-sqchroma r1) resolved a luma
425// transform smaller than their own side (`tx_depth != 0`) while coding a
426// chroma prediction other than `DC_PRED` -- the pair the square path's chroma
427// only exercises with aomenc's tx-size search left ON (its default), which
428// every older recipe in this file pins off. Counted at the block, so a stream
429// where RD happened to give every split-transform block a DC chroma mode
430// reads as zero rather than silently passing for free.
431thread_local! {
432 pub(super) static SQ_CHROMA_TX_HITS: std::cell::Cell<usize> =
433 const { std::cell::Cell::new(0) };
434}
435
436/// Current value of [`SQ_CHROMA_TX_HITS`].
437#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
438pub(crate) fn sq_chroma_tx_hits() -> usize {
439 SQ_CHROMA_TX_HITS.with(|c| c.get())
440}
441
442/// Current value of [`TX_DEPTH_HITS`].
443#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
444pub(crate) fn tx_depth_hits() -> usize {
445 TX_DEPTH_HITS.with(|c| c.get())
446}
447
448// lane-txselect: how many `txfm_split` symbols an inter frame's var-tx tree
449// read, and how many of those actually took the split, on the current thread
450// -- the same before/after counter pattern as [`TX_DEPTH_HITS`], proving a
451// stream exercised spec 5.11.17's `read_var_tx_size` rather than every block
452// coincidentally coding one whole-block transform.
453thread_local! {
454 pub(super) static TXFM_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
455 // lane-inter4 r2: rectangular INTER residual coding -- how many rect
456 // strips coded one whole-block rect transform unit, and how many split
457 // their rect max transform into square sub-transforms.
458 pub(super) static RECT_INTER_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
459 pub(super) static RECT_INTER_TXSPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
460 // lane-r14 r2: luma transform units of an inter strip with a 64-px axis
461 // (64x32/32x64/64x16/16x64), whose coefficients are coded as the
462 // truncated low-32 corner.
463 pub(super) static RECT64_INTER_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
464 // lane-rectres r1: whole-block luma transform units of a 32x32-level 1:4
465 // inter strip, `[32x8, 8x32]`.
466 pub(super) static RECT32X8_INTER_TU_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
467 // lane-r14 r3: rectangular var-tx LEAVES, [32x16, 16x32].
468 pub(super) static VARTX_RECT_LEAF_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
469 // lane-inter16ab r4: rectangular var-tx leaves with a 4-px axis, [8x4, 4x8]
470 // -- the `sub_tx_size_map[TX_16X4]` split leaves of a 16x16-level 1:4 strip.
471 pub(super) static VARTX_RECT_LEAF4_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
472 // lane-inter4 r3: 16x16-level PARTITION_HORZ / PARTITION_VERT on an inter
473 // frame -- 16x8 and 8x16 inter leaves.
474 pub(super) static INTER_LEAF16_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
475 pub(super) static INTER_LEAF16_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
476 // This frame's own `tx_mode == TxMode::Select` and `reduced_tx_set` bits,
477 // set once per inter tile by [`decode_inter_frame_tile_with_cdfs`] --
478 // `decode_inter_block` already carries forty parameters and both are
479 // frame-constant.
480 // lane-fiinter r1: this sequence header's own `enable_filter_intra` bit,
481 // frame-constant like the two above and stashed the same way -- an intra
482 // block inside an inter frame reads `use_filter_intra` under it.
483}
484
485/// Current value of [`TXFM_SPLIT_HITS`].
486#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
487pub(crate) fn txfm_split_hits() -> usize {
488 TXFM_SPLIT_HITS.with(|c| c.get())
489}
490
491/// Current value of [`INTER_LEAF16_HORZ_HITS`] (lane-inter4 r3).
492#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
493pub(crate) fn inter_leaf16_horz_hits() -> usize {
494 INTER_LEAF16_HORZ_HITS.with(|c| c.get())
495}
496
497/// Current value of [`INTER_LEAF16_VERT_HITS`] (lane-inter4 r3).
498#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
499pub(crate) fn inter_leaf16_vert_hits() -> usize {
500 INTER_LEAF16_VERT_HITS.with(|c| c.get())
501}
502
503/// Current value of [`RECT_INTER_TU_HITS`] (lane-inter4 r2).
504pub(crate) fn rect_inter_tu_hits() -> usize {
505 RECT_INTER_TU_HITS.with(|c| c.get())
506}
507
508/// Current value of [`RECT_INTER_TXSPLIT_HITS`] (lane-inter4 r2).
509pub(crate) fn rect_inter_txsplit_hits() -> usize {
510 RECT_INTER_TXSPLIT_HITS.with(|c| c.get())
511}
512
513/// Current value of [`RECT64_INTER_TU_HITS`] (lane-r14 r2).
514pub(crate) fn rect64_inter_tu_hits() -> usize {
515 RECT64_INTER_TU_HITS.with(|c| c.get())
516}
517
518/// Current value of [`RECT32X8_INTER_TU_HITS`] (lane-rectres r1): `[32x8, 8x32]`
519/// whole-block luma units of a 32x32-level 1:4 inter strip.
520pub(crate) fn rect32x8_inter_tu_hits() -> [usize; 2] {
521 RECT32X8_INTER_TU_HITS.with(|c| c.get())
522}
523
524/// Current value of [`VARTX_RECT_LEAF_HITS`] (lane-r14 r3): how many
525/// rectangular var-tx leaf transform units were coded, `[32x16, 16x32]`.
526pub(crate) fn vartx_rect_leaf_hits() -> [usize; 2] {
527 VARTX_RECT_LEAF_HITS.with(|c| c.get())
528}
529
530/// Current value of [`VARTX_RECT_LEAF4_HITS`] (lane-inter16ab r4): 8x4/4x8
531/// split leaves of a 16x4/4x16 strip, `[8x4, 4x8]`.
532pub(crate) fn vartx_rect_leaf4_hits() -> [usize; 2] {
533 VARTX_RECT_LEAF4_HITS.with(|c| c.get())
534}
535
536/// Records one rectangular var-tx leaf.
537pub(super) fn vartx_rect_leaf_hit(tw: usize, th: usize) {
538 if crate::envflags::env_flag!("EC_VARTXLEAF") {
539 eprintln!("EC_VARTXLEAF tw={tw} th={th}");
540 }
541 let cell = if tw.min(th) == 4 {
542 &VARTX_RECT_LEAF4_HITS
543 } else {
544 &VARTX_RECT_LEAF_HITS
545 };
546 cell.with(|c| {
547 let mut h = c.get();
548 h[usize::from(th > tw)] += 1;
549 c.set(h);
550 });
551}
552
553// How many `partition_w16` reads (a 16x16 block's own partition symbol, key
554// intra-frame path) resolved to `PARTITION_VERT_B` -- lane-rect16 r1: a
555// plain default-settings aomenc run over lavfi mandelbrot hits this arm on
556// frame 0's very first non-NONE/SPLIT `partition_w16` symbol (mi=(3,2)), not
557// the plain HORZ/VERT this lane's charter assumed. Left rect (8x16, real
558// `decode_block_rect`) + two 8x8 leaves stacked on the right (`decode_leaf8`,
559// chained via `prev_leaf` exactly like the existing 16x16-SPLIT-into-4x8x8
560// path above).
561thread_local! {
562 pub(super) static VERT_B_INTRA_HITS: std::cell::Cell<usize> =
563 const { std::cell::Cell::new(0) };
564}
565
566/// Current value of [`VERT_B_INTRA_HITS`].
567#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
568pub(crate) fn vert_b_intra_hits() -> usize {
569 VERT_B_INTRA_HITS.with(|c| c.get())
570}
571
572// lane-ab16 r1: how many 16x16-level AB partitions fired, per arm, in
573// `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`, `_VERT_B` order. Each arm is two
574// 8x8 squares (`decode_leaf8`) plus one 16x8/8x16 strip (`decode_leaf_rect`,
575// the non-skip coefficient path lane-rectx proved); the gate hard-asserts
576// every arm separately so a run where aomenc's RD only picked one cannot
577// pass as proof of four.
578thread_local! {
579 pub(super) static AB16_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) };
580}
581
582// [`AB16_HITS`] per arm (HORZ_A, HORZ_B, VERT_A, VERT_B at 16x16).
583thread_local! {
584 /// 4x4 transform units decoded inside an 8x8 square of a
585 /// `PARTITION_VERT_A`/`_B` -- the exact call that panicked before
586 /// [`crate::encode::Reach::of_tu`] (lane-ab16 r2), so the gate can prove
587 /// a real `--enable-tx-size-search=1` stream reaches it.
588 pub(super) static VERT_AB_TX4_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
589}
590
591#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
592pub(crate) fn vert_ab_tx4_hits() -> usize {
593 VERT_AB_TX4_HITS.with(std::cell::Cell::get)
594}
595
596#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
597pub(crate) fn ab16_hits_by_arm() -> [usize; 4] {
598 AB16_HITS.with(std::cell::Cell::get)
599}
600
601// How many `partition_w16` reads resolved to a plain `PARTITION_HORZ`/
602// `PARTITION_VERT` (lane-rect16 r2): re-measuring after the VERT_B fix above
603// showed mandelbrot's real first-hit blocker is this plain arm at mi=(0,7),
604// not VERT_B (`refusal-names-a-correlate`; the VERT_B write-up's "frame 0's
605// very first non-NONE/SPLIT symbol" claim was about decode ORDER within one
606// superblock's z-order recursion, not raster mi position).
607thread_local! {
608 pub(super) static HORZ_VERT_INTRA_HITS: std::cell::Cell<usize> =
609 const { std::cell::Cell::new(0) };
610}
611
612/// Current value of [`HORZ_VERT_INTRA_HITS`].
613#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
614pub(crate) fn horz_vert_intra_hits() -> usize {
615 HORZ_VERT_INTRA_HITS.with(|c| c.get())
616}
617
618// How many blocks were decoded as a frame-edge rect strip -- the single
619// coded half of a `PARTITION_HORZ`/`PARTITION_VERT` at the true frame edge
620// (lane-oddh r1), i.e. a block living inside the 8px band of a frame whose
621// height or width is 8 mod 16 (the user's 3840x1608 film). Intra and inter
622// paths share the counter.
623thread_local! {
624 pub(super) static EDGE_RECT_STRIP_HITS: std::cell::Cell<usize> =
625 const { std::cell::Cell::new(0) };
626}
627
628/// Current value of [`EDGE_RECT_STRIP_HITS`].
629#[allow(dead_code)] // gate counter accessor with no reader yet; the counter itself is live
630pub(crate) fn edge_rect_strip_hits() -> usize {
631 EDGE_RECT_STRIP_HITS.with(|c| c.get())
632}
633
634// lane-interedge r1: frame-edge half strips on the INTER path, per partition
635// level (64/32/16) x axis (HORZ at a bottom edge, VERT at a right edge). The
636// index is `level_idx * 2 + axis` with `level_idx` 0=64, 1=32, 2=16 and
637// `axis` 0=HORZ (`!has_rows`), 1=VERT (`!has_cols`). Both of the user's films
638// are height mod 16 == 8, so every inter frame crosses these nodes.
639thread_local! {
640 pub(super) static INTER_EDGE_STRIP_HITS: std::cell::Cell<[usize; 6]> =
641 const { std::cell::Cell::new([0; 6]) };
642}
643
644// lane-edgeboth r1: how many partition nodes were coded as the BOTH-AXES-CUT
645// forced split -- libaom `decode_partition` (decodeframe.c):
646// `else if (!has_rows && !has_cols) partition = PARTITION_SPLIT;`, the one
647// straddle case that reads NO symbol at all. Indexed by level:
648// 0 = 16x16, 1 = 32x32, 2 = 64x64, 3 = 128x128; intra and inter share it.
649thread_local! {
650 pub(super) static EDGE_BOTH_CUT_HITS: std::cell::Cell<[usize; 4]> =
651 const { std::cell::Cell::new([0; 4]) };
652}
653
654/// Current value of [`INTER_EDGE_STRIP_HITS`] (`[h64, v64, h32, v32, h16, v16]`).
655pub fn inter_edge_strip_hits() -> [usize; 6] {
656 INTER_EDGE_STRIP_HITS.with(|c| c.get())
657}
658
659/// Resets [`INTER_EDGE_STRIP_HITS`] -- a refused attempt must not carry hits
660/// into the next one (class `counter-from-refused-stream`).
661pub fn reset_inter_edge_strip_hits() {
662 INTER_EDGE_STRIP_HITS.with(|c| c.set([0; 6]));
663}
664
665/// Current value of [`EDGE_BOTH_CUT_HITS`] (`[16, 32, 64, 128]` levels).
666#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
667pub(crate) fn edge_both_cut_hits() -> [usize; 4] {
668 EDGE_BOTH_CUT_HITS.with(|c| c.get())
669}
670
671/// Zeroes [`EDGE_BOTH_CUT_HITS`] so a gate can measure a per-attempt delta.
672#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
673pub(crate) fn reset_edge_both_cut_hits() {
674 EDGE_BOTH_CUT_HITS.with(|c| c.set([0; 4]));
675}
676
677// How many HORZ/VERT intra strips resolved a SPLIT luma transform
678// (`tx_depth != 0`) and decoded it per transform unit (lane-rectsplit r1) --
679// the case every rect path here refused by name before, and the first
680// refusal the user's ReelB extract (600s in) stops at.
681thread_local! {
682 pub(super) static RECT_SPLIT_TX_HITS: std::cell::Cell<usize> =
683 const { std::cell::Cell::new(0) };
684}
685
686/// Current value of [`RECT_SPLIT_TX_HITS`].
687#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
688pub(crate) fn rect_split_tx_hits() -> usize {
689 RECT_SPLIT_TX_HITS.with(|c| c.get())
690}
691
692// The subset of [`RECT_SPLIT_TX_HITS`] that is BOTH superblock-level (one
693// side 64) AND split past the first depth, i.e. tiled more than one unit in
694// each axis -- the only shape with a transform unit that has neighbours on
695// two sides inside its own strip (`row_off > 0 && col_off > 0`), and the one
696// no gate fired before lane-rectsplit r2 (the shared counter above also
697// counts 32x32-level and depth-1 strips, so it cannot prove this case).
698thread_local! {
699 pub(super) static RECT_SPLIT_SB_INTERIOR_TU_HITS: std::cell::Cell<usize> =
700 const { std::cell::Cell::new(0) };
701}
702
703/// Current value of [`RECT_SPLIT_SB_INTERIOR_TU_HITS`].
704#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
705pub(crate) fn rect_split_sb_interior_tu_hits() -> usize {
706 RECT_SPLIT_SB_INTERIOR_TU_HITS.with(|c| c.get())
707}
708
709// Per-shape hit counts for the rect chroma transforms lane-rectchroma r1
710// wired into [`decode_rect_split`] -- the shapes a split-transform strip's
711// chroma half takes that had no coefficient tables before (index order:
712// 32x8, 8x32, 8x4, 4x8). One counter per shape because a gate that only
713// proves the pair it happens to hit cannot catch a transposed scan/context
714// table (class scan-weights-cross-axis).
715thread_local! {
716 pub(super) static RECT_SPLIT_CHROMA_SHAPE_HITS: std::cell::Cell<[usize; 4]> =
717 const { std::cell::Cell::new([0; 4]) };
718}
719
720/// Current value of [`RECT_SPLIT_CHROMA_SHAPE_HITS`] (32x8, 8x32, 8x4, 4x8).
721#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
722pub(crate) fn rect_split_chroma_shape_hits() -> [usize; 4] {
723 RECT_SPLIT_CHROMA_SHAPE_HITS.with(|c| c.get())
724}
725
726// lane-av1-422: how many SQUARE chroma coefficient units the strip path read
727// on a 4:2:2 frame (ss 1,0) -- the half-width, unhalved-height shape whose
728// tables only exist because of the square rows in the chroma_tiled arm. A
729// 4:2:0 or 4:4:4 frame can never increment it (their rect strips' chroma is
730// itself rect), and a restored `/2 chroma height` diverts 4:2:2 squares onto
731// the rect rows, so the witness gate reads 0 there and fails.
732thread_local! {
733 pub(super) static CHROMA422_SQUARE_HITS: std::cell::Cell<usize> =
734 const { std::cell::Cell::new(0) };
735}
736
737/// Current value of [`CHROMA422_SQUARE_HITS`].
738// lane-av1-422b: `pub` so `examples/decode_probe.rs` can census it the way
739// it does every other capability counter.
740pub fn chroma422_square_hits() -> usize {
741 CHROMA422_SQUARE_HITS.with(|c| c.get())
742}
743
744// lane-av1422tailskip: how many 4:2:2 (ss 1,0) intra-in-inter chroma TRANSFORM
745// UNITS took their own window on the block-sized chroma palette prediction --
746// `decode_inter_block`'s `side == 64` TX_32X32 walk, where the plane block is
747// 32x64 but codes two stacked square units per plane. Zero on a 4:2:0 or 4:4:4
748// frame (their chroma unit is the whole plane block, one window), and zero on
749// a 4:2:2 block with no palette, so a witness gate reading 0 proves the arm
750// never ran.
751thread_local! {
752 pub(super) static PALETTE_422_UNIT_WINDOW_HITS: std::cell::Cell<usize> =
753 const { std::cell::Cell::new(0) };
754}
755
756/// Current value of [`PALETTE_422_UNIT_WINDOW_HITS`].
757// lane-av1422tailskip: `pub` so `examples/decode_probe.rs` can census it the
758// way it does every other capability counter.
759pub fn palette_422_unit_window_hits() -> usize {
760 PALETTE_422_UNIT_WINDOW_HITS.with(|c| c.get())
761}
762
763// lane-av1-422f: how many RECT chroma coefficient units the square-block
764// path read on a 4:2:2 frame (ss 1,0) -- TX_4X8 / TX_8X16 / TX_16X32, the
765// plane block's own half-width, unhalved-height shape. A 4:2:0 or 4:4:4
766// frame never takes the rect branch (their units are square
767// `chroma_tx == chroma_tx_h`), so a witness gate reading 0 here proves the
768// model reverted to squares.
769thread_local! {
770 pub(super) static CHROMA422_RECT_HITS: std::cell::Cell<usize> =
771 const { std::cell::Cell::new(0) };
772}
773
774/// Current value of [`CHROMA422_RECT_HITS`].
775pub fn chroma422_rect_hits() -> usize {
776 CHROMA422_RECT_HITS.with(|c| c.get())
777}
778
779// lane-av1-422g: how many PER-LEAF TX_4X4 chroma coefficient units the
780// sub-8x8 split4 path read on a 4:2:2 frame (ss 1,0) -- one per even-column
781// leaf per plane (`is_chroma_reference`'s `!(mi_col & ss_x)`). A 4:2:0 frame
782// codes no sub-8 chroma at all and 4:4:4 goes through `sub8_leaf_chroma444`,
783// so a witness gate reading 0 here proves the per-leaf 4:2:2 arm never ran.
784thread_local! {
785 pub(super) static CHROMA422_SUB8_HITS: std::cell::Cell<usize> =
786 const { std::cell::Cell::new(0) };
787}
788
789/// Current value of [`CHROMA422_SUB8_HITS`].
790pub fn chroma422_sub8_hits() -> usize {
791 CHROMA422_SUB8_HITS.with(|c| c.get())
792}
793
794// lane-av1422llintra: how many 4:2:2 LOSSLESS chroma plane blocks
795// (`decode_leaf8`) were walked as 4x4 units rather than as the one
796// `av1_get_max_uv_txsize` rect that rule only reaches OUTSIDE a lossless
797// frame. A 4:2:0 or 4:4:4 frame never takes the arm (its own lossless walk
798// was already there), so a witness gate reading 0 here proves the model
799// reverted to the rect unit.
800thread_local! {
801 pub(super) static CHROMA422_LOSSLESS_4X4_HITS: std::cell::Cell<usize> =
802 const { std::cell::Cell::new(0) };
803}
804
805/// Current value of [`CHROMA422_LOSSLESS_4X4_HITS`].
806pub fn chroma422_lossless_4x4_hits() -> usize {
807 CHROMA422_LOSSLESS_4X4_HITS.with(|c| c.get())
808}
809
810// lane-av1-422sub8rect: how many PER-PIECE TX_4X4 chroma coefficient units
811// the INTER sub-8x8 split4 path read on a 4:2:2 frame (ss 1,0) -- one per
812// non-skipped odd-column piece per plane (`is_chroma_reference`'s
813// `mi_col & 0x01` at ss_x 1). 4:2:0 goes through the shared group unit and
814// 4:4:4 through [`sub8_leaf_chroma444`]'s own per-piece twin, so a witness
815// gate reading 0 here proves the inter 4:2:2 per-piece arm never ran.
816thread_local! {
817 pub(super) static CHROMA422_INTER_SUB8_HITS: std::cell::Cell<usize> =
818 const { std::cell::Cell::new(0) };
819}
820
821/// Current value of [`CHROMA422_INTER_SUB8_HITS`].
822pub fn chroma422_inter_sub8_hits() -> usize {
823 CHROMA422_INTER_SUB8_HITS.with(|c| c.get())
824}
825
826// lane-av1-422m: how many TX_4X4 chunk units the invalid-ss-size chroma arm
827// read (the 8x32 luma block whose 4:2:2 plane has no `ss_size_lookup` block).
828// A 4:2:0 or 4:4:4 frame cannot increment it, so a non-zero read proves the
829// chunked 4:2:2 chroma really decoded.
830thread_local! {
831 pub(super) static CHROMA422_CHUNK_HITS: std::cell::Cell<usize> =
832 const { std::cell::Cell::new(0) };
833}
834
835/// Current value of [`CHROMA422_CHUNK_HITS`].
836pub fn chroma422_chunk_hits() -> usize {
837 CHROMA422_CHUNK_HITS.with(|c| c.get())
838}
839
840// lane-av1-422stripanchor: how many 4-wide-strip PAIR chroma units
841// ([`decode_rect_split`]'s ported floored-pair anchor) decoded. A 4:2:0 or
842// 4:4:4 frame cannot increment it (the arm is keyed to a 2-px-wide chroma
843// block, which only a 1-mi-wide strip at ss (1, 0) produces), so a non-zero
844// read proves a stream routed a 4-wide strip through the split path.
845thread_local! {
846 pub(super) static CHROMA422_PAIR_WIDE_HITS: std::cell::Cell<usize> =
847 const { std::cell::Cell::new(0) };
848}
849
850/// Current value of [`CHROMA422_PAIR_WIDE_HITS`].
851pub fn chroma422_pair_wide_hits() -> usize {
852 CHROMA422_PAIR_WIDE_HITS.with(|c| c.get())
853}
854
855// How many HORZ/VERT intra strips actually predicted with filter intra
856// (lane-rectsplit r1) -- the case `decode_block_rect` refused by name
857// ("this decoder predicts square-only") until `predict_filter_intra` took
858// `bw`x`bh`.
859thread_local! {
860 pub(super) static FILTER_INTRA_RECT_HITS: std::cell::Cell<usize> =
861 const { std::cell::Cell::new(0) };
862}
863
864/// Current value of [`FILTER_INTRA_RECT_HITS`].
865#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
866pub(crate) fn filter_intra_rect_hits() -> usize {
867 FILTER_INTRA_RECT_HITS.with(|c| c.get())
868}
869
870// As [`FILTER_INTRA_RECT_HITS`], counting only the 32x32-level 1:4 strips
871// (32x8/8x32, lane-fi32x8 r1) -- the shapes whose `use_filter_intra` symbol
872// was never read at all before that round, so a gate needs to prove the flag
873// fired at THAT shape and not at a 16x8 one somewhere else in the frame.
874// Split by ORIENTATION: rows 8 (32x8) and 9 (8x32) of `cdf::FILTER_INTRA`
875// carry different probabilities (18101 vs 20229), so a transposed pair is
876// only caught by a gate that sees the flag fire on BOTH shapes (class
877// scan-weights-cross-axis).
878thread_local! {
879 pub(super) static FILTER_INTRA_RECT4_HORZ_HITS: std::cell::Cell<usize> =
880 const { std::cell::Cell::new(0) };
881 pub(super) static FILTER_INTRA_RECT4_VERT_HITS: std::cell::Cell<usize> =
882 const { std::cell::Cell::new(0) };
883}
884
885/// Current value of [`FILTER_INTRA_RECT4_HORZ_HITS`] (32x8 strips).
886#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
887pub(crate) fn filter_intra_rect4_horz_hits() -> usize {
888 FILTER_INTRA_RECT4_HORZ_HITS.with(|c| c.get())
889}
890
891/// Current value of [`FILTER_INTRA_RECT4_VERT_HITS`] (8x32 strips).
892#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
893pub(crate) fn filter_intra_rect4_vert_hits() -> usize {
894 FILTER_INTRA_RECT4_VERT_HITS.with(|c| c.get())
895}
896
897// How many rectangular transform units actually coded coefficients through
898// [`read_coeffs_rect`] (`all_zero == 0`) -- lane-rect1d's measure that a gate
899// exercised the rect coefficient reader at all rather than passing on
900// all-skip blocks.
901thread_local! {
902 pub(super) static RECT_COEFF_TU_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
903 pub(super) static RECT_CLASS1_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
904}
905
906/// Current value of [`RECT_COEFF_TU_HITS`].
907#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
908pub(crate) fn rect_coeff_tu_hits() -> usize {
909 RECT_COEFF_TU_HITS.with(|c| c.get())
910}
911
912/// Rectangular transform units whose resolved `tx_type` is a 1D class
913/// (`V_DCT`/`H_DCT`) -- [`TX_CLASS1_HITS`]'s rect-only half, so a gate can
914/// pin that the 1D-class-on-a-RECT-transform path fired rather than settling
915/// for the square reader's own 1D types.
916#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
917pub(crate) fn rect_class1_hits() -> usize {
918 RECT_CLASS1_HITS.with(|c| c.get())
919}
920
921// lane-av1readcensus: the PER-UNIT coefficient census -- one unit counted
922// per `read_coeffs`/`read_coeffs_rect` call, i.e. per object this decoder
923// actually walks, which is the unit the round-4 `av1444rect` count measured
924// (636 square chroma reads against the oracle's 1086).
925//
926// lane-av1422census422 widened the arming. The counters used to be
927// 4:4:4-ONLY (`CENSUS_444`), so at 4:2:2 -- a chroma format an AV1
928// `color_config` can carry and libaom's writer emits -- every
929// `census_444_units()` / `census_444_coded()` read zero BY CONSTRUCTION: a
930// byte-exact 4:2:2 gate asserting those counters would be asserting a
931// literal, and would be green while proving nothing about that stream. The
932// census is now armed for every chroma format that leaves at least one luma
933// axis unsubsampled -- (0,0) 4:4:4 and (1,0) 4:2:2 -- and 4:2:0 (1,1) stays
934// off, so the existing 4:4:4 exact counts and the 4:2:0 zero control are
935// unmoved by the widening. The counters are per-PLANE, not per-format, so a
936// 4:2:2 cell's `[luma, u, v]` split is directly comparable with a 4:4:4
937// cell's on the same walk shape.
938thread_local! {
939 /// Per-plane unit counts, `[luma, u, v]`, at 4:4:4 and 4:2:2.
940 pub(super) static CENSUS_NONSUB_UNITS: std::cell::Cell<[usize; 3]> = const { std::cell::Cell::new([0; 3]) };
941 /// Of [`CENSUS_NONSUB_UNITS`], the units that coded at least one
942 /// coefficient (`txb_skip == 0`) -- the per-plane split is only
943 /// comparable against the oracle's when both sides count all-zero units
944 /// the same way.
945 pub(super) static CENSUS_NONSUB_CODED: std::cell::Cell<[usize; 3]> = const { std::cell::Cell::new([0; 3]) };
946 /// Sequential unit index, so a trace line names its own position in the
947 /// frame's walk rather than relying on line order alone.
948 pub(super) static CENSUS_UNIT_N: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
949 /// The plane the units read from here on belong to. A thread-local rather
950 /// than a `read_coeffs` parameter because the three luma call sites
951 /// (`decode_rect_split`, `decode_block_rect64`, `read_inter_plane_rect`)
952 /// are not this lane's to edit and would each grow an argument; the
953 /// plane-owning readers stamp it once on entry instead.
954 pub(super) static CENSUS_PLANE: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
955 /// At least one luma axis unsubsampled -- (0,0) 4:4:4 or (1,0) 4:2:2 --
956 /// for the frame being decoded, set per frame from [`crate::stream`].
957 /// 4:2:0 (1,1) arms nothing.
958 pub(super) static CENSUS_NONSUB: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
959}
960
961/// Current `[luma, u, v]` coefficient-unit counts, per plane. Zero at 4:2:0
962/// by design ([`set_census_nonsub`] arms nothing there).
963pub fn census_nonsub_units() -> [usize; 3] {
964 CENSUS_NONSUB_UNITS.with(|c| c.get())
965}
966
967/// Current `[luma, u, v]` counts of units that coded coefficients.
968pub fn census_nonsub_coded() -> [usize; 3] {
969 CENSUS_NONSUB_CODED.with(|c| c.get())
970}
971
972/// lane-av1readcensus: arms the coefficient-unit census for the frame about
973/// to decode, called once per frame from [`crate::stream`]'s decode loop
974/// beside [`set_subsampling`]. Armed for every chroma format with an
975/// unsubsampled luma axis -- 4:4:4 (0,0) and 4:2:2 (1,0) -- and NOT for
976/// 4:2:0 (1,1), where the walk-shape question this census answers does not
977/// arise, so a 4:2:0 control can still assert exactly zero.
978///
979/// lane-av1422census422 widened this from `(ss_x == 0 && ss_y == 0)`. The
980/// old condition made 4:2:2 silently UNCUNTABLE rather than uncounted. The
981/// two format pairs keep disjoint conditions, so neither the 4:4:4 exact
982/// counts nor the 4:2:0 zero control can move because of this.
983pub(crate) fn set_census_nonsub(ss_x: u8, ss_y: u8) {
984 CENSUS_NONSUB.with(|c| c.set(ss_x == 0 || ss_y == 0));
985}
986
987/// lane-av1readcensus: the plane the units read from here on belong to,
988/// stamped by the plane-owning readers ([`read_plane`], [`read_inter_plane`],
989/// [`read_inter_plane_rect`]) on entry.
990pub(crate) fn set_census_plane(plane: usize) {
991 CENSUS_PLANE.with(|c| c.set(plane));
992}
993
994/// lane-av1readcensus: is the per-unit census trace on? Shares
995/// [`coeff_trace_on`]'s per-frame narrowing so one frame's walk can be
996/// dumped without the rest of the stream.
997fn census_trace_on() -> bool {
998 if !crate::envflags::env_flag!("EC_CENSUS_UNIT") {
999 return false;
1000 }
1001 match COEFF_TRACE_FRAME.with(|c| c.get()) {
1002 None => true,
1003 Some(w) if w >= usize::MAX - 1 => true,
1004 Some(w) => COEFF_TRACE_CUR.with(|c| c.get()) == w,
1005 }
1006}
1007
1008/// lane-av1readcensus: one line per coefficient unit this decoder walks, the
1009/// twin of the oracle's `EC_COEFF` / `EC_COEFF_VAL` bracket around each
1010/// `av1_read_coeffs_txb` call. Pair the two sides by `post_rng` (or by `n`),
1011/// never by plane label or by walk position -- the walk order is exactly what
1012/// the census is measuring.
1013pub(super) fn census_unit(
1014 w: usize,
1015 h: usize,
1016 tx_type: TxType,
1017 eob: usize,
1018 all_zero: bool,
1019 entry_rng: u32,
1020 dec: &SymbolDecoder,
1021) {
1022 let plane = CENSUS_PLANE.with(|c| c.get()).min(2);
1023 let coded = usize::from(!all_zero);
1024 CENSUS_UNIT_N.with(|c| c.set(c.get() + 1));
1025 hit_do! {
1026 CENSUS_NONSUB_UNITS.with(|c| {
1027 if CENSUS_NONSUB.with(|on| on.get()) {
1028 let mut v = c.get();
1029 v[plane] += 1;
1030 c.set(v);
1031 }
1032 });
1033 CENSUS_NONSUB_CODED.with(|c| {
1034 if CENSUS_NONSUB.with(|on| on.get()) {
1035 let mut v = c.get();
1036 v[plane] += coded;
1037 c.set(v);
1038 }
1039 });
1040 }
1041 if !census_trace_on() {
1042 return;
1043 }
1044 let n = CENSUS_UNIT_N.with(|c| c.get()) - 1;
1045 let post_rng = dec.debug_state().0;
1046 eprintln!(
1047 "EC_CENSUS_UNIT side=ours n={n} plane={plane} w={w} h={h} tx={tx_type:?} eob={eob} \
1048 all_zero={all_zero} entry_rng={entry_rng} post_rng={post_rng}"
1049 );
1050}
1051
1052/// How many transform units this thread has read since the last
1053/// [`reset_census_unit_n`] (lane-av1offtile). The per-unit oracle twin is
1054/// `EC_ECDUMP_IN`, one line per `read_coeffs_txb` call, so this count IS
1055/// directly comparable with an oracle `EC_ECDUMP_IN` census -- which is what
1056/// makes "we walk N units where libaom walks M" a gated claim rather than an
1057/// inference from the desync's position.
1058pub fn census_unit_n() -> usize {
1059 CENSUS_UNIT_N.with(|c| c.get())
1060}
1061
1062/// Reset [`census_unit_n`] to zero (lane-av1offtile).
1063pub fn reset_census_unit_n() {
1064 CENSUS_UNIT_N.with(|c| c.set(0));
1065}
1066
1067// As [`FILTER_INTRA_RECT_HITS`], counting only the strips BELOW 16x16
1068// (8x16/16x8 leaves of a 16x16 HORZ/VERT partition, lane-fistrip r1) -- the
1069// shapes whose `use_filter_intra` symbol had no CDF class before this round.
1070// A gate asserting the wider counter would be satisfied by a 32x16 strip and
1071// prove nothing about the new shapes.
1072thread_local! {
1073 pub(super) static FILTER_INTRA_RECT_SUB16_HITS: std::cell::Cell<usize> =
1074 const { std::cell::Cell::new(0) };
1075}
1076
1077/// Current value of [`FILTER_INTRA_RECT_SUB16_HITS`].
1078#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1079pub(crate) fn filter_intra_rect_sub16_hits() -> usize {
1080 FILTER_INTRA_RECT_SUB16_HITS.with(|c| c.get())
1081}
1082
1083// As [`FILTER_INTRA_RECT_SUB16_HITS`], one partition level further down:
1084// 4x8/8x4 leaves of an 8x8 HORZ/VERT (lane-fi8 r1). A gate on the sub16
1085// counter would be satisfied by a 16x8 strip and prove nothing here.
1086thread_local! {
1087 pub(super) static FILTER_INTRA_RECT_SUB8_HITS: std::cell::Cell<usize> =
1088 const { std::cell::Cell::new(0) };
1089}
1090
1091/// Current value of [`FILTER_INTRA_RECT_SUB8_HITS`].
1092#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1093pub(crate) fn filter_intra_rect_sub8_hits() -> usize {
1094 FILTER_INTRA_RECT_SUB8_HITS.with(|c| c.get())
1095}
1096
1097// How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D`
1098// (`V_DCT`/`H_DCT`, spec 5.11.39's `TxClass::Horiz`/`Vert`), across every
1099// call on the current thread -- the same before/after counter pattern as
1100// [`TX_DEPTH_HITS`], proving a stream actually exercised the class-split
1101// `eob_pt`/1D-neighbour context path rather than every block coincidentally
1102// landing on `DCT_DCT`.
1103thread_local! {
1104 pub(super) static TX_CLASS1_HITS: std::cell::Cell<usize> =
1105 const { std::cell::Cell::new(0) };
1106}
1107
1108// How many `uv_mode` reads resolved to a directional chroma mode (neither
1109// `DC_PRED` nor `UV_CFL_PRED`), across every call on the current thread -- the same
1110// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
1111// actually exercised chroma's own directional predictor.
1112thread_local! {
1113 pub(super) static DIRECTIONAL_UV_HITS: std::cell::Cell<usize> =
1114 const { std::cell::Cell::new(0) };
1115}
1116
1117/// Current value of [`DIRECTIONAL_UV_HITS`].
1118#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1119pub(crate) fn directional_uv_hits() -> usize {
1120 DIRECTIONAL_UV_HITS.with(|c| c.get())
1121}
1122
1123// How many `angle_delta`/`angle_delta_uv` symbols this decoder has read as
1124// something other than [`ANGLE_DELTA_ZERO`], across every call in the
1125// process -- the same before/after counter pattern as [`FILTER_INTRA_HITS`],
1126// proving a stream actually exercised a nonzero angle delta.
1127thread_local! {
1128 pub(super) static ANGLE_DELTA_HITS: std::cell::Cell<usize> =
1129 const { std::cell::Cell::new(0) };
1130}
1131
1132// How many [`read_single_ref`] reads resolved to a reference other than
1133// `LAST_FRAME`, across every call on the current thread -- the same before/after
1134// counter pattern as [`FILTER_INTRA_HITS`], proving a stream actually
1135// exercised a non-`LAST_FRAME` reference (`GOLDEN_FRAME`, this decoder's
1136// only other supported one so far) rather than every block coincidentally
1137// resolving `LAST_FRAME`.
1138thread_local! {
1139 pub(super) static NON_LAST_REF_HITS: std::cell::Cell<usize> =
1140 const { std::cell::Cell::new(0) };
1141}
1142
1143/// Current value of [`NON_LAST_REF_HITS`].
1144#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1145pub(crate) fn non_last_ref_hits() -> usize {
1146 NON_LAST_REF_HITS.with(|c| c.get())
1147}
1148
1149// Per-reference [`NON_LAST_REF_HITS`] breakdown (lane-av1refs): one counter
1150// per `MV_REFERENCE_FRAME` past `LAST_FRAME`, so a gate targeting one
1151// specific reference (`LAST2`/`LAST3`/`GOLDEN`/`BWDREF`/`ALTREF2`/`ALTREF`)
1152// can prove THAT reference fired rather than any non-`LAST_FRAME` one --
1153// `NON_LAST_REF_HITS` alone cannot tell a `LAST2_FRAME` gate from a
1154// `GOLDEN_FRAME` draw it did not ask for.
1155thread_local! {
1156 pub(super) static LAST2_HITS: std::cell::Cell<usize> =
1157 const { std::cell::Cell::new(0) };
1158}
1159
1160thread_local! {
1161 pub(super) static LAST3_HITS: std::cell::Cell<usize> =
1162 const { std::cell::Cell::new(0) };
1163}
1164
1165thread_local! {
1166 pub(super) static GOLDEN_HITS: std::cell::Cell<usize> =
1167 const { std::cell::Cell::new(0) };
1168}
1169
1170thread_local! {
1171 pub(super) static BWDREF_HITS: std::cell::Cell<usize> =
1172 const { std::cell::Cell::new(0) };
1173}
1174
1175thread_local! {
1176 pub(super) static ALTREF2_HITS: std::cell::Cell<usize> =
1177 const { std::cell::Cell::new(0) };
1178}
1179
1180thread_local! {
1181 pub(super) static ALTREF_HITS: std::cell::Cell<usize> =
1182 const { std::cell::Cell::new(0) };
1183}
1184
1185// How many [`read_comp_mode`] reads resolved `COMPOUND_REFERENCE` (lane-av1comp)
1186// -- proves a `reference_select` stream actually reached a block that picked
1187// compound, not just that the header bit was set. Every such block is
1188// refused after this fires ([`decode_inter_block`]/[`decode_inter_block8`]),
1189// so this only ever counts attempted reads, never a completed decode.
1190thread_local! {
1191 pub(super) static COMP_MODE_HITS: std::cell::Cell<usize> =
1192 const { std::cell::Cell::new(0) };
1193}
1194
1195/// Current value of [`COMP_MODE_HITS`].
1196#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1197pub(crate) fn comp_mode_hits() -> usize {
1198 COMP_MODE_HITS.with(|c| c.get())
1199}
1200
1201// How many blocks [`read_intra_mode`] decoded a real (nonzero-size) palette-Y
1202// use for, across every call on the current thread -- the same before/after
1203// counter pattern as [`FILTER_INTRA_HITS`], proving a stream actually
1204// exercised palette reconstruction rather than only reading and refusing the
1205// `palette_y_mode` symbol.
1206thread_local! {
1207 pub(super) static PALETTE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1208}
1209
1210/// Current value of [`PALETTE_HITS`].
1211#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1212pub(crate) fn palette_hits() -> usize {
1213 PALETTE_HITS.with(|c| c.get())
1214}
1215
1216// lane-tiles r12: of those, how many sat at their own TILE's left column --
1217// exactly the blocks whose palette cache/ctx must NOT see the previous tile's
1218// colours (`av1_get_palette_cache`'s `xd->left_mbmi == NULL`). A multi-tile
1219// palette gate that never hits one proves nothing about the tile guard.
1220thread_local! {
1221 pub(super) static PALETTE_TILE_LEFT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1222}
1223
1224/// Current value of [`PALETTE_TILE_LEFT_HITS`].
1225#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1226pub(crate) fn palette_tile_left_hits() -> usize {
1227 PALETTE_TILE_LEFT_HITS.with(|c| c.get())
1228}
1229
1230// lane-palette2 r1: as [`PALETTE_HITS`], for a real (nonzero-size) chroma
1231// palette use -- proves a stream actually reconstructed UV palette pixels,
1232// not just read and refused the `palette_uv_mode` symbol.
1233thread_local! {
1234 pub(super) static PALETTE_UV_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1235}
1236
1237/// Current value of [`PALETTE_UV_HITS`].
1238#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1239pub(crate) fn palette_uv_hits() -> usize {
1240 PALETTE_UV_HITS.with(|c| c.get())
1241}
1242
1243// lane-palette2 r1: how many HORZ/VERT rect intra strips ([`read_intra_mode_rect`])
1244// decoded a real palette-Y use -- proves the rect strip's own palette syntax
1245// (not just the square path's) actually fired.
1246thread_local! {
1247 pub(super) static PALETTE_RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1248}
1249
1250/// Current value of [`PALETTE_RECT_HITS`].
1251#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1252pub(crate) fn palette_rect_hits() -> usize {
1253 PALETTE_RECT_HITS.with(|c| c.get())
1254}
1255
1256// lane-palette2 r6: how many HORZ/VERT rect intra strips ran the
1257// [`palette_bsize_ctx_wh`]-gated code path in [`read_intra_mode_rect`] --
1258// i.e. `allow_screen_content_tools` was set and the strip's `bw`x`bh` was in
1259// range, so `palette_y_mode`/`palette_uv_mode` were actually read (and, per
1260// RD, almost always refused-on-use because the block doesn't end up USING a
1261// palette -- see r5's report). This is the site the removed refusal
1262// ("a HORZ/VERT intra strip in a screen-content frame") used to guard: it
1263// fired here whether or not the block picked a palette, so this is the
1264// counter that proves the case r5's narrower [`PALETTE_RECT_HITS`] almost
1265// never observes.
1266thread_local! {
1267 pub(super) static RECT_SCREEN_CONTENT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1268}
1269
1270/// Current value of [`RECT_SCREEN_CONTENT_HITS`].
1271#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1272pub(crate) fn rect_screen_content_hits() -> usize {
1273 RECT_SCREEN_CONTENT_HITS.with(|c| c.get())
1274}
1275
1276// lane-palette2 r1: how many palette-Y luma transform UNITS decoded under a
1277// split luma transform (`logical_tx != side`) -- proves the per-TU index-map
1278// windowing actually ran, not just that the whole-block path stayed exact.
1279// Counts units, not blocks (a 64x64 palette block split to 16x16 TUs adds 16);
1280// first actually incremented in r7, when the refusal it guarded was lifted.
1281thread_local! {
1282 pub(super) static PALETTE_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1283}
1284
1285thread_local! {
1286 /// lane-kf900 r4: rect intra strips that ACTUALLY use a palette -- the
1287 /// 1:4 shapes (32x8/8x32, 16x4/4x16) and the sub-16x16 2:1 leaves
1288 /// (16x8/8x16), the two shapes the lifted refusals named.
1289 pub(super) static RECT4_PALETTE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1290}
1291
1292/// Current value of [`RECT4_PALETTE_HITS`].
1293#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1294pub(crate) fn rect4_palette_hits() -> usize {
1295 RECT4_PALETTE_HITS.with(|c| c.get())
1296}
1297
1298/// Current value of [`PALETTE_SPLIT_TX_HITS`].
1299#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1300pub(crate) fn palette_split_tx_hits() -> usize {
1301 PALETTE_SPLIT_TX_HITS.with(|c| c.get())
1302}
1303
1304thread_local! {
1305 /// lane-av1444d10: chroma PREDICTION units on the 32-capped tiled chroma
1306 /// walk (`decode_block_rect`'s `uw/uh = min(chroma, 32)` units) that were
1307 /// handed a STRICT sub-slice of their block's palette buffer -- i.e. the
1308 /// units of a block the 32-cap actually TILED (`nw * nh > 1`).
1309 ///
1310 /// CORRECTED 2026-09-30 after the refutation pass `lanes/refute-av1444d10`
1311 /// read the numbers back: the previous comment claimed it counted "the
1312 /// units that are NOT the block's top-left corner", which is not what the
1313 /// code did -- the hit was unconditional, so a block's corner unit fired it
1314 /// too AND a single-unit block (whose window is a pure re-stride copy of
1315 /// the whole buffer) fired it as well. That made a hit prove only that some
1316 /// palette chroma block existed, not that the tiled arm ran. The `bigger`
1317 /// guard now makes the counter discriminate. On the pinned fixture the
1318 /// measured value is unchanged at 4 (one block with nw = 1, nh = 2 x two
1319 /// planes x two unit rows); a stream whose palette chroma blocks are all
1320 /// single-unit now leaves it at zero.
1321 ///
1322 /// FURTHER CORRECTED the same day by the palette lane's refutation
1323 /// (`lanes/av1444palw.report.md` + the arm-isolated mutation): the guard is
1324 /// about TILING, not about `nw > 1` specifically. Isolating the two window
1325 /// sites shows the RECT-unit arm alone reds the 10-bit cell, and the
1326 /// SQUARE-unit arm alone reds the 12-bit cell *and* the 10-bit one -- so
1327 /// windowing is load-bearing for every tiled block, and `nw > 1` is merely
1328 /// the case the corpus could not reach. Do not read this counter as
1329 /// evidence that only the horizontal term matters.
1330 pub(super) static CHROMA_PALETTE_WINDOW_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1331}
1332
1333/// Current value of [`CHROMA_PALETTE_WINDOW_HITS`].
1334#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1335pub(crate) fn chroma_palette_window_hits() -> usize {
1336 CHROMA_PALETTE_WINDOW_HITS.with(|c| c.get())
1337}
1338
1339/// Zeroes [`CHROMA_PALETTE_WINDOW_HITS`] so a gate can read it as a DELTA
1340/// (it is process-wide, like every counter here).
1341#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1342pub(crate) fn reset_chroma_palette_window_hits() {
1343 CHROMA_PALETTE_WINDOW_HITS.with(|c| c.set(0));
1344}
1345
1346thread_local! {
1347 /// lane-pal8 r1: square 8x8 LEAVES ([`decode_leaf8`]) that actually use a
1348 /// palette (Y or UV) -- the shape every 8-bit `--tune-content=screen`
1349 /// stream stopped on, since aomenc palettes square blocks at 8 bit and
1350 /// `--min-partition-size=8` puts them on this leaf path.
1351 pub(super) static PALETTE_LEAF8_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1352}
1353
1354/// Current value of [`PALETTE_LEAF8_HITS`].
1355#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1356pub(crate) fn palette_leaf8_hits() -> usize {
1357 PALETTE_LEAF8_HITS.with(|c| c.get())
1358}
1359
1360/// Zeroes [`PALETTE_LEAF8_HITS`] (per-attempt gate counting).
1361#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1362pub(crate) fn reset_palette_leaf8_hits() {
1363 PALETTE_LEAF8_HITS.with(|c| c.set(0));
1364}
1365
1366thread_local! {
1367 /// lane-pal8 r1: NON-SKIP palette blocks on a superblock-level (64-level)
1368 /// HORZ/VERT or 1:4 strip ([`decode_block_rect64`]) -- i.e. a palette
1369 /// block that also carries a real, corner-cropped luma transform.
1370 pub(super) static PALETTE_SB_STRIP_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1371}
1372
1373/// Current value of [`PALETTE_SB_STRIP_HITS`].
1374#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1375pub(crate) fn palette_sb_strip_hits() -> usize {
1376 PALETTE_SB_STRIP_HITS.with(|c| c.get())
1377}
1378
1379/// Zeroes [`PALETTE_SB_STRIP_HITS`] (per-attempt gate counting).
1380#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1381pub(crate) fn reset_palette_sb_strip_hits() {
1382 PALETTE_SB_STRIP_HITS.with(|c| c.set(0));
1383}
1384
1385thread_local! {
1386 /// lane-av1rectreach: units of `decode_rect_split`'s `chroma_tiled` walk
1387 /// whose PER-UNIT reach ([`tu_reach_rect`], libaom's per-unit
1388 /// `has_top_right` / `has_bottom_left`) DIFFERS from the block-level
1389 /// `reach` this walk used to hand every unit -- i.e. units for which the
1390 /// two answers are not interchangeable. This is what a gate needs before
1391 /// it compares the walk byte-exactly: if the two agreed everywhere, the
1392 /// substitution could not change a single predicted sample and the
1393 /// exactness assert would be measuring a witness the fix cannot touch.
1394 ///
1395 /// What it does NOT prove is that the argument handed to the unit reader
1396 /// is the per-unit one -- the count is taken from the same expression
1397 /// either way, so deleting the substitution reds the exactness assert
1398 /// rather than this counter. That is the right way round: the assert is
1399 /// the claim, this is only the floor under it.
1400 pub(super) static RECT_TILED_CHROMA_UNIT_REACH_HITS: std::cell::Cell<usize> =
1401 const { std::cell::Cell::new(0) };
1402 /// Chroma units of the same walk whose grid is exactly 2x1 (a 4:4:4
1403 /// 64x32 chroma plane block as two 32x32 units).
1404 pub(super) static RECT_TILED_CHROMA_2X1_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1405 /// Chroma units of the same walk whose grid is exactly 1x2 (4:4:4 32x64,
1406 /// or 16x64 as two 16x32s).
1407 pub(super) static RECT_TILED_CHROMA_1X2_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1408 /// Chroma units of the same walk in any other multi-unit grid (2x2 and
1409 /// up). lane-av1422lift: this used to say "only reachable at 4:2:2, which
1410 /// is refused, so this stays 0 on every admitted stream", and that was
1411 /// true. 4:2:2 is decoded now, so the "cannot happen" is gone -- but the
1412 /// arm is still UNWITNESSED: measured on this branch's tip over all 21
1413 /// committed 4:2:2 cells and over the 4:2:0 / 4:4:4 cells probed, it
1414 /// reads 0 on every one of them. No committed gate reads it either (the
1415 /// only readers of `rect_tiled_chroma_grid_hits()` are two 4:4:4 strip
1416 /// gates, where `nxn` is interpolated into a failure message and never
1417 /// asserted). Kept so the match above is exhaustive.
1418 pub(super) static RECT_TILED_CHROMA_NXN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1419}
1420
1421/// Current values of the four `RECT_TILED_CHROMA_*` counters, in the order
1422/// `(unit_reach_differs, 2x1, 1x2, other multi-unit)`.
1423#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1424pub(crate) fn rect_tiled_chroma_grid_hits() -> (usize, usize, usize, usize) {
1425 (
1426 RECT_TILED_CHROMA_UNIT_REACH_HITS.with(|c| c.get()),
1427 RECT_TILED_CHROMA_2X1_HITS.with(|c| c.get()),
1428 RECT_TILED_CHROMA_1X2_HITS.with(|c| c.get()),
1429 RECT_TILED_CHROMA_NXN_HITS.with(|c| c.get()),
1430 )
1431}
1432
1433/// Zeroes the four `RECT_TILED_CHROMA_*` counters (gate tests call this
1434/// before their own decode).
1435#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1436pub(crate) fn reset_rect_tiled_chroma_grid_hits() {
1437 RECT_TILED_CHROMA_UNIT_REACH_HITS.with(|c| c.set(0));
1438 RECT_TILED_CHROMA_2X1_HITS.with(|c| c.set(0));
1439 RECT_TILED_CHROMA_1X2_HITS.with(|c| c.set(0));
1440 RECT_TILED_CHROMA_NXN_HITS.with(|c| c.set(0));
1441}
1442
1443// lane-t900 r22: palette blocks reconstructed inside an INTER frame (the
1444// intra-in-inter path, `decode_inter_block`/`decode_inter_block8`) -- counted
1445// apart from [`PALETTE_HITS`] so a witness gate can prove the INTER-frame
1446// capability rather than the key frame's, which every screen stream also
1447// carries.
1448thread_local! {
1449 pub(super) static INTRA_IN_INTER_PALETTE_Y_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1450 pub(super) static INTRA_IN_INTER_PALETTE_UV_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1451}
1452
1453// lane-t900 r23: as [`INTRA_IN_INTER_PALETTE_Y_HITS`], narrowed to the 8x8
1454// LEAF site ([`decode_inter_block8`]'s intra arm) -- the >=16 site fires the
1455// shared counter too, so only this one proves a gate really reached the leaf
1456// where the refusal used to sit.
1457thread_local! {
1458 pub(super) static INTER8_PALETTE_HITS: std::cell::Cell<(usize, usize)> =
1459 const { std::cell::Cell::new((0, 0)) };
1460}
1461
1462/// Current values of the 8x8-leaf intra-in-inter palette counters, `(y, uv)`.
1463pub(crate) fn inter8_palette_hits() -> (usize, usize) {
1464 INTER8_PALETTE_HITS.with(std::cell::Cell::get)
1465}
1466
1467/// Current values of the two intra-in-inter palette counters, `(y, uv)`.
1468pub(crate) fn intra_in_inter_palette_hits() -> (usize, usize) {
1469 (
1470 INTRA_IN_INTER_PALETTE_Y_HITS.with(|c| c.get()),
1471 INTRA_IN_INTER_PALETTE_UV_HITS.with(|c| c.get()),
1472 )
1473}
1474
1475// lane-hgkf r2: SKIPPED intra blocks whose `tx_depth` split the luma transform
1476// and which are therefore predicted one transform unit at a time (a skipped
1477// block codes no coefficients, so nothing else in the stream witnesses this
1478// path -- only the pixels do).
1479thread_local! {
1480 pub(super) static SKIP_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1481}
1482
1483/// Current value of [`SKIP_SPLIT_TX_HITS`] (blocks, not units).
1484pub fn skip_split_tx_hits() -> usize {
1485 SKIP_SPLIT_TX_HITS.with(|c| c.get())
1486}
1487
1488// lane-svt1: SKIPPED square blocks carrying a palette/intrabc prediction whose
1489// `tx_depth` split the luma transform -- the arm that predicted DC off the
1490// block edges before the fix. Like [`SKIP_SPLIT_TX_HITS`] only the pixels
1491// witness this path, so a gate that wants it needs the counter.
1492thread_local! {
1493 pub(super) static SKIP_SPLIT_TX_OVERRIDE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1494 /// lane-av1chromadc: chroma units of a skipped block whose intra-BC /
1495 /// UV-palette override had to be WINDOWED to the unit's own extent --
1496 /// i.e. `cn_cols * cn_rows > 1`, which at 4:2:0 never happens (the chroma
1497 /// plane block is one 32x32 unit) and at 4:4:4 is every block of 64 and
1498 /// above. Counts UNITS, not blocks. EXCLUSIVE to this walk: the other two
1499 /// override sites (the luma slot and `decode_intrabc_owned_rect`) have
1500 /// their own windows.
1501 pub(super) static SKIP_CHROMA_OVERRIDE_WINDOW_HITS: std::cell::Cell<usize> =
1502 const { std::cell::Cell::new(0) };
1503}
1504
1505/// Current value of [`SKIP_SPLIT_TX_OVERRIDE_HITS`] (blocks).
1506pub fn skip_split_tx_override_hits() -> usize {
1507 SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.get())
1508}
1509
1510/// lane-av1chromadc: [`SKIP_CHROMA_OVERRIDE_WINDOW_HITS`].
1511#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1512pub fn skip_chroma_override_window_hits() -> usize {
1513 SKIP_CHROMA_OVERRIDE_WINDOW_HITS.with(|c| c.get())
1514}
1515
1516/// Zeroes [`SKIP_CHROMA_OVERRIDE_WINDOW_HITS`] before a gate's own decode.
1517#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1518pub fn reset_skip_chroma_override_window_hits() {
1519 SKIP_CHROMA_OVERRIDE_WINDOW_HITS.with(|c| c.set(0));
1520}
1521
1522/// Zeroes [`SKIP_SPLIT_TX_OVERRIDE_HITS`] before a gate's own decode attempt.
1523pub fn reset_skip_split_tx_override_hits() {
1524 SKIP_SPLIT_TX_OVERRIDE_HITS.with(|c| c.set(0));
1525}
1526
1527// lane-svtinter: palette colour-index maps whose block is cut by the frame's
1528// bottom/right mi edge, so spec 5.11.50's `onscreenWidth`/`onscreenHeight`
1529// really are smaller than the block and FEWER symbols are read than the
1530// block has cells (class map-read-past-frame-edge).
1531thread_local! {
1532 pub(super) static PALETTE_ONSCREEN_CUT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1533}
1534
1535/// Current value of [`PALETTE_ONSCREEN_CUT_HITS`] (colour-index maps).
1536pub fn palette_onscreen_cut_hits() -> usize {
1537 PALETTE_ONSCREEN_CUT_HITS.with(|c| c.get())
1538}
1539
1540/// Zeroes [`PALETTE_ONSCREEN_CUT_HITS`] before a gate's own decode attempt.
1541pub fn reset_palette_onscreen_cut_hits() {
1542 PALETTE_ONSCREEN_CUT_HITS.with(|c| c.set(0));
1543}
1544
1545/// Zeroes [`SKIP_SPLIT_TX_HITS`] before a gate's own decode attempt.
1546pub fn reset_skip_split_tx_hits() {
1547 SKIP_SPLIT_TX_HITS.with(|c| c.set(0));
1548}
1549
1550// lane-intrainter r1: intra blocks inside an INTER frame whose `tx_depth`
1551// symbol split their luma transform, bucketed by block side (8, 16, 32, 64) --
1552// the gate's proof that the lifted path actually ran, per size.
1553thread_local! {
1554 pub(super) static INTRA_IN_INTER_SPLIT_TX_HITS: std::cell::Cell<[usize; 4]> =
1555 const { std::cell::Cell::new([0; 4]) };
1556}
1557
1558/// Current value of [`INTRA_IN_INTER_SPLIT_TX_HITS`], indexed 8/16/32/64.
1559#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1560pub(crate) fn intra_in_inter_split_tx_hits() -> [usize; 4] {
1561 INTRA_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get)
1562}
1563
1564thread_local! {
1565 /// The current frame's `mi` grid, kept only while a frame header set
1566 /// `allow_intrabc` -- an intrabc block's DV predictor is the ordinary
1567 /// MV stack ([`crate::mvstack::find_mv_stack`]) built against
1568 /// `INTRA_FRAME`, which needs the neighbour state a key frame otherwise
1569 /// never keeps. `(grid, mi_cols, mi_rows)`; `None` on every frame that
1570 /// does not allow intrabc (so nothing is paid for it).
1571 ///
1572 /// corner-cut: only [`decode_block`] (the square path) records into it,
1573 /// so a frame mixing intrabc with rect/sub-8x8 leaves would predict off
1574 /// an incomplete grid. Ceiling: the DV *value* (never the parse) would
1575 /// be wrong there; upgrade = record from the rect/leaf paths too.
1576 /// The block vector [`read_intra_mode`] just decoded, handed to
1577 /// [`decode_block`] off the call stack (same idiom as [`PALETTE_PRED`],
1578 /// which the alternative -- a tenth tuple member through every caller --
1579 /// already avoids). Always `.take()`n by the block that reads it.
1580 /// How many blocks read `use_intrabc == 1` and took the DV path -- the
1581 /// gate's hit counter. Bumped on the READ, before the rect-strip refusal
1582 /// returns too, so it counts reads, not reconstructions (a refused block
1583 /// is never reconstructed).
1584 pub(super) static INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1585}
1586
1587/// Zeroes [`RECT_INTRABC_READS`] (gate tests call this before a decode).
1588#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1589pub(crate) fn reset_rect_intrabc_reads() {
1590 RECT_INTRABC_READS.with(|c| c.set(0));
1591}
1592
1593thread_local! {
1594 /// Blocks that USED intrabc at an 8x8 LEAF (`decode_leaf8`) specifically
1595 /// -- the shape lane-kf900 r7 fixed; [`INTRABC_HITS`] counts every shape.
1596 pub(super) static LEAF8_INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1597}
1598
1599thread_local! {
1600 /// Chroma reads of an intrabc TX4-split leaf that consulted an ARMED
1601 /// [`INTRABC_CHROMA_TX`] slot -- proof that the arm's frame-copy +
1602 /// inherited-type route actually ran (lane-av1intrapred r2's non-vacuity
1603 /// counter: zero means the gate's fixture no longer reaches the route).
1604 pub(super) static INTRABC_TX4_CHROMA_COPY_HITS: std::cell::Cell<usize> =
1605 const { std::cell::Cell::new(0) };
1606}
1607
1608/// Current value of [`INTRABC_TX4_CHROMA_COPY_HITS`].
1609#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1610pub(crate) fn intrabc_tx4_chroma_copy_hits() -> usize {
1611 INTRABC_TX4_CHROMA_COPY_HITS.with(|c| c.get())
1612}
1613
1614/// Zeroes [`INTRABC_TX4_CHROMA_COPY_HITS`] (gate tests call this before a decode).
1615#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1616pub(crate) fn reset_intrabc_tx4_chroma_copy_hits() {
1617 INTRABC_TX4_CHROMA_COPY_HITS.with(|c| c.set(0));
1618}
1619
1620/// Current value of [`LEAF8_INTRABC_HITS`].
1621pub(crate) fn leaf8_intrabc_hits() -> usize {
1622 LEAF8_INTRABC_HITS.with(|c| c.get())
1623}
1624
1625/// Zeroes [`LEAF8_INTRABC_HITS`] (gate tests call this before a decode).
1626#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1627pub(crate) fn reset_leaf8_intrabc_hits() {
1628 LEAF8_INTRABC_HITS.with(|c| c.set(0));
1629}
1630
1631/// Current value of [`INTRABC_HITS`].
1632#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1633pub(crate) fn intrabc_hits() -> usize {
1634 INTRABC_HITS.with(|c| c.get())
1635}
1636
1637thread_local! {
1638 /// An intrabc block that IS a sub-8x8 group's CHROMA REFERENCE and is
1639 /// SKIPPED: the route that arms [`INTRABC_CHROMA_TX`] and then reads no
1640 /// chroma coefficient at all, so the slot used to stay armed into the NEXT
1641 /// block's chroma read. Both group shapes (4x4 split, 4x8/8x4 rect) count
1642 /// here. A non-zero value is what makes the disarm below load-bearing.
1643 pub(super) static SKIPPED_INTRABC_CHROMA_ARM_HITS: std::cell::Cell<usize> =
1644 const { std::cell::Cell::new(0) };
1645}
1646
1647/// Current value of [`SKIPPED_INTRABC_CHROMA_ARM_HITS`].
1648#[allow(dead_code)] // read only from the `#[cfg(test)]` gates and the probe
1649pub(crate) fn skipped_intrabc_chroma_arm_hits() -> usize {
1650 SKIPPED_INTRABC_CHROMA_ARM_HITS.with(|c| c.get())
1651}
1652
1653/// Zeroes [`SKIPPED_INTRABC_CHROMA_ARM_HITS`] (gate tests call this before a
1654/// decode).
1655#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1656pub(crate) fn reset_skipped_intrabc_chroma_arm_hits() {
1657 SKIPPED_INTRABC_CHROMA_ARM_HITS.with(|c| c.set(0));
1658}
1659
1660thread_local! {
1661 /// lane-av1-ibcskip2: a sub-8x8 4:4:4 leaf that is BOTH intrabc AND
1662 /// `skip` -- the arm whose chroma is the bare frame copy at the DV
1663 /// (libaom `av1_build_inter_predictors_sb` runs regardless of `skip`).
1664 /// Before the fix this route predicted intra-DC and every one of this
1665 /// fixture's 150 such cells differed from the oracle on both chroma
1666 /// planes.
1667 pub(super) static SKIPPED_INTRABC_DV_COPY_HITS: std::cell::Cell<usize> =
1668 const { std::cell::Cell::new(0) };
1669}
1670
1671/// Current value of [`SKIPPED_INTRABC_DV_COPY_HITS`].
1672#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1673pub(crate) fn skipped_intrabc_dv_copy_hits() -> usize {
1674 SKIPPED_INTRABC_DV_COPY_HITS.with(|c| c.get())
1675}
1676
1677/// Zeroes [`SKIPPED_INTRABC_DV_COPY_HITS`] (gate tests call this before a
1678/// decode).
1679#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1680pub(crate) fn reset_skipped_intrabc_dv_copy_hits() {
1681 SKIPPED_INTRABC_DV_COPY_HITS.with(|c| c.set(0));
1682}
1683
1684/// Zeroes [`INTRABC_HITS`] (gate tests call this before a decode).
1685#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1686pub(crate) fn reset_intrabc_hits() {
1687 INTRABC_HITS.with(|c| c.set(0));
1688}
1689
1690thread_local! {
1691 /// lane-t900 r32: intrabc blocks whose transform size came off the INTER
1692 /// var-tx partition tree (unskipped, `TX_MODE_SELECT`) -- the capability
1693 /// that replaced the refusal "an intrabc block under TxMode::Select".
1694 pub(super) static INTRABC_VARTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1695 /// lane-av1-ibcvtx: intrabc var-tx trees that resolved to MIXED leaf
1696 /// sizes (not one square size across every leaf) -- the engagement
1697 /// counter proving a witness actually exercises the per-leaf reconstruct.
1698 pub(super) static INTRABC_VARTX_MIXED_LEAVES_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1699 /// lane-av1txr: as above for a `BLOCK_4X8`/`BLOCK_8X4` intrabc leaf --
1700 /// libaom's `block_signals_txsize` is `bsize > BLOCK_4X4`, so these leaves
1701 /// signal a transform size where a plain `BLOCK_4X4` does not. Reading no
1702 /// symbol here desynced `warped.obu` at the very next block.
1703 pub(super) static RECT_INTRABC_VARTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1704 /// lane-av1-intrabc: rect INTRABC blocks whose reconstruction
1705 /// [`decode_intrabc_rect`] ran -- the engagement counter the rect-strip
1706 /// gates assert on (a refused block bumps [`INTRABC_HITS`] but never
1707 /// this one).
1708 pub(super) static INTRABC_RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1709 /// Of those, how many read the INTER var-tx tree (unskipped, TX_MODE_SELECT).
1710 pub(super) static INTRABC_RECT_VARTX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1711 /// lane-av1-intrabc r4: rect INTRABC blocks whose reconstruction
1712 /// [`decode_intrabc_rect`] ran with `skip == 0` (a real residual read),
1713 /// split by the strip's orientation -- `bw > bh` is a HORZ strip,
1714 /// `bh > bw` a VERT one. The reviewer's unblock condition needs a CODED
1715 /// witness in BOTH orientations, and the existing `INTRABC_RECT_HITS`
1716 /// counts neither orientation nor the skip flag, so an arm that flipped
1717 /// to an all-skip stream (no residual reader at all) would stay green.
1718 pub(super) static INTRABC_RECT_CODED_HITS: std::cell::Cell<[usize; 2]> =
1719 const { std::cell::Cell::new([0, 0]) };
1720 /// lane-av1-intrabc r5: the `skip == 1` twin of [`INTRABC_RECT_CODED_HITS`]
1721 /// -- rect INTRABC blocks reconstructed as a bare prediction copy, split
1722 /// by orientation. The r5 panic (residual stride `bw * bh` underrunning
1723 /// `reconstruct_mc_rect`'s `row * side + w` index on a VERT strip) was
1724 /// invisible to every gate because they only counted CODED strips.
1725 pub(super) static INTRABC_RECT_SKIPPED_HITS: std::cell::Cell<[usize; 2]> =
1726 const { std::cell::Cell::new([0, 0]) };
1727 /// lane-ibc444c: rect intra-BC blocks whose chroma plane block was sized
1728 /// `bw >> ss_x` by `bh >> ss_y` -- the 4:4:4 and 4:4:0 cells, where
1729 /// `av1_get_max_uv_txsize` (`ss_size_lookup[bsize]`, blockd.h) applies no
1730 /// halving of its own. At 4:2:0 this is the same arithmetic as the halving,
1731 /// so a `>= 1` witness can only come from a stream that is not 4:2:0.
1732 /// EXCLUSIVE to this arm: no other caller sizes an intrabc rect block's
1733 /// chroma plane block.
1734 pub(super) static IBC_RECT_CHROMA_FOOTPRINT_444_HITS: std::cell::Cell<usize> =
1735 const { std::cell::Cell::new(0) };
1736 /// lane-whtshape: LOSSLESS rect intrabc blocks whose chroma plane block
1737 /// [`decode_intrabc_rect`] walked as a `(cw/4) * (ch/4)` PLANE-MAJOR
1738 /// raster of TX_4X4 units -- the shape libaom's lossless geometry codes
1739 /// (`read_tx_size` returns `TX_4X4` for EVERY plane of a lossless block,
1740 /// `get_vartx_max_txsize` likewise, and `read_tx_mode` forced the frame's
1741 /// `ONLY_4X4`) -- instead of the single rect unit, which is what put a
1742 /// non-4x4 unit on the lossless Walsh-Hadamard path. EXCLUSIVE to this arm:
1743 /// no other caller walks a rect intrabc block's chroma, so `>= 1` cannot
1744 /// be satisfied by any older route.
1745 pub(super) static INTRABC_RECT_LOSSLESS_CHROMA4_HITS: std::cell::Cell<usize> =
1746 const { std::cell::Cell::new(0) };
1747 /// lane-av1chromarect: 128-root intra-BC HORZ/VERT strips
1748 /// ([`decode_intrabc_owned_rect`]) whose chroma plane block was sized
1749 /// `bw >> ss_x` by `bh >> ss_y` -- the 4:4:4 and 4:4:0 cells, where
1750 /// `av1_get_max_uv_txsize` (`ss_size_lookup[bsize]`, blockd.h:1372) applies
1751 /// no halving of its own. At 4:2:0 the two forms are the same arithmetic,
1752 /// so a `>= 1` witness can only come from a stream that is not 4:2:0.
1753 /// EXCLUSIVE to this arm: no other caller sizes a 128-root intra-BC
1754 /// strip's chroma plane block.
1755 pub(super) static IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS: std::cell::Cell<usize> =
1756 const { std::cell::Cell::new(0) };
1757 /// lane-av1422ibctxsel: `decode_intrabc_owned_rect`'s NON-SPLIT chroma
1758 /// gather taken through the 4:2:2 pair rule (`around_mi_422_chroma`)
1759 /// under the ss (1, 0) guard -- both residual branches (the var-tx tree
1760 /// and the no-leaves twin). `>= 1` can only come from a 4:2:2 stream
1761 /// that reaches this function's non-split chroma arm; the 4:2:0/4:4:4
1762 /// arms keep the plain `around_mi_rect` gather (`ss_y != 0` / `ss_x == 0`
1763 /// take the else), so the counter stays 0 for them.
1764 pub(super) static IBC_OWNED_RECT_422_PAIR_HITS: std::cell::Cell<usize> =
1765 const { std::cell::Cell::new(0) };
1766}
1767
1768/// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed,
1769/// as `[horz, vert]` -- see [`INTRABC_RECT_CODED_HITS`].
1770#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1771pub fn intrabc_rect_coded_hits() -> [usize; 2] {
1772 INTRABC_RECT_CODED_HITS.with(std::cell::Cell::get)
1773}
1774
1775/// lane-av1-intrabc r5: skipped (`skip == 1`) rect intrabc blocks
1776/// reconstructed, as `[horz, vert]` -- see [`INTRABC_RECT_SKIPPED_HITS`].
1777#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1778pub fn intrabc_rect_skipped_hits() -> [usize; 2] {
1779 INTRABC_RECT_SKIPPED_HITS.with(std::cell::Cell::get)
1780}
1781
1782/// Current value of [`INTRABC_RECT_HITS`].
1783#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1784pub fn intrabc_rect_hits() -> usize {
1785 INTRABC_RECT_HITS.with(|c| c.get())
1786}
1787
1788/// Zeroes [`INTRABC_RECT_HITS`]/[`INTRABC_RECT_VARTX_HITS`].
1789#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1790pub(crate) fn reset_intrabc_rect_hits() {
1791 INTRABC_RECT_HITS.with(|c| c.set(0));
1792 INTRABC_RECT_VARTX_HITS.with(|c| c.set(0));
1793 INTRABC_RECT_CODED_HITS.with(|c| c.set([0, 0]));
1794 INTRABC_RECT_SKIPPED_HITS.with(|c| c.set([0, 0]));
1795}
1796
1797/// lane-ibc444c: [`IBC_RECT_CHROMA_FOOTPRINT_444_HITS`].
1798#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1799pub fn ibc_rect_chroma_footprint_444_hits() -> usize {
1800 IBC_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.get())
1801}
1802
1803/// lane-ibc444c: zeroes [`IBC_RECT_CHROMA_FOOTPRINT_444_HITS`].
1804#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1805pub(crate) fn reset_ibc_rect_chroma_footprint_444_hits() {
1806 IBC_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0));
1807}
1808
1809/// lane-av1chromarect: [`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS`].
1810#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1811pub fn ibc_owned_rect_chroma_footprint_444_hits() -> usize {
1812 IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.get())
1813}
1814
1815/// lane-av1chromarect: zeroes [`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS`].
1816#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1817pub(crate) fn reset_ibc_owned_rect_chroma_footprint_444_hits() {
1818 IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0));
1819}
1820
1821/// lane-av1422ibctxsel: [`IBC_OWNED_RECT_422_PAIR_HITS`].
1822#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1823pub fn ibc_owned_rect_422_pair_hits() -> usize {
1824 IBC_OWNED_RECT_422_PAIR_HITS.with(|c| c.get())
1825}
1826
1827/// lane-av1422ibctxsel: zeroes [`IBC_OWNED_RECT_422_PAIR_HITS`].
1828#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1829pub(crate) fn reset_ibc_owned_rect_422_pair_hits() {
1830 IBC_OWNED_RECT_422_PAIR_HITS.with(|c| c.set(0));
1831}
1832
1833/// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`].
1834#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1835pub fn intrabc_rect_lossless_chroma4_hits() -> usize {
1836 INTRABC_RECT_LOSSLESS_CHROMA4_HITS.with(|c| c.get())
1837}
1838
1839/// lane-whtshape: zeroes [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`].
1840#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1841pub(crate) fn reset_intrabc_rect_lossless_chroma4_hits() {
1842 INTRABC_RECT_LOSSLESS_CHROMA4_HITS.with(|c| c.set(0));
1843}
1844
1845/// Current value of [`INTRABC_RECT_VARTX_HITS`].
1846#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1847pub fn intrabc_rect_vartx_hits() -> usize {
1848 INTRABC_RECT_VARTX_HITS.with(|c| c.get())
1849}
1850
1851thread_local! {
1852 /// lane-av1-ibcrect: `use_intrabc` blocks on a 128-root HORZ/VERT strip
1853 /// (BLOCK_128X64 / BLOCK_64X128) whose reconstruction
1854 /// [`decode_intrabc_128rect`] ran -- the shape the named refusal used to
1855 /// guard (`decode_block_128rect`). A refused block bumps
1856 /// [`INTRABC_HITS`] but never this one.
1857 pub(super) static INTRABC_128RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1858 /// lane-av1-ibc128chunk: chroma transform units the 128-root intrabc
1859 /// strip's mu-chunk walk read, one per `read_inter_plane` chroma call.
1860 /// At 4:2:0 a 64x64 mu chunk's chroma plane block is 32x32, so one
1861 /// TX_32X32 per plane per chunk; at 4:2:2 it is 32x64 and holds TWO
1862 /// STACKED units per plane. The square-cut `chunk_chroma = cside * 64 /
1863 /// side` model walked the 4:2:0 count on every axis, so this counter is
1864 /// the reach/arm witness for the per-axis walk.
1865 pub(super) static INTRABC_128RECT_CHROMA_CHUNK_HITS: std::cell::Cell<usize> =
1866 const { std::cell::Cell::new(0) };
1867}
1868
1869/// Current value of [`INTRABC_128RECT_HITS`].
1870#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1871pub fn intrabc_128rect_hits() -> usize {
1872 INTRABC_128RECT_HITS.with(|c| c.get())
1873}
1874
1875/// Zeroes [`INTRABC_128RECT_HITS`].
1876#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1877pub(crate) fn reset_intrabc_128rect_hits() {
1878 INTRABC_128RECT_HITS.with(|c| c.set(0));
1879}
1880
1881/// Current value of [`INTRABC_128RECT_CHROMA_CHUNK_HITS`].
1882#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1883pub fn intrabc_128rect_chroma_chunk_hits() -> usize {
1884 INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.get())
1885}
1886
1887/// Zeroes [`INTRABC_128RECT_CHROMA_CHUNK_HITS`] and
1888/// [`INTRABC_128RECT_CHUNK_SHAPE`].
1889#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1890pub(crate) fn reset_intrabc_128rect_chroma_chunk_hits() {
1891 INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.set(0));
1892 INTRABC_128RECT_CHUNK_SHAPE.with(|c| c.set(0));
1893}
1894
1895/// Current value of [`INTRABC_VARTX_HITS`].
1896pub fn intrabc_vartx_hits() -> usize {
1897 INTRABC_VARTX_HITS.with(|c| c.get())
1898}
1899
1900/// Current value of [`INTRABC_VARTX_MIXED_LEAVES_HITS`].
1901pub fn intrabc_vartx_mixed_leaves_hits() -> usize {
1902 INTRABC_VARTX_MIXED_LEAVES_HITS.with(|c| c.get())
1903}
1904
1905/// Zeroes [`INTRABC_VARTX_HITS`] (gate tests call this before a decode).
1906#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1907pub(crate) fn reset_intrabc_vartx_hits() {
1908 INTRABC_VARTX_HITS.with(|c| c.set(0));
1909}
1910
1911/// Zeroes [`INTRABC_VARTX_MIXED_LEAVES_HITS`] (gate tests call this before a
1912/// decode).
1913#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1914pub(crate) fn reset_intrabc_vartx_mixed_leaves_hits() {
1915 INTRABC_VARTX_MIXED_LEAVES_HITS.with(|c| c.set(0));
1916}
1917
1918/// Current value of [`RECT_INTRABC_VARTX_HITS`].
1919#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1920pub fn rect_intrabc_vartx_hits() -> usize {
1921 RECT_INTRABC_VARTX_HITS.with(|c| c.get())
1922}
1923
1924// How many blocks decoded `skip_mode == 1` (lane-av1comp round 14) --
1925// proves a real `skip_mode_present` stream actually reached a block that
1926// picked it, not just that the frame header bit was set.
1927thread_local! {
1928 pub(super) static SKIP_MODE_HITS: std::cell::Cell<usize> =
1929 const { std::cell::Cell::new(0) };
1930}
1931
1932/// Current value of [`SKIP_MODE_HITS`].
1933#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1934pub(crate) fn skip_mode_hits() -> usize {
1935 SKIP_MODE_HITS.with(|c| c.get())
1936}
1937
1938// lane-motionmode: how many blocks actually decoded `obmc_selected == true`
1939// (as opposed to just reaching an eligible `read_motion_mode` symbol read)
1940// -- the gate's own proof that a real aomenc `--enable-obmc=1` stream
1941// reached [`obmc_blend`], not just the header bit.
1942thread_local! {
1943 pub(super) static OBMC_HITS: std::cell::Cell<usize> =
1944 const { std::cell::Cell::new(0) };
1945}
1946
1947// lane-fimv r1 (class wrong-alphabet-same-value): how many blocks took the
1948// 2-symbol `obmc_cdf` alphabet *because* `force_integer_mv` (or a scaled
1949// reference) vetoed `WARPED_CAUSAL` in libaom `motion_mode_allowed`, while
1950// `allow_warped_motion == 1` and `num_proj_ref >= 1` would otherwise have
1951// picked the 3-symbol `motion_mode_cdf`. These are exactly the blocks this
1952// decoder used to read with the wrong alphabet, so a gate that asserts this
1953// counter advanced proves the fixed path fired (class
1954// `gate-blind-to-feature`).
1955thread_local! {
1956 pub(super) static FIMV_ALPHABET_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1957}
1958
1959/// Current value of [`FIMV_ALPHABET_HITS`].
1960pub fn fimv_alphabet_hits() -> usize {
1961 FIMV_ALPHABET_HITS.with(|c| c.get())
1962}
1963
1964// lane-fimv r1: how many frame headers this decoder has decoded with
1965// `force_integer_mv == 1` (bumped by `stream.rs` per frame). Lets a gate
1966// prove the encoder really produced the header state under test rather than
1967// assume it.
1968thread_local! {
1969 pub(super) static FIMV_FRAME_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1970}
1971
1972/// Current value of [`FIMV_FRAME_HITS`].
1973pub fn fimv_frame_hits() -> usize {
1974 FIMV_FRAME_HITS.with(|c| c.get())
1975}
1976
1977/// Current value of [`OBMC_HITS`].
1978#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
1979pub(crate) fn obmc_hits() -> usize {
1980 OBMC_HITS.with(|c| c.get())
1981}
1982
1983// lane-scaledref r1: per-case firing counts for the scaled-reference gate
1984// (class `gate-blind-to-feature`) -- a pixel match under an UNSCALED
1985// reference would pass just as well and prove nothing, so the gate
1986// hard-asserts each combination this round lifts actually occurred:
1987// a compound block with a scaled tap, a warp block whose warp libaom
1988// suppresses because the reference is scaled, an OBMC block, an interintra
1989// block, and an 8x8 leaf.
1990thread_local! {
1991 pub(super) static SCALED_COMPOUND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1992 pub(super) static SCALED_WARP_FALLBACK_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1993 pub(super) static SCALED_OBMC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1994 pub(super) static SCALED_INTERINTRA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1995 pub(super) static SCALED_BLOCK8_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1996 pub(super) static SCALED_WARP_SUPPRESSED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1997 pub(super) static MIXED_SCALE_COMPOUND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1998}
1999
2000/// Current value of [`MIXED_SCALE_COMPOUND_HITS`]: compound blocks with one
2001/// scaled and one unscaled tap.
2002#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2003pub(crate) fn mixed_scale_compound_hits() -> usize {
2004 MIXED_SCALE_COMPOUND_HITS.with(|c| c.get())
2005}
2006
2007/// Current value of [`SCALED_WARP_SUPPRESSED_HITS`]: blocks that would have
2008/// read the 3-symbol `motion_mode_cdf` but read the 2-symbol `obmc_cdf`
2009/// instead because their reference is scaled (libaom `motion_mode_allowed`,
2010/// `blockd.h:1484`).
2011#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2012pub(crate) fn scaled_warp_suppressed_hits() -> usize {
2013 SCALED_WARP_SUPPRESSED_HITS.with(|c| c.get())
2014}
2015
2016/// Current value of [`SCALED_COMPOUND_HITS`].
2017#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2018pub(crate) fn scaled_compound_hits() -> usize {
2019 SCALED_COMPOUND_HITS.with(|c| c.get())
2020}
2021
2022/// Current value of [`SCALED_WARP_FALLBACK_HITS`].
2023pub fn scaled_warp_fallback_hits() -> usize {
2024 SCALED_WARP_FALLBACK_HITS.with(|c| c.get())
2025}
2026
2027/// Current value of [`SCALED_OBMC_HITS`].
2028#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2029pub(crate) fn scaled_obmc_hits() -> usize {
2030 SCALED_OBMC_HITS.with(|c| c.get())
2031}
2032
2033/// Current value of [`SCALED_INTERINTRA_HITS`].
2034#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2035pub(crate) fn scaled_interintra_hits() -> usize {
2036 SCALED_INTERINTRA_HITS.with(|c| c.get())
2037}
2038
2039/// Current value of [`SCALED_BLOCK8_HITS`].
2040#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2041pub(crate) fn scaled_block8_hits() -> usize {
2042 SCALED_BLOCK8_HITS.with(|c| c.get())
2043}
2044
2045// lane-motionmode round 3: same proof as [`OBMC_HITS`], narrowed to
2046// `decode_inter_block8`'s own 8x8-leaf `read_motion_mode` -- a subset of
2047// [`OBMC_HITS`] (both fire together on an 8x8 hit), lets the gate tell an
2048// 8x8-leaf OBMC block apart from a 16x16+ one.
2049thread_local! {
2050 pub(super) static OBMC_HITS_8: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2051}
2052
2053// lane-interp3 r1: how many inter blocks read a SWITCHABLE `interp_filter`
2054// pair whose two directions differ (`enable_dual_filter` only -- with dual
2055// filter off both directions take the single symbol, so this can never fire).
2056// A gate asserting it proves the stream really carries dual-filter blocks.
2057thread_local! {
2058 pub(super) static DUAL_FILTER_DIFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2059}
2060
2061// lane-interp3 r1: how many COMPOUND 8x8 leaves read their own
2062// `read_mb_interp_filter` symbol(s) -- the read this round added (the leaf
2063// used to skip it entirely, losing a symbol and stamping the `[3, 3]`
2064// no-filter sentinel that made a neighbouring OBMC block panic).
2065thread_local! {
2066 pub(super) static COMPOUND8_FILTER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2067}
2068
2069/// Current value of [`DUAL_FILTER_DIFF_HITS`].
2070#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2071pub(crate) fn dual_filter_diff_hits() -> usize {
2072 DUAL_FILTER_DIFF_HITS.with(|c| c.get())
2073}
2074
2075/// Current value of [`COMPOUND8_FILTER_HITS`].
2076#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2077pub(crate) fn compound8_filter_hits() -> usize {
2078 COMPOUND8_FILTER_HITS.with(|c| c.get())
2079}
2080
2081// lane-warp round 1: how many blocks resolved `motion_mode_allowed` to
2082// `WARPED_CAUSAL`-eligible (3-symbol read, `num_proj_ref >= 1` under
2083// `allow_warped_motion`) AND the symbol actually decoded to `WARPED_CAUSAL`
2084// -- the gate's proof that a fixture really exercises the alphabet this
2085// round changed, even though the block itself still refuses (warp
2086// estimation/filter not ported).
2087thread_local! {
2088 pub(super) static WARP_SELECTED_HITS: std::cell::Cell<usize> =
2089 const { std::cell::Cell::new(0) };
2090}
2091
2092/// Current value of [`WARP_SELECTED_HITS`].
2093#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2094pub(crate) fn warp_selected_hits() -> usize {
2095 WARP_SELECTED_HITS.with(|c| c.get())
2096}
2097
2098// lane-cwarp r1: how many COMPOUND_REFERENCE blocks had at least one
2099// reference predicted through the per-ref GLOBAL warp (`av1_warp_plane`
2100// into the compound intermediate) rather than translationally -- the
2101// gate's proof that a `GLOBAL_GLOBALMV` block under a ROTZOOM/AFFINE model
2102// really reached [`crate::warp::warp_affine_compound`].
2103// lane-av1422warp: the 4:2:2 coverage witness has to show compound and warped
2104// motion firing ABOVE the vertical midpoint, and every pre-existing warp
2105// counter is frame-global. These two are the same arms restricted to blocks
2106// whose top mode-info row is in the frame's upper half, which is the half
2107// this lane's evidence covers.
2108thread_local! {
2109 pub(super) static TOP_HALF_COMPOUND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2110 pub(super) static TOP_HALF_WARP_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2111}
2112
2113/// How many `GLOBAL_GLOBALMV` (compound) inter blocks decoded in the frame's
2114/// upper half -- the block's top mode-info row is under `mi_rows / 2`.
2115///
2116/// NO COMMITTED TEST READS THIS, and none can while the 4:2:2 header refusal
2117/// stands: the pinned 4:2:2 coverage gate asserts the byte pin and the
2118/// refusal by name, so nothing in the suite ever decodes a 4:2:2 stream.
2119/// The figure quoted for that fixture comes from a patch-run-restore build
2120/// with the `EC_AV1_ALLOW_422_PROBE` bypass applied and then reverted, which
2121/// is the same discipline every 4:2:2 lane in this family uses.
2122#[allow(dead_code)]
2123pub(crate) fn top_half_compound_hits() -> usize {
2124 TOP_HALF_COMPOUND_HITS.with(std::cell::Cell::get)
2125}
2126
2127/// How many inter blocks in the frame's upper half satisfy libaom's
2128/// `is_global_mv_block` on at least one reference slot -- mode
2129/// `GLOBAL_GLOBALMV` AND block >= 8x8 AND that slot's own global-motion
2130/// model > `TRANSLATION`. This is the block set whose prediction goes
2131/// through `crate::warp`, and it is exactly `is_global_mv0 || is_global_mv1`
2132/// as computed at the increment site; it is NOT merely "some slot has a
2133/// non-TRANSLATION model", which also counts blocks that are not global-mv
2134/// blocks.
2135///
2136/// Like [`top_half_compound_hits`], no committed test reads it: with the
2137/// 4:2:2 header refusal in force nothing in the suite decodes the stream
2138/// these numbers describe.
2139#[allow(dead_code)]
2140pub(crate) fn top_half_warp_hits() -> usize {
2141 TOP_HALF_WARP_HITS.with(std::cell::Cell::get)
2142}
2143
2144thread_local! {
2145 pub(super) static COMPOUND_WARP_HITS: std::cell::Cell<usize> =
2146 const { std::cell::Cell::new(0) };
2147}
2148
2149/// Current value of [`COMPOUND_WARP_HITS`].
2150#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2151pub(crate) fn compound_warp_hits() -> usize {
2152 COMPOUND_WARP_HITS.with(|c| c.get())
2153}
2154
2155// lane-interp3 r3: the same proof narrowed to the 8x8 LEAF's own compound
2156// arm ([`decode_inter_block8`]) -- that arm predicted both taps
2157// translationally until r3, so a gate needs to tell a warped 8x8 compound
2158// leaf apart from a warped 16x16+ one (both bump [`COMPOUND_WARP_HITS`]).
2159thread_local! {
2160 pub(super) static COMPOUND_WARP_HITS_8: std::cell::Cell<usize> =
2161 const { std::cell::Cell::new(0) };
2162}
2163
2164/// Current value of [`COMPOUND_WARP_HITS_8`].
2165#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2166pub(crate) fn compound_warp_hits_8() -> usize {
2167 COMPOUND_WARP_HITS_8.with(|c| c.get())
2168}
2169
2170// lane-gmaffine r1: how many blocks built their prediction from a
2171// SIX-parameter (`AFFINE`) global-motion model through
2172// `crate::warp::global_warp_params` -- the gate's proof that a stream really
2173// carried an AFFINE `global_motion_params` AND that a block was predicted
2174// with it, not merely that the header parsed one.
2175thread_local! {
2176 pub(super) static AFFINE_GM_HITS: std::cell::Cell<usize> =
2177 const { std::cell::Cell::new(0) };
2178}
2179
2180/// Current value of [`AFFINE_GM_HITS`].
2181#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2182pub(crate) fn affine_gm_hits() -> usize {
2183 AFFINE_GM_HITS.with(|c| c.get())
2184}
2185
2186// lane-av1distwtd: how many blocks took the DISTANCE-WEIGHTED compound
2187// combine rather than the simple average -- `compound_idx == 0` under
2188// `enable_jnt_comp`, whose weights come from
2189// [`crate::compound::dist_wtd_comp_weight_assign`] instead of the constant
2190// `(8, 8)` split. Counting the `idx == 0` arm (not merely the
2191// `compound_idx` symbol read) is what makes this a witness of the TOOL: a
2192// stream that carries `enable_jnt_comp = true` in its sequence header but
2193// codes every compound block with `compound_idx == 1` leaves this at 0 and
2194// decoded identically without the whole distance-weight path.
2195thread_local! {
2196 pub(super) static DIST_WTD_COMP_HITS: std::cell::Cell<usize> =
2197 const { std::cell::Cell::new(0) };
2198}
2199
2200/// Current value of [`DIST_WTD_COMP_HITS`].
2201#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2202pub(crate) fn dist_wtd_comp_hits() -> usize {
2203 DIST_WTD_COMP_HITS.with(|c| c.get())
2204}
2205
2206/// Resets [`DIST_WTD_COMP_HITS`] to 0.
2207#[allow(dead_code)] // test-only
2208pub(crate) fn reset_dist_wtd_comp_hits() {
2209 DIST_WTD_COMP_HITS.with(|c| c.set(0));
2210}
2211
2212// lane-av1gwarp12: how many 16x16+ blocks built their SINGLE-reference
2213// prediction through `crate::warp::global_warp_params` with a FOUR-parameter
2214// (`ROTZOOM`) model. Vanilla aomenc pins its global-motion search to ROTZOOM
2215// (`global_motion_facade.c:24`), so this is the only >TRANSLATION single-ref
2216// global-warp arm a real aomenc stream can reach (AFFINE needs the widened
2217// side build and its own counter, [`AFFINE_GM_HITS`]).
2218thread_local! {
2219 pub(super) static ROTZOOM_GM_WARP_HITS: std::cell::Cell<usize> =
2220 const { std::cell::Cell::new(0) };
2221}
2222
2223/// Current value of [`ROTZOOM_GM_WARP_HITS`].
2224#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2225pub(crate) fn rotzoom_gm_warp_hits() -> usize {
2226 ROTZOOM_GM_WARP_HITS.with(|c| c.get())
2227}
2228
2229// lane-t900 r9: rect blocks whose warp-sample top-right probe answers
2230// differently at the block's WIDTH than at libaom's
2231// `AOMMAX(xd->width, xd->height)` -- each one is a `num_proj_ref` that could
2232// pick the wrong motion_mode alphabet.
2233thread_local! {
2234 pub(super) static TR_REACH_LONGER_SIDE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2235}
2236
2237/// Current value of [`TR_REACH_LONGER_SIDE_HITS`].
2238pub fn tr_reach_longer_side_hits() -> usize {
2239 TR_REACH_LONGER_SIDE_HITS.with(std::cell::Cell::get)
2240}
2241
2242// lane-t900 r9: libaom `is_nontrans_global_motion` (mvref_common.h) returns 0
2243// for `AOMMIN(mi_size_wide[bsize], mi_size_high[bsize]) < 2`, i.e. any block
2244// with a 4-px side is NEVER "non-translational global" and therefore ALWAYS
2245// reads its interp-filter symbol. Counts the blocks where that guard flips
2246// our answer -- a GLOBALMV/GLOBAL_GLOBALMV block with a non-TRANSLATION model
2247// and a 4-px side, which we used to suppress the interp read on (a pre-mode
2248// entropy desync one symbol wide).
2249thread_local! {
2250 pub(super) static GM_NONTRANS_SMALL_SIDE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2251}
2252
2253/// Current value of [`GM_NONTRANS_SMALL_SIDE_HITS`].
2254pub fn gm_nontrans_small_side_hits() -> usize {
2255 GM_NONTRANS_SMALL_SIDE_HITS.with(std::cell::Cell::get)
2256}
2257
2258// lane-gmaffine r1: 8x8-leaf-only counters -- how many `BLOCK_8X8` leaves
2259// coded `GLOBALMV` (`GLOBALMV_HITS_8`) and how many built a real
2260// `WARPED_CAUSAL` local-warp prediction there (`WARP_HITS_8`, incremented
2261// only once `find_projection` returned a usable model, unlike
2262// `WARP_SELECTED_HITS` which counts the symbol). Both are the 8x8 gates'
2263// proof that the leaf path itself fired, not the 16x16+ one.
2264thread_local! {
2265 pub(super) static GLOBALMV_HITS_8: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2266 pub(super) static WARP_HITS_8: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2267}
2268
2269/// Current value of [`GLOBALMV_HITS_8`].
2270#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2271pub(crate) fn globalmv_hits_8() -> usize {
2272 GLOBALMV_HITS_8.with(|c| c.get())
2273}
2274
2275/// Current value of [`WARP_HITS_8`].
2276#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2277pub(crate) fn warp_hits_8() -> usize {
2278 WARP_HITS_8.with(|c| c.get())
2279}
2280
2281// How many blocks decoded `interintra == 1` with the non-wedge blended
2282// prediction applied (lane-interintra r1) -- the gate's proof that a
2283// stream actually exercised interintra.
2284thread_local! {
2285 pub(super) static INTERINTRA_HITS: std::cell::Cell<usize> =
2286 const { std::cell::Cell::new(0) };
2287}
2288
2289/// Current value of [`INTERINTRA_HITS`].
2290#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2291pub(crate) fn interintra_hits() -> usize {
2292 INTERINTRA_HITS.with(|c| c.get())
2293}
2294
2295// lane-midcut r1: of those, how many were RECTANGULAR (`write_w != write_h`)
2296// -- the shape `interintra_blend` used to build a square `side x side` intra
2297// predictor for, with `ii_size_scales`/`edges` taken at the square. Every
2298// pre-existing interintra gate passed with that bug, so the rect arm needs
2299// its own counter to stop being vacuous.
2300thread_local! {
2301 pub(super) static INTERINTRA_RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2302}
2303
2304/// Current value of [`INTERINTRA_RECT_HITS`].
2305pub fn interintra_rect_hits() -> usize {
2306 INTERINTRA_RECT_HITS.with(|c| c.get())
2307}
2308
2309// How many blocks decoded `comp_group_idx == 1` (masked COMPOUND_REFERENCE,
2310// wedge or diffwtd) and had `compound_type`/`wedge_idx`/`wedge_sign`/
2311// `mask_type` consumed entropy-exact -- lane-maskcomp r1's proof that a
2312// gate fixture actually exercises this alphabet, even though the block
2313// still refuses (the mask blend itself is unported).
2314thread_local! {
2315 pub(super) static MASKED_COMPOUND_HITS: std::cell::Cell<usize> =
2316 const { std::cell::Cell::new(0) };
2317}
2318
2319/// Current value of [`MASKED_COMPOUND_HITS`].
2320#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2321pub(crate) fn masked_compound_hits() -> usize {
2322 MASKED_COMPOUND_HITS.with(|c| c.get())
2323}
2324
2325// lane-intersub8 r4/r5: the NON-SQUARE half of `MASKED_COMPOUND_HITS` -- a
2326// masked-compound block whose true footprint is rectangular, i.e. the case
2327// whose `compound_type`/`wedge_idx` CDF row r4 fixed (it used to read the
2328// square envelope's `BLOCK_SIZES_ALL` index). Square blocks cannot show that
2329// defect, so a gate asserting `masked_compound_hits` alone stays vacuous for it.
2330thread_local! {
2331 pub(super) static RECT_MASKED_COMPOUND_HITS: std::cell::Cell<usize> =
2332 const { std::cell::Cell::new(0) };
2333}
2334
2335/// Current value of [`RECT_MASKED_COMPOUND_HITS`].
2336#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2337pub(crate) fn rect_masked_compound_hits() -> usize {
2338 RECT_MASKED_COMPOUND_HITS.with(|c| c.get())
2339}
2340
2341// How many blocks decoded a real `COMPOUND_WEDGE` block (`comp_group_idx ==
2342// 1`, `compound_type == 0`) -- lane-wedge r3's proof a gate fixture
2343// actually exercised the wedge blend, not just the DIFFWTD half of
2344// `MASKED_COMPOUND_HITS`.
2345thread_local! {
2346 pub(super) static WEDGE_HITS: std::cell::Cell<usize> =
2347 const { std::cell::Cell::new(0) };
2348}
2349
2350/// Current value of [`WEDGE_HITS`].
2351#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2352pub(crate) fn wedge_hits() -> usize {
2353 WEDGE_HITS.with(|c| c.get())
2354}
2355
2356// How many blocks decoded a real wedge-INTERINTRA block
2357// (`interintra == 1 && use_wedge_interintra == 1`) -- lane-wii r2's proof
2358// a gate fixture exercised the wedge blend (fixed sign 0), not just the
2359// smooth arm counted by `INTERINTRA_HITS`.
2360thread_local! {
2361 pub(super) static WII_HITS: std::cell::Cell<usize> =
2362 const { std::cell::Cell::new(0) };
2363}
2364
2365/// Current value of [`WII_HITS`].
2366#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2367pub(crate) fn wii_hits() -> usize {
2368 WII_HITS.with(|c| c.get())
2369}
2370
2371// lane-sbrect10 r1: how many INTRA blocks read `uv_mode` off the 13-symbol
2372// NO-CFL alphabet *because their size excludes CFL* (libaom `is_cfl_allowed`:
2373// wide <= 32 && high <= 32). The witness that a gate stream really carries a
2374// 64-axis intra block -- the shape whose 14-symbol read desynced every inter
2375// frame carrying one.
2376thread_local! {
2377 pub(super) static NOCFL_UV_MODE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2378}
2379
2380/// Current value of [`NOCFL_UV_MODE_HITS`].
2381#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2382pub(crate) fn nocfl_uv_mode_hits() -> usize {
2383 NOCFL_UV_MODE_HITS.with(|c| c.get())
2384}
2385
2386// lane-inter16ab r5: how many COMPOUND_WEDGE / wedge-INTERINTRA blocks used a
2387// RECTANGULAR codebook row (hgtw/hltw), per shape -- the gate's proof that
2388// the rect wedge masks lifted this round actually fired, not just the square
2389// ones already counted by `WEDGE_HITS`/`WII_HITS`.
2390thread_local! {
2391 pub(super) static RECT_WEDGE_HITS: std::cell::Cell<[usize; 6]> = const { std::cell::Cell::new([0; 6]) };
2392 pub(super) static RECT_WII_HITS: std::cell::Cell<[usize; 6]> = const { std::cell::Cell::new([0; 6]) };
2393}
2394
2395/// Current value of [`RECT_WEDGE_HITS`], indexed by [`RECT_WEDGE_SHAPES`].
2396pub(crate) fn rect_wedge_hits() -> [usize; 6] {
2397 RECT_WEDGE_HITS.with(|c| c.get())
2398}
2399
2400/// Current value of [`RECT_WII_HITS`], indexed by [`RECT_WEDGE_SHAPES`].
2401pub(crate) fn rect_wii_hits() -> [usize; 6] {
2402 RECT_WII_HITS.with(|c| c.get())
2403}
2404
2405// lane-inter4 r4: how many 16x8/8x16 INTER LEAVES actually ran the OBMC
2406// blend -- the gate's proof that `--enable-obmc=1` reached this shape (the
2407// r3 refusal's replacement: prefilt frames are bit-exact vs an instrumented
2408// aomdec, neighbour list included).
2409thread_local! {
2410 pub(super) static OBMC_RECT_LEAF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2411}
2412
2413/// Current value of [`OBMC_RECT_LEAF_HITS`].
2414pub(crate) fn obmc_rect_leaf_hits() -> usize {
2415 OBMC_RECT_LEAF_HITS.with(|c| c.get())
2416}
2417
2418// lane-obmcrec r1: how many OBMC neighbours were taken from the SECOND half of
2419// a 4-wide/4-tall (1:4 strip) chroma pair -- the case whose interp filter used
2420// to be read from the pair's FIRST mi, which is a different block and, when
2421// that half is intra, carries the `[3, 3]` "no filter" sentinel (the three
2422// 1080p 10-bit film cuts refused there). The gate's proof the shape fired.
2423thread_local! {
2424 pub(super) static OBMC_PAIR_FILTER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2425}
2426
2427/// Current value of [`OBMC_PAIR_FILTER_HITS`].
2428pub(crate) fn obmc_pair_filter_hits() -> usize {
2429 OBMC_PAIR_FILTER_HITS.with(|c| c.get())
2430}
2431
2432// lane-t900 r14: how many OBMC neighbour predictions run PAST the frame edge
2433// -- libaom's `op_mi_size` is `AOMMIN(xd->width|height, mi_step)`, the block's
2434// own side, so a block overhanging the bottom/right still predicts the full
2435// neighbour strip (the destination write is what clips). We used to shrink the
2436// prediction to the visible part, which at 4 chroma rows/cols also swaps the
2437// vertical/horizontal kernel to the 4-tap one. The gate's proof the shape fired.
2438thread_local! {
2439 pub(super) static OBMC_EDGE_SPAN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2440}
2441
2442/// Current value of [`OBMC_EDGE_SPAN_HITS`].
2443#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2444pub(crate) fn obmc_edge_span_hits() -> usize {
2445 OBMC_EDGE_SPAN_HITS.with(|c| c.get())
2446}
2447
2448/// Current value of [`OBMC_HITS_8`].
2449#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2450pub(crate) fn obmc_hits_8() -> usize {
2451 OBMC_HITS_8.with(|c| c.get())
2452}
2453
2454// lane-rectgate r1: how many 32x32 quadrants actually decoded a
2455// `PARTITION_HORZ_B` split (the one extended/ab partition this decoder's
2456// inter-frame tile loop decodes -- `PARTITION_HORZ`/`VERT`/`HORZ_A`/`VERT_A`/
2457// `VERT_B` all still fall into the generic "a partition type this encoder
2458// never writes" refusal below) -- the gate's proof that a free-partition
2459// aomenc stream actually exercised a non-`NONE`/`SPLIT` partition rather than
2460// coincidentally never selecting one.
2461thread_local! {
2462 pub(super) static EXTENDED_PARTITION_HITS: std::cell::Cell<usize> =
2463 const { std::cell::Cell::new(0) };
2464}
2465
2466/// Current value of [`EXTENDED_PARTITION_HITS`].
2467#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2468pub(crate) fn extended_partition_hits() -> usize {
2469 EXTENDED_PARTITION_HITS.with(|c| c.get())
2470}
2471
2472// lane-partitions r1: how many 32x32 quadrants decoded a real
2473// `PARTITION_HORZ`/`PARTITION_VERT` (two true rectangular strips, unlike
2474// `PARTITION_HORZ_B`'s square-context stand-in) -- the free-partition
2475// gate's proof this round's arms actually fired.
2476thread_local! {
2477 pub(super) static RECT_PARTITION_HITS: std::cell::Cell<usize> =
2478 const { std::cell::Cell::new(0) };
2479}
2480
2481/// Current value of [`RECT_PARTITION_HITS`].
2482#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2483pub(crate) fn rect_partition_hits() -> usize {
2484 RECT_PARTITION_HITS.with(|c| c.get())
2485}
2486
2487// lane-inter8 r1: how many superblocks an inter tile coded as a single
2488// whole-SB `PARTITION_NONE` 64x64 inter block (the case aomenc picks for
2489// static content, previously a named refusal).
2490thread_local! {
2491 /// lane-sb128c r1: how many 128x128 `PARTITION_NONE` roots this INTER tile
2492 /// path decoded as one whole block (its gate's own witness).
2493 pub(crate) static INTER_SB128_NONE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2494 /// 128x64 / 64x128 INTER blocks decoded at the 128 root (lane-sb128c r7).
2495 pub(crate) static INTER_SB128_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2496 pub(crate) static INTER_SB128_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2497}
2498
2499/// Current value of [`INTER_SB128_HORZ_HITS`], for a gate's before/after delta.
2500pub(crate) fn inter_sb128_horz_hits() -> usize {
2501 INTER_SB128_HORZ_HITS.with(std::cell::Cell::get)
2502}
2503
2504/// Current value of [`INTER_SB128_VERT_HITS`], for a gate's before/after delta.
2505pub(crate) fn inter_sb128_vert_hits() -> usize {
2506 INTER_SB128_VERT_HITS.with(std::cell::Cell::get)
2507}
2508
2509/// Current value of [`INTER_SB128_NONE_HITS`], for a gate's before/after delta.
2510pub fn inter_sb128_none_hits() -> usize {
2511 INTER_SB128_NONE_HITS.with(std::cell::Cell::get)
2512}
2513
2514thread_local! {
2515 /// lane-sb128c r3: how many INTRA-coded 128x128 blocks inside an INTER
2516 /// frame this decoder reconstructed (mu-chunk chroma, four TX_64X64 luma
2517 /// units) -- the gate's witness that the lifted refusal's case fired.
2518 pub(crate) static INTRA_128_IN_INTER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2519}
2520
2521/// Current value of [`INTRA_128_IN_INTER_HITS`], for a gate's before/after delta.
2522pub fn intra_128_in_inter_hits() -> usize {
2523 INTRA_128_IN_INTER_HITS.with(std::cell::Cell::get)
2524}
2525
2526thread_local! {
2527 /// lane-av1ibc128arm: how many 64x64 mu-chunk CHROMA units the
2528 /// intra-in-inter 128x128 root read (`decode_inter_block`'s
2529 /// `side > 64` mu-chunk arm, the INTRA half of the inter pair). Every
2530 /// unit is one `read_plane` on U and one on V, so the counter is the
2531 /// gate's proof the arm ran at all -- no committed 4:4:4 fixture
2532 /// reached it before this lane.
2533 pub(crate) static INTRA_128_IN_INTER_MU_CHROMA_HITS: std::cell::Cell<usize> =
2534 const { std::cell::Cell::new(0) };
2535}
2536
2537/// Current value of [`INTRA_128_IN_INTER_MU_CHROMA_HITS`], for a gate's
2538/// before/after delta.
2539pub fn intra_128_in_inter_mu_chroma_hits() -> usize {
2540 INTRA_128_IN_INTER_MU_CHROMA_HITS.with(std::cell::Cell::get)
2541}
2542
2543thread_local! {
2544 pub(super) static INTER_SB_NONE_HITS: std::cell::Cell<usize> =
2545 const { std::cell::Cell::new(0) };
2546}
2547
2548/// Current value of [`INTER_SB_NONE_HITS`].
2549#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2550pub(crate) fn inter_sb_none_hits() -> usize {
2551 INTER_SB_NONE_HITS.with(|c| c.get())
2552}
2553
2554// lane-inter8 r1: how many INTERIOR (not frame-edge-straddling) 16x16 inter
2555// blocks coded a real `PARTITION_SPLIT` into four 8x8 leaves -- the straddle
2556// path has always run that loop, so only this counter proves the newly-lifted
2557// alphabet value fired.
2558thread_local! {
2559 pub(super) static INTER_SUB16_SPLIT_HITS: std::cell::Cell<usize> =
2560 const { std::cell::Cell::new(0) };
2561}
2562
2563/// Current value of [`INTER_SUB16_SPLIT_HITS`].
2564#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2565pub(crate) fn inter_sub16_split_hits() -> usize {
2566 INTER_SUB16_SPLIT_HITS.with(|c| c.get())
2567}
2568
2569// lane-t900 r28: how many 16x16 inter splits reached their four 8x8 leaves
2570// while at least one reference picture was SCALED (superres) -- the counter
2571// behind the lifted "8x8 partition leaf under a scaled reference" refusal.
2572thread_local! {
2573 pub(super) static SCALED_LEAF8_HITS: std::cell::Cell<usize> =
2574 const { std::cell::Cell::new(0) };
2575}
2576
2577/// Current value of [`SCALED_LEAF8_HITS`].
2578pub fn scaled_leaf8_hits() -> usize {
2579 SCALED_LEAF8_HITS.with(|c| c.get())
2580}
2581
2582// lane-t900 r28: how many sub-8x8 inter blocks (the 4x4 split and the 8x4/4x8
2583// rect pair) were predicted from a SCALED reference -- the counter behind the
2584// lifted "sub-8x8 inter block under a scaled reference" refusal.
2585thread_local! {
2586 pub(super) static SCALED_SUB8_HITS: std::cell::Cell<usize> =
2587 const { std::cell::Cell::new(0) };
2588}
2589
2590/// Current value of [`SCALED_SUB8_HITS`].
2591pub fn scaled_sub8_hits() -> usize {
2592 SCALED_SUB8_HITS.with(|c| c.get())
2593}
2594
2595// lane-rectwire r2: how many `PARTITION_HORZ`/`VERT` strips actually decoded
2596// real (non-skip) coefficients through [`read_coeffs_rect`] -- proves the
2597// rect coefficient reader itself fired, not just the strip-level partition
2598// symbol [`RECT_PARTITION_HITS`] already counts.
2599thread_local! {
2600 pub(super) static RECT_COEFF_HITS: std::cell::Cell<usize> =
2601 const { std::cell::Cell::new(0) };
2602}
2603
2604/// Current value of [`RECT_COEFF_HITS`].
2605#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2606pub(crate) fn rect_coeff_hits() -> usize {
2607 RECT_COEFF_HITS.with(|c| c.get())
2608}
2609
2610// lane-rectx r1: how many below-16x16 HORZ/VERT leaves ([`decode_leaf_rect`])
2611// decoded real (non-skip) TX_16X8/TX_8X16 coefficients -- the counter the
2612// charter's real-aomenc gate hard-asserts.
2613thread_local! {
2614 pub(super) static RECT_LEAF_COEFF_HITS: std::cell::Cell<usize> =
2615 const { std::cell::Cell::new(0) };
2616}
2617
2618/// Current value of [`RECT_LEAF_COEFF_HITS`].
2619#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2620pub(crate) fn rect_leaf_coeff_hits() -> usize {
2621 RECT_LEAF_COEFF_HITS.with(|c| c.get())
2622}
2623
2624// lane-intrarect r1: how many intra-coded HORZ/VERT strips decoded on the
2625// INTER block path ([`decode_intra_rect_in_inter`]), per shape class --
2626// [0] the superblock-level 64x32/32x64, [1] 32x16/16x32, [2] 16x8/8x16.
2627// Every one of them was the named refusal "an intra-coded HORZ/VERT strip
2628// needs rectangular intra prediction" before this round.
2629thread_local! {
2630 pub(super) static INTRA_RECT_IN_INTER_HITS: std::cell::Cell<[usize; 3]> =
2631 const { std::cell::Cell::new([0; 3]) };
2632}
2633
2634/// Current value of [`INTRA_RECT_IN_INTER_HITS`] for one shape class
2635/// (0 = 64x32/32x64, 1 = 32x16/16x32, 2 = 16x8/8x16).
2636#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2637pub(crate) fn intra_rect_strip_in_inter_hits(class: usize) -> usize {
2638 INTRA_RECT_IN_INTER_HITS.with(|c| c.get()[class])
2639}
2640
2641// lane-rect64port r1 (ported by hand from lane-intra64split 5ffbaf3): coded
2642// (non-skip) 64-level HORZ/VERT intra strips whose luma transform is the
2643// un-split TX_64X32/TX_32X64 -- the corner-cropped 32x32 coefficient read of
2644// [`decode_rect_split`], the shape both 10-bit 3840x1608 film cuts stop on.
2645// Split by ORIENTATION (index 0 = 64x32 wide / HORZ, 1 = 32x64 tall / VERT):
2646// a single counter cannot tell an axis swap from a working arm
2647// (class [[scan-weights-cross-axis]]), so the gate asserts both cells.
2648thread_local! {
2649 pub(super) static RECT64_CORNER_TU_HITS: std::cell::Cell<[usize; 2]> =
2650 const { std::cell::Cell::new([0; 2]) };
2651}
2652
2653/// Current value of [`RECT64_CORNER_TU_HITS`] for one orientation
2654/// (0 = 64x32, 1 = 32x64).
2655pub(crate) fn rect64_corner_tu_hits(orient: usize) -> usize {
2656 RECT64_CORNER_TU_HITS.with(|c| c.get()[orient])
2657}
2658
2659// lane-intrasplit r1: intra HORZ/VERT strips inside an INTER frame whose luma
2660// transform is SPLIT, bucketed by the read `tx_depth` (index 1 and 2; index 0
2661// is never incremented) -- the gate's proof that the lifted path ran per depth.
2662thread_local! {
2663 pub(super) static INTRA_RECT_IN_INTER_SPLIT_TX_HITS: std::cell::Cell<[usize; 3]> =
2664 const { std::cell::Cell::new([0; 3]) };
2665}
2666
2667// lane-t900 r21: rect intra strips inside an inter frame that read the
2668// screen-content palette syntax (`allow_screen_content_tools` set and the
2669// strip's own shape admitted by `palette_bsize_ctx_wh`) -- the site a blanket
2670// refusal used to guard, so this counter is what keeps its witness gate
2671// non-vacuous.
2672thread_local! {
2673 pub(super) static INTRA_RECT_IN_INTER_SCREEN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2674}
2675
2676/// Current value of [`INTRA_RECT_IN_INTER_SCREEN_HITS`].
2677#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2678pub(crate) fn intra_rect_in_inter_screen_hits() -> usize {
2679 INTRA_RECT_IN_INTER_SCREEN_HITS.with(std::cell::Cell::get)
2680}
2681
2682/// Resets [`INTRA_RECT_IN_INTER_SCREEN_HITS`] before a decode.
2683#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2684pub(crate) fn reset_intra_rect_in_inter_screen_hits() {
2685 INTRA_RECT_IN_INTER_SCREEN_HITS.with(|c| c.set(0));
2686}
2687
2688/// Current value of [`INTRA_RECT_IN_INTER_SPLIT_TX_HITS`], indexed by tx depth.
2689#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2690pub(crate) fn intra_rect_in_inter_split_tx_hits() -> [usize; 3] {
2691 INTRA_RECT_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get)
2692}
2693
2694// lane-av1txbands: how many `tx_depth`/`txfm_split` reads the deblock-grid
2695// approximation would have resolved off a DIFFERENT CDF row than the real
2696// `TXFM_CONTEXT` bands do -- the exact blocks this band read fixes, on ANY
2697// frame (lane-midcut r2 had it inter-frame-only). A plain "rect/intra block"
2698// tally is green on the old code too (class gate-blind-to-feature).
2699thread_local! {
2700 pub(super) static TXCTX_DEBLOCK_DIVERGENCE_HITS: std::cell::Cell<usize> =
2701 const { std::cell::Cell::new(0) };
2702}
2703
2704/// Current value of [`TXCTX_DEBLOCK_DIVERGENCE_HITS`].
2705#[allow(dead_code)] // gate counter accessor with no reader yet; the counter itself is live
2706pub(crate) fn txctx_deblock_divergence_hits() -> usize {
2707 TXCTX_DEBLOCK_DIVERGENCE_HITS.with(std::cell::Cell::get)
2708}
2709
2710// lane-av1txctxband: how many `get_tx_size_context` reads the per-CELL
2711// `is_inter_block` cover and the per-COLUMN `above_inter`/`left_inter` bands
2712// DISAGREE about -- i.e. exactly the reads whose CDF row the old code chose
2713// wrongly. Green on the old code too (a plain "some block was inter" tally
2714// would be), so this is the non-vacuity arm of the witness gate: it is 0 on
2715// every stream where the bands happened to be right and non-zero on the
2716// 4:4:4 lossy `--sb-size=128` cq-62 stream whose entropy forked at read 32813
2717// on the 8x4 intra leaf at mi(57,52).
2718thread_local! {
2719 pub(super) static TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS: std::cell::Cell<usize> =
2720 const { std::cell::Cell::new(0) };
2721}
2722
2723/// Current value of [`TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS`].
2724#[allow(dead_code)] // read only from the `#[cfg(test)]` gate
2725pub(crate) fn txctx_inter_cell_band_divergence_hits() -> usize {
2726 TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS.with(std::cell::Cell::get)
2727}
2728
2729/// Zeroes [`TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS`].
2730#[allow(dead_code)] // read only from the `#[cfg(test)]` gate
2731pub(crate) fn reset_txctx_inter_cell_band_divergence_hits() {
2732 TXCTX_INTER_CELL_BAND_DIVERGENCE_HITS.with(|c| c.set(0));
2733}
2734
2735// lane-intra14 r1: how many intra-coded 1:4 strips decoded on the INTER
2736// block path, per shape -- [0] 64x16, [1] 16x64, [2] 32x8, [3] 8x32. Every
2737// one of them was the named refusal "an intra-coded 1:4 (or other non-2:1)
2738// rect strip on the inter block path" before this round.
2739thread_local! {
2740 pub(super) static INTRA_RECT4_IN_INTER_HITS: std::cell::Cell<[usize; 4]> =
2741 const { std::cell::Cell::new([0; 4]) };
2742}
2743
2744/// Current value of [`INTRA_RECT4_IN_INTER_HITS`] for one shape
2745/// (0 = 64x16, 1 = 16x64, 2 = 32x8, 3 = 8x32).
2746pub(crate) fn intra_rect4_strip_in_inter_hits(shape: usize) -> usize {
2747 INTRA_RECT4_IN_INTER_HITS.with(|c| c.get()[shape])
2748}
2749
2750// lane-av1444rect: how many 1:4 inter strips at `ss_x == 0` read their chroma
2751// coefficient context over the STRIP'S OWN extent instead of the 4:2:0 pair's
2752// (see [`decode_inter_block`]'s `around_c`). `is_chroma_reference`
2753// (av1_common_int.h:1454) is unconditionally true at ss (0,0), so no pair
2754// exists there; the counter keeps a 4:4:4 1:4-strip gate from passing
2755// vacuously (a 4:2:0 stream of the same content leaves it at 0). It proves
2756// REACH only, never that the fix bites -- that is the gate's byte compare and
2757// its mutation, not this count (skill://ec-av1-pipeline-gate-counters).
2758thread_local! {
2759 pub(super) static RECT4_INTER_OWN_CHROMA444_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2760}
2761
2762/// Current value of [`RECT4_INTER_OWN_CHROMA444_HITS`].
2763#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2764pub(crate) fn rect4_inter_own_chroma444_hits() -> usize {
2765 RECT4_INTER_OWN_CHROMA444_HITS.with(std::cell::Cell::get)
2766}
2767
2768/// Resets [`RECT4_INTER_OWN_CHROMA444_HITS`] before a decode.
2769#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2770pub(crate) fn reset_rect4_inter_own_chroma444_hits() {
2771 RECT4_INTER_OWN_CHROMA444_HITS.with(|c| c.set(0));
2772}
2773
2774// lane-av1444rect r2: how many intra-BC 1:4 strips at `ss (0,0)` took the
2775// own-chroma arm of [`decode_rect4_16_intrabc`]'s `own444`. A 4:2:0 / 4:2:2
2776// stream of the same recipe leaves it at 0, which is what makes it the
2777// 4:4:4-only route.
2778//
2779// WHAT THIS COUNTER IS NOT: it is NOT evidence that the fix bites, and it
2780// never was. A route counter fires identically before and after a change that
2781// changes nothing downstream, so a non-zero count proves REACH and nothing
2782// more. On this lane it is also armed deliberately OUTSIDE the `own444`
2783// expression, so that the mutation (`own444 = false`) still increments it and
2784// the red comes from the pixel/entropy arm instead. The evidence that the ss
2785// gate bites is the measured fork move -- first entropy fork read 11750 ->
2786// 12465, luma first wrong sample 164416 -> 205264, 455240 -> 390380 total --
2787// not this count. See skill://ec-av1-pipeline-gate-counters: a counter needs
2788// a DIFFERS-style assertion to carry a claim.
2789thread_local! {
2790 pub(super) static INTRABC_RECT4_OWN_CHROMA444_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2791}
2792
2793// lane-av1422luma: the ss (1,0) twin of `INTRABC_RECT4_OWN_CHROMA444_HITS`
2794// -- how many intra-BC 1:4 strips at 4:2:2 took the own-chroma (no pair)
2795// route. Same caveat as the 4:4:4 counter: it proves REACH and nothing else.
2796// lane-av1422lift: 4:2:2 is DECODED, so this counter is no longer pinned
2797// behind a header refusal -- and it DOES fire: measured on this branch's tip,
2798// the six committed corpus cells each read 1 more than the cell before
2799// (`s422_320x246` 1, `s422_322x240` 2, `s422_322x246` 3, `s422_352x242_10b`
2800// 4, `s422_416x242_10b` 5, `s422_416x250_10b` 6), and every other committed
2801// 4:2:2 cell leaves it at 6. **No committed gate reads it**: the accessor
2802// below has no callers in the crate (the 4:4:4 twin is read at two
2803// `stream.rs` sites, this one nowhere). The honest sentence is therefore
2804// "no committed test reads this counter", which is what the 4:4:4 twin's
2805// doc says about itself -- it does NOT become "the corpus gate reads it".
2806thread_local! {
2807 pub(super) static INTRABC_RECT4_OWN_CHROMA422_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2808}
2809
2810/// Current value of [`INTRABC_RECT4_OWN_CHROMA422_HITS`].
2811#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2812pub(crate) fn intrabc_rect4_own_chroma422_hits() -> usize {
2813 INTRABC_RECT4_OWN_CHROMA422_HITS.with(std::cell::Cell::get)
2814}
2815
2816/// Resets [`INTRABC_RECT4_OWN_CHROMA422_HITS`] before a decode.
2817#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2818pub(crate) fn reset_intrabc_rect4_own_chroma422_hits() {
2819 INTRABC_RECT4_OWN_CHROMA422_HITS.with(|c| c.set(0));
2820}
2821
2822/// Current value of [`INTRABC_RECT4_OWN_CHROMA444_HITS`].
2823#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2824pub(crate) fn intrabc_rect4_own_chroma444_hits() -> usize {
2825 INTRABC_RECT4_OWN_CHROMA444_HITS.with(std::cell::Cell::get)
2826}
2827
2828/// Resets [`INTRABC_RECT4_OWN_CHROMA444_HITS`] before a decode.
2829#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2830pub(crate) fn reset_intrabc_rect4_own_chroma444_hits() {
2831 INTRABC_RECT4_OWN_CHROMA444_HITS.with(|c| c.set(0));
2832}
2833
2834// lane-rectx r5: how many times a NON-strip `kf_y_mode` reader
2835// ([`decode_block`], [`decode_block_rect`], [`decode_block_rect64`]) took an
2836// above/left mode from the mi-exact map that DIFFERS from its coarse 16x16
2837// slot -- i.e. how often the r5 defect would have picked the wrong CDF row.
2838thread_local! {
2839 pub(super) static MODE_MI_OVERRIDE_HITS: std::cell::Cell<usize> =
2840 const { std::cell::Cell::new(0) };
2841}
2842
2843/// Current value of [`MODE_MI_OVERRIDE_HITS`].
2844#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2845pub(crate) fn mode_mi_override_hits() -> usize {
2846 MODE_MI_OVERRIDE_HITS.with(|c| c.get())
2847}
2848
2849// lane-cfl r1: how many times a chroma intra-edge filter-type read
2850// (`get_filt_type`, libaom reconintra.c) took an above/left UV mode from the
2851// mi-exact map that DIFFERS from its coarse 16x16 slot -- i.e. how often the
2852// r1 defect would have filtered a chroma edge with the wrong strength.
2853thread_local! {
2854 pub(super) static UV_MODE_MI_OVERRIDE_HITS: std::cell::Cell<usize> =
2855 const { std::cell::Cell::new(0) };
2856}
2857
2858/// Current value of [`UV_MODE_MI_OVERRIDE_HITS`].
2859#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2860pub(crate) fn uv_mode_mi_override_hits() -> usize {
2861 UV_MODE_MI_OVERRIDE_HITS.with(|c| c.get())
2862}
2863
2864// lane-t900 r12: how many chroma edge-filter-type reads took their above/left
2865// `uv_mode` from the mi GRID where the one-slot-per-column map would have
2866// answered differently -- the sub-8x8 pair case where the pair's own first
2867// half had already overwritten the column slot the chroma-ref half reads.
2868thread_local! {
2869 pub(super) static UV_MODE_GRID_OVERRIDE_HITS: std::cell::Cell<usize> =
2870 const { std::cell::Cell::new(0) };
2871}
2872
2873/// Current value of [`UV_MODE_GRID_OVERRIDE_HITS`].
2874pub fn uv_mode_grid_override_hits() -> usize {
2875 UV_MODE_GRID_OVERRIDE_HITS.with(|c| c.get())
2876}
2877
2878// lane-t900 r8: how many intra edge-filter-type reads (luma + chroma) the
2879// INTER neighbour stamp saved: the coarse SUB band still held a SMOOTH mode
2880// from an earlier block in that pixel row/column while the mi-exact map --
2881// which an inter block only started writing this round -- correctly says the
2882// neighbour is not smooth (libaom `is_smooth`: an inter neighbour's `mode` is
2883// an INTER mode, and its `uv_mode` "is not set for inter blocks").
2884thread_local! {
2885 pub(super) static INTER_NEIGHBOUR_NOT_SMOOTH_HITS: std::cell::Cell<usize> =
2886 const { std::cell::Cell::new(0) };
2887}
2888
2889/// Current value of [`INTER_NEIGHBOUR_NOT_SMOOTH_HITS`].
2890#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2891pub(crate) fn inter_neighbour_not_smooth_hits() -> usize {
2892 INTER_NEIGHBOUR_NOT_SMOOTH_HITS.with(|c| c.get())
2893}
2894
2895// lane-mtfix r1: how many times a chroma intra-edge filter-type read was
2896// suppressed at a TILE edge that is not a frame edge -- the above/left
2897// `uv_mode` neighbour of a block on a tile's first mi row/column lives in
2898// another tile, so libaom's `above_mbmi`/`left_mbmi` are NULL there. The
2899// coarse [`SUB`] maps are frame-sized and (`above_uv_mode`) not cleared per
2900// tile, so without the guard in [`Neighbours::smooth_uv_neighbour`] the tile
2901// above would decide this tile's chroma edge filter strength.
2902thread_local! {
2903 pub(super) static UV_TILE_EDGE_SUPPRESSED_HITS: std::cell::Cell<usize> =
2904 const { std::cell::Cell::new(0) };
2905}
2906
2907/// Current value of [`UV_TILE_EDGE_SUPPRESSED_HITS`].
2908#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2909pub(crate) fn uv_tile_edge_suppressed_hits() -> usize {
2910 UV_TILE_EDGE_SUPPRESSED_HITS.with(|c| c.get())
2911}
2912
2913// lane-av1leftref: how many chroma intra-edge filter-type reads land on a
2914// left neighbour whose `uv_mode` at libaom's real read cell
2915// (`base_mi[ss_y * mi_stride - 1]` = row `+ss_y`, col `-1`) DIFFERS from the
2916// cell this decoder used to read (its own mi row). Two buckets: the raw mode
2917// value moved, and `is_smooth_mode` -- the boolean the read actually feeds --
2918// flipped. The second is the one that can move pixels.
2919thread_local! {
2920 pub(super) static UV_LEFT_SS_Y_MODE_DIFF_HITS: std::cell::Cell<usize> =
2921 const { std::cell::Cell::new(0) };
2922 pub(super) static UV_LEFT_SS_Y_SMOOTH_DIFF_HITS: std::cell::Cell<usize> =
2923 const { std::cell::Cell::new(0) };
2924}
2925
2926/// Current value of [`UV_LEFT_SS_Y_MODE_DIFF_HITS`].
2927pub fn uv_left_ss_y_mode_diff_hits() -> usize {
2928 UV_LEFT_SS_Y_MODE_DIFF_HITS.with(|c| c.get())
2929}
2930
2931/// Current value of [`UV_LEFT_SS_Y_SMOOTH_DIFF_HITS`].
2932pub fn uv_left_ss_y_smooth_diff_hits() -> usize {
2933 UV_LEFT_SS_Y_SMOOTH_DIFF_HITS.with(|c| c.get())
2934}
2935
2936// lane-av1leftwit: decode-path chroma edge-filter-type reads at `ss_y > 0`
2937// whose left-neighbour COLUMN holds a run of length 1 -- the cell this
2938// decoder reads (its own mi row) and the cell libaom reads (one row down)
2939// were written by two DIFFERENT blocks, i.e. the left neighbour is at most
2940// 1 mi tall. That is the only geometry in which the `+ss_y` term can change
2941// the answer at all; `UV_LEFT_SS_Y_READS` alone proves nothing about it.
2942thread_local! {
2943 pub(super) static UV_LEFT_1MI_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2944}
2945
2946/// Current value of [`UV_LEFT_1MI_SPLIT_HITS`].
2947pub fn uv_left_1mi_split_hits() -> usize {
2948 UV_LEFT_1MI_SPLIT_HITS.with(|c| c.get())
2949}
2950
2951// lane-cfl r1 gate counters: `UV_CFL_PRED` blocks (every `cfl_alpha_signs`
2952// read) and chroma blocks with a NONZERO `angle_delta_uv` -- the two block
2953// shapes the r1 chroma defect showed up on.
2954thread_local! {
2955 pub(super) static CFL_BLOCK_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2956 pub(super) static UV_ANGLE_DELTA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2957}
2958
2959// lane-av1cfl: which `cfl_ac_ss` arm ran, one bump per CfL block. The 4:4:4
2960// arm is libaom `cfl_luma_subsampling_444_lbd_c` (1x1 luma per chroma sample)
2961// and the 4:2:2 arm is `cfl_luma_subsampling_422_lbd_c`; only the last two
2962// reach `cfl_ac_q3_at`'s 2x2 average, so these four are the reachability
2963// evidence for that function's format-blind extent.
2964thread_local! {
2965 pub(super) static CFL_AC_444_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2966 pub(super) static CFL_AC_422_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2967 pub(super) static CFL_AC_420_SQ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2968 pub(super) static CFL_AC_420_RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2969 pub(super) static CFL_AC_Q3_AT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2970}
2971
2972/// `[4:4:4, 4:2:2, 4:2:0 square, 4:2:0 rect]` [`cfl_ac_ss`] arm hits.
2973pub fn cfl_ac_arm_hits() -> [usize; 4] {
2974 [
2975 CFL_AC_444_HITS.with(|c| c.get()),
2976 CFL_AC_422_HITS.with(|c| c.get()),
2977 CFL_AC_420_SQ_HITS.with(|c| c.get()),
2978 CFL_AC_420_RECT_HITS.with(|c| c.get()),
2979 ]
2980}
2981
2982/// Entries into [`cfl_ac_q3_at`] itself -- the one arm whose extent is
2983/// `bw / 2, bh / 2` and whose footprint is a 2x2 luma average. The gate
2984/// proves it is reached ONLY at 4:2:0.
2985pub fn cfl_ac_q3_at_hits() -> usize {
2986 CFL_AC_Q3_AT_HITS.with(|c| c.get())
2987}
2988
2989/// Current value of [`CFL_BLOCK_HITS`].
2990#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2991pub(crate) fn cfl_block_hits() -> usize {
2992 CFL_BLOCK_HITS.with(|c| c.get())
2993}
2994
2995/// Current value of [`UV_ANGLE_DELTA_HITS`].
2996#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2997pub(crate) fn uv_angle_delta_hits() -> usize {
2998 UV_ANGLE_DELTA_HITS.with(|c| c.get())
2999}
3000
3001// lane-sbpart r2: how many superblock-level `PARTITION_HORZ`/`PARTITION_VERT`
3002// blocks (two true 64x32/32x64 strips, [`decode_block_rect64`]) fired -- the
3003// gate's proof this round's arms actually reached a real block, not just
3004// that `partition_w64` read one of those two symbol values.
3005thread_local! {
3006 pub(super) static SB_RECT_HITS: std::cell::Cell<usize> =
3007 const { std::cell::Cell::new(0) };
3008}
3009
3010// Current value of [`SB_RECT_HITS`].
3011// lane-hgkf r1: the frame-edge partition bit, one level each. Slot 0 = a
3012// 64-level gathered edge bit read as HORZ/VERT, 1 = the same bit read as
3013// SPLIT, 2/3 = the 32-level pair. A gate asserting slot 0 or 2 proves the
3014// non-SPLIT edge arm actually decoded (before this round the bit was read and
3015// thrown away, so that arm was unreachable).
3016thread_local! {
3017 pub(super) static EDGE_PART_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) };
3018}
3019
3020/// Current value of [`EDGE_PART_HITS`].
3021#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3022pub(crate) fn edge_part_hits() -> [usize; 4] {
3023 EDGE_PART_HITS.with(|c| c.get())
3024}
3025
3026/// Reset [`EDGE_PART_HITS`] (a gate counts one stream at a time).
3027#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3028pub(crate) fn reset_edge_part_hits() {
3029 EDGE_PART_HITS.with(|c| c.set([0; 4]));
3030}
3031
3032#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3033pub(crate) fn sb_rect_hits() -> usize {
3034 SB_RECT_HITS.with(|c| c.get())
3035}
3036
3037// lane-golomb r2: the 32x32-level FRAME-EDGE partition. Slot 0/1 = the
3038// gathered edge bit read as 0 (HORZ/VERT) / 1 (SPLIT); slot 2 = a 32-level
3039// PARTITION_HORZ decoded with `has_rows32 == false` (only the top 32x16 half
3040// is coded), slot 3 = a PARTITION_VERT with `has_cols32 == false`. Both tile
3041// paths (intra and inter) feed the same counter.
3042//
3043// lane-golomb r3: slots 4..7 are the same four facts one level up, at the
3044// SUPERBLOCK (64x64) edge -- 4/5 = the gathered 64-level bit read as
3045// HORZ/VERT / SPLIT, 6 = a 64x32 bottom-edge strip decoded with
3046// `has_rows == false`, 7 = a 32x64 right-edge strip. Real aomenc answers a
3047// bottom-edge superblock with the 64-level HORZ (measured: 192x80 flat-band,
3048// every SB of the last row), so the 32-level slots stay 0 on that content and
3049// only these prove the arm fired.
3050thread_local! {
3051 pub(super) static EDGE32_HITS: std::cell::Cell<[usize; 8]> =
3052 const { std::cell::Cell::new([0; 8]) };
3053}
3054
3055/// Current value of [`EDGE32_HITS`].
3056#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3057pub(crate) fn edge32_hits() -> [usize; 8] {
3058 EDGE32_HITS.with(|c| c.get())
3059}
3060
3061// lane-part32 r4: how many superblock-level AB blocks (`PARTITION_HORZ_A`/
3062// `_B`/`VERT_A`/`_B` at 64x64 -- two 32x32 squares plus one 64x32/32x64
3063// strip) fired. Real aomenc picks these at 64 even with
3064// `--enable-ab-partitions=0` (lane-sbpart r2's own measurement), so this is
3065// the counter the gate hard-asserts.
3066thread_local! {
3067 pub(super) static SB_AB_HITS: std::cell::Cell<[usize; 4]> =
3068 const { std::cell::Cell::new([0; 4]) };
3069}
3070
3071/// Current value of [`SB_AB_HITS`], summed over the four arms.
3072#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3073pub(crate) fn sb_ab_hits() -> usize {
3074 SB_AB_HITS.with(|c| c.get().iter().sum())
3075}
3076
3077/// [`SB_AB_HITS`] split per arm, in `PARTITION_HORZ_A`, `_HORZ_B`,
3078/// `_VERT_A`, `_VERT_B` order -- what the gate hard-asserts arm by arm, so a
3079/// run where aomenc's RD only ever picked (say) `HORZ_A` cannot pass off as
3080/// proof of all four.
3081#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3082pub(crate) fn sb_ab_hits_by_arm() -> [usize; 4] {
3083 SB_AB_HITS.with(std::cell::Cell::get)
3084}
3085
3086// lane-tx64x16: the two 1:4 superblock arms, counted per orientation --
3087// `PARTITION_HORZ_4` (four 64x16 strips) and `PARTITION_VERT_4` (four 16x64
3088// strips). Two counters, not one, because a gate that only proved "some 1:4
3089// strip fired" would pass on a stream that never coded the other axis, and
3090// every scan/context table this round added comes in a transposed pair.
3091thread_local! {
3092 pub(super) static SB_RECT4_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3093 pub(super) static SB_RECT4_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3094}
3095
3096/// Current value of `SB_RECT4_HORZ_HITS` (64x16 strips decoded).
3097#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3098pub(crate) fn sb_rect4_horz_hits() -> usize {
3099 SB_RECT4_HORZ_HITS.with(|c| c.get())
3100}
3101
3102/// Current value of `SB_RECT4_VERT_HITS` (16x64 strips decoded).
3103#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3104pub(crate) fn sb_rect4_vert_hits() -> usize {
3105 SB_RECT4_VERT_HITS.with(|c| c.get())
3106}
3107
3108// lane-tx64x16 r3: the 32x32-level 1:4 arms, counted per orientation --
3109// `PARTITION_HORZ_4` (four 32x8 strips) and `PARTITION_VERT_4` (four 8x32
3110// strips), the arms the ReelB mid-film extract stops at.
3111thread_local! {
3112 pub(super) static RECT4_32_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3113 pub(super) static RECT4_32_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3114 /// lane-inter4 r1: the INTER-frame twins of the two counters above --
3115 /// four 32x8 / 8x32 inter strips of a 32x32-level `PARTITION_HORZ_4` /
3116 /// `PARTITION_VERT_4`.
3117 pub(super) static RECT4_32_HORZ_INTER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3118 pub(super) static RECT4_32_VERT_INTER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3119 /// lane-inter4 r1: superblock-level inter `PARTITION_HORZ`/`PARTITION_VERT`
3120 /// strips (64x32 / 32x64) and their 1:4 pair (64x16 / 16x64).
3121 pub(super) static INTER_SB_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3122 pub(super) static INTER_SB_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3123 pub(super) static INTER_SB_HORZ4_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3124 pub(super) static INTER_SB_VERT4_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3125}
3126
3127// How many 32x32-level 1:4 strips actually read coefficients (non-skip):
3128// a gate that only counted strips would pass on an all-skip stream, which
3129// exercises none of the new scan/context tables.
3130thread_local! {
3131 pub(super) static RECT4_COEFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3132}
3133
3134// lane-rectsplitx r1: 1:4 strips (32x8/8x32/64x16/16x64) decoded through the
3135// per-transform-unit split path, split by tx depth -- depth 1 is a 2:1 RECT
3136// unit (TX_16X8/TX_32X16), depth 2 a square one, and the two INTERLEAVE in
3137// every real stream, so a gate must prove both fired. `SUB16_SPLIT_HITS`
3138// counts the same for a 16x8/8x16 strip below 16x16.
3139thread_local! {
3140 pub(super) static RECT4_SPLIT_DEPTH1_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3141 pub(super) static RECT4_SPLIT_DEPTH2_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3142 pub(super) static SUB16_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3143}
3144
3145/// Current values of `RECT4_SPLIT_DEPTH1_HITS` / `RECT4_SPLIT_DEPTH2_HITS`.
3146#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3147pub(crate) fn rect4_split_depth_hits() -> (usize, usize) {
3148 (
3149 RECT4_SPLIT_DEPTH1_HITS.with(|c| c.get()),
3150 RECT4_SPLIT_DEPTH2_HITS.with(|c| c.get()),
3151 )
3152}
3153
3154/// Current value of `SUB16_SPLIT_HITS`.
3155#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3156pub(crate) fn sub16_split_hits() -> usize {
3157 SUB16_SPLIT_HITS.with(|c| c.get())
3158}
3159
3160// lane-frame36 r2: superblock-level strips ([`decode_block_rect64`]) whose
3161// luma transform is SPLIT and which therefore leave through that fn's early
3162// return -- the arm that published no `TXFM_CONTEXT` band until this round.
3163thread_local! {
3164 pub(super) static RECT64_SPLIT_TXFM_PUBLISH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3165}
3166
3167/// Current value of `RECT64_SPLIT_TXFM_PUBLISH_HITS`.
3168#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3169pub(crate) fn rect64_split_txfm_publish_hits() -> usize {
3170 RECT64_SPLIT_TXFM_PUBLISH_HITS.with(|c| c.get())
3171}
3172
3173/// Current value of `RECT4_COEFF_HITS`.
3174pub(crate) fn rect4_coeff_hits() -> usize {
3175 RECT4_COEFF_HITS.with(|c| c.get())
3176}
3177
3178// lane-sbab r1: how many superblock-level (64x64) AB partitions fired IN AN
3179// INTER frame, per arm, in `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`,
3180// `_VERT_B` order (the intra-frame counterpart is `SB_AB_HITS`). Each arm is
3181// two 32x32 inter squares plus one true 64x32/32x64 inter strip; the gate
3182// asserts the arms it proves separately so a run whose RD only picked one
3183// cannot pass as proof of the others.
3184thread_local! {
3185 pub(super) static SB_AB_INTER_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) };
3186}
3187
3188/// [`SB_AB_INTER_HITS`] per arm (HORZ_A, HORZ_B, VERT_A, VERT_B at 64x64 in an
3189/// inter frame).
3190pub fn sb_ab_inter_hits_by_arm() -> [usize; 4] {
3191 SB_AB_INTER_HITS.with(std::cell::Cell::get)
3192}
3193
3194// lane-inter16ab r1: how many 16x16-level AB partitions fired IN AN INTER
3195// frame, per arm, in `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`, `_VERT_B`
3196// order (the intra-frame counterpart is `AB16_HITS`). Each arm is two 8x8
3197// inter leaves (`decode_inter_block8`) plus one true 16x8/8x16 inter strip
3198// (`decode_inter_block` with `write_w`/`write_h`); the gate asserts every
3199// arm separately so a run whose RD only picked one cannot pass as proof of
3200// four.
3201thread_local! {
3202 pub(super) static AB16_INTER_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) };
3203}
3204
3205/// [`AB16_INTER_HITS`] per arm (HORZ_A, HORZ_B, VERT_A, VERT_B at 16x16 in an
3206/// inter frame).
3207pub fn ab16_inter_hits_by_arm() -> [usize; 4] {
3208 AB16_INTER_HITS.with(std::cell::Cell::get)
3209}
3210
3211// lane-inter16ab r2: the 16x16-level 1:4 pair as INTER blocks -- four 16x4
3212// (`PARTITION_HORZ_4`) or 4x16 (`PARTITION_VERT_4`) strips. `CHROMA_PAIRS`
3213// counts the odd strips that close a 4:2:0 chroma pair
3214// (`is_chroma_reference`, av1_common_int.h:1454: bh == 1 mi => odd mi_row),
3215// `SUB8_PIECES` the pair chroma blocks whose TOP (LEFT) half was built from
3216// the PREVIOUS strip's own mv/ref/filters -- libaom
3217// `build_inter_predictors_sub8x8` (reconinter_template.inc:87-160), reached
3218// through `is_sub8x8_inter` (same file, :54).
3219thread_local! {
3220 pub(super) static INTER16_HORZ4_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3221 pub(super) static INTER16_VERT4_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3222 pub(super) static INTER16_CHROMA_PAIR_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3223 pub(super) static INTER16_SUB8_PIECE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3224}
3225
3226// lane-arfchroma: chroma transform-unit publications whose block started
3227// MID-CELL -- the condition `record_mi_chroma`'s origin alignment exists for.
3228// A 4x4 chroma unit is `1 << ss` luma mi per axis, so a block whose mi origin
3229// is not step-aligned (a 16x4 / 4x16 1:4 strip at 4:2:0 has an ODD mi row or
3230// column) publishes a context cell whose origin is the step-aligned mi BELOW
3231// or RIGHT of its own. Counted per publication, `[row_misaligned,
3232// col_misaligned, both]`, so a gate can prove the witness really walks the
3233// realigned path instead of passing on a stream whose chroma units all happen
3234// to start on a cell boundary.
3235thread_local! {
3236 pub(super) static CHROMA_MIDCELL_PUB_HITS: std::cell::Cell<[usize; 3]> =
3237 const { std::cell::Cell::new([0; 3]) };
3238}
3239
3240/// ChROMA publications that started mid-cell: `[row, col, both]`. See
3241/// [`CHROMA_MIDCELL_PUB_HITS`].
3242#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3243pub fn chroma_midcell_pub_hits() -> [usize; 3] {
3244 CHROMA_MIDCELL_PUB_HITS.with(std::cell::Cell::get)
3245}
3246
3247/// Zeroes [`CHROMA_MIDCELL_PUB_HITS`] so a gate can measure its own decode.
3248#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3249pub fn reset_chroma_midcell_pub_hits() {
3250 CHROMA_MIDCELL_PUB_HITS.with(|c| c.set([0; 3]));
3251}
3252
3253// lane-intra16x4: INTRA-coded strips of an inter 16x16-level 1:4 partition --
3254// [0] 16x4, [1] 4x16, [2] the odd (chroma-reference) ones, which carry the
3255// pair's single 8x4 (4x8) chroma unit for BOTH strips.
3256thread_local! {
3257 pub(super) static INTRA16X4_IN_INTER_HITS: std::cell::Cell<[usize; 3]> =
3258 const { std::cell::Cell::new([0; 3]) };
3259}
3260
3261/// `(intra 16x4 strips, intra 4x16 strips, of which chroma-reference)` decoded
3262/// inside an INTER 16x16-level 1:4 partition (lane-intra16x4).
3263pub fn intra16x4_in_inter_hits() -> (usize, usize, usize) {
3264 let v = INTRA16X4_IN_INTER_HITS.with(std::cell::Cell::get);
3265 (v[0], v[1], v[2])
3266}
3267
3268/// Current values of the inter 16x16-level 1:4 counters: `(16x4 strips, 4x16
3269/// strips, chroma pairs closed, chroma pairs built from two different
3270/// strips' motion vectors)`.
3271pub fn inter16_rect4_counters() -> (usize, usize, usize, usize) {
3272 (
3273 INTER16_HORZ4_HITS.with(std::cell::Cell::get),
3274 INTER16_VERT4_HITS.with(std::cell::Cell::get),
3275 INTER16_CHROMA_PAIR_HITS.with(std::cell::Cell::get),
3276 INTER16_SUB8_PIECE_HITS.with(std::cell::Cell::get),
3277 )
3278}
3279
3280// lane-r14: the 16x16-level 1:4 pair -- four 16x4 (`PARTITION_HORZ_4`) or
3281// 4x16 (`PARTITION_VERT_4`) strips, `CHROMA` counting the odd strips that
3282// close a 4:2:0 chroma pair and `COEFF` the strips with a coded residual.
3283thread_local! {
3284 pub(super) static RECT4_16_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3285 pub(super) static RECT4_16_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3286 pub(super) static RECT4_16_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3287 pub(super) static RECT4_16_COEFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3288 pub(super) static RECT4_16_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3289 /// lane-kf1200: pairs whose chroma edge-filter type read from the PAIR's
3290 /// base mi differs from what the strip's own (odd) mi would have said --
3291 /// the shape that made 4 chroma samples of the ReelB `-ss 1200`
3292 /// key frame miss by 1. Zero here means a gate never exercised the fix.
3293 pub(super) static RECT4_16_UV_PAIR_FILT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3294 /// lane-av1-rect14: lossless 16x4/4x16 chroma pairs walked as two TX_4X4s.
3295 pub(super) static RECT4_16_LOSSLESS_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3296 /// lane-av1-rect14: intrabc reconstructions of a 16x4/4x16 pair strip.
3297 pub(super) static RECT4_16_INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3298 /// lane-kf1200 r2: sub-8x8 chroma blocks that are `skip_txfm` AND
3299 /// `UV_CFL_PRED` -- the arm that used to drop the CfL alpha entirely.
3300 pub(super) static SKIP_CFL_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3301 /// lane-av1-loss64: chroma transform units the frame-edge clip skipped
3302 /// (libaom `decode_reconstruct_tx`'s `max_blocks_wide/high` test) in
3303 /// [`decode_block`]'s multi-transform-unit walk -- the units a lossless
3304 /// block overhanging the frame does NOT code.
3305 pub(super) static CHROMA_EDGE_TU_CLIP_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3306 /// lane-av1-loss64: skipped lossless intrabc rect strips whose luma
3307 /// entropy bands were zeroed per unit (libaom `av1_reset_entropy_context`,
3308 /// decodeframe.c:1262) instead of leaking the previous occupant's.
3309 pub(super) static SKIP_LOSSLESS_BAND_RESET_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3310 /// lane-av1-llband: 4x4 chroma transform units a lossless HORZ/VERT strip
3311 /// walked at subsampling 0/0 (one unit per mi cell -- the geometry the
3312 /// hardcoded 4:2:0 span mis-stepped).
3313 pub(super) static RECT_SPLIT_LOSSLESS_CHROMA444_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3314 /// lane-av1-ibc444rect: unskipped intrabc 8x4/4x8 leaves whose luma
3315 /// coefficients a lossless frame walked as per-4x4 inter units (the walk
3316 /// that replaced the single rect unit).
3317 pub(super) static INTRABC_RECT8_LOSSLESS_LUMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3318 /// lane-av1-ibc444rect: unskipped intrabc 8x4/4x8 leaves whose chroma a
3319 /// lossless 4:4:4 frame walked as per-4x4 [`TxbSet::Chroma4`] units.
3320 pub(super) static INTRABC_RECT8_LOSSLESS_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3321 /// lane-av1loss444kf: 4:4:4 lossless sub-8x8 RECT (8x4 / 4x8) leaf chroma
3322 /// units whose libaom-faithful block-relative reach
3323 /// ([`Reach::of_tu`] over the leaf's own bsize) differs from the
3324 /// standalone-BLOCK_4X4 lookup that used to answer for them. Zero means
3325 /// no stream reached a rect leaf where the two disagree -- a gate
3326 /// asserting the reach fix must see this nonzero, or the fixture never
3327 /// exercised the fixed path.
3328 pub(super) static SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3329 /// lane-av1offtile: 4x4 chroma units a lossless HORZ/VERT strip's plane-
3330 /// major walk skipped because their top-left sample falls outside the
3331 /// CHROMA plane. libaom bounds that walk per plane (`max_block_wide/high`,
3332 /// av1_common_int.h:1565); this walk used to count the block's own
3333 /// `chroma_w / 4` x `chroma_h / 4`. Zero means no stream decoded a
3334 /// lossless strip overhanging the frame edge -- a gate asserting the
3335 /// clip must see this nonzero.
3336 pub(super) static RECT_SPLIT_LOSSLESS_CHROMA_OFFTILE_HITS: std::cell::Cell<usize> =
3337 const { std::cell::Cell::new(0) };
3338}
3339
3340/// How many skipped sub-8x8 chroma blocks carried a CfL alpha (the shape
3341/// that reconstructed as flat DC before lane-kf1200 r2).
3342pub fn skip_cfl_hits() -> usize {
3343 SKIP_CFL_HITS.with(|c| c.get())
3344}
3345
3346/// How many chroma transform units the frame-edge clip skipped in
3347/// [`decode_block`]'s multi-transform-unit walk (lane-av1-loss64). Zero on a
3348/// stream whose lossless blocks never overhang the frame -- a gate asserting
3349/// the clip fired must see this nonzero.
3350pub fn chroma_edge_tu_clip_hits() -> usize {
3351 CHROMA_EDGE_TU_CLIP_HITS.with(|c| c.get())
3352}
3353
3354/// How many skipped lossless intrabc rect strips had their luma entropy
3355/// bands zeroed per unit (lane-av1-loss64).
3356pub fn skip_lossless_band_reset_hits() -> usize {
3357 SKIP_LOSSLESS_BAND_RESET_HITS.with(|c| c.get())
3358}
3359
3360/// How many 4x4 chroma transform units a lossless HORZ/VERT strip walked at
3361/// subsampling 0/0 (lane-av1-llband). Zero means a stream never decoded the
3362/// 4:4:4 lossless unit walk this counter proves -- a gate asserting the fix
3363/// must see this nonzero.
3364pub fn rect_split_lossless_chroma444_hits() -> usize {
3365 RECT_SPLIT_LOSSLESS_CHROMA444_HITS.with(|c| c.get())
3366}
3367
3368/// How many 4x4 chroma units a lossless HORZ/VERT strip's plane-major walk
3369/// skipped for falling outside the chroma plane (lane-av1offtile). Zero means
3370/// no stream decoded a lossless strip overhanging the frame edge -- a gate
3371/// asserting the clip must see this nonzero.
3372pub fn rect_split_lossless_chroma_offtile_hits() -> usize {
3373 RECT_SPLIT_LOSSLESS_CHROMA_OFFTILE_HITS.with(|c| c.get())
3374}
3375
3376/// Reset [`rect_split_lossless_chroma_offtile_hits`] to zero (lane-av1offtile).
3377pub fn reset_rect_split_lossless_chroma_offtile_hits() {
3378 RECT_SPLIT_LOSSLESS_CHROMA_OFFTILE_HITS.with(|c| c.set(0));
3379}
3380
3381/// How many unskipped intrabc 8x4/4x8 leaves a lossless frame walked luma as
3382/// per-4x4 inter units (lane-av1-ibc444rect).
3383pub fn intrabc_rect8_lossless_luma_hits() -> usize {
3384 INTRABC_RECT8_LOSSLESS_LUMA_HITS.with(|c| c.get())
3385}
3386
3387/// How many unskipped intrabc 8x4/4x8 leaves a lossless 4:4:4 frame walked
3388/// chroma as per-4x4 [`TxbSet::Chroma4`] units (lane-av1-ibc444rect).
3389pub fn intrabc_rect8_lossless_chroma_hits() -> usize {
3390 INTRABC_RECT8_LOSSLESS_CHROMA_HITS.with(|c| c.get())
3391}
3392
3393/// How many 4:4:4 lossless sub-8x8 RECT leaf chroma units took the
3394/// block-relative reach libaom's `has_bottom_left` gives, where the
3395/// standalone-BLOCK_4X4 lookup that used to answer disagreed
3396/// (lane-av1loss444kf). Zero on a stream with no such leaf.
3397pub fn sub8_chroma444_lossless_tu_reach_hits() -> usize {
3398 SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS.with(|c| c.get())
3399}
3400
3401/// Gate-side reset for [`SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS`].
3402pub fn reset_sub8_chroma444_tu_reach_hits() {
3403 SUB8_CHROMA444_LOSSLESS_TU_REACH_HITS.with(|c| c.set(0));
3404}
3405
3406/// Gate-side reset for the two lane-av1-ibc444rect counters above.
3407pub fn reset_ibc444rect_hits() {
3408 INTRABC_RECT8_LOSSLESS_LUMA_HITS.with(|c| c.set(0));
3409 INTRABC_RECT8_LOSSLESS_CHROMA_HITS.with(|c| c.set(0));
3410}
3411
3412/// Gate-side reset for the two lane-av1-loss64 counters above.
3413pub fn reset_loss64_hits() {
3414 CHROMA_EDGE_TU_CLIP_HITS.with(|c| c.set(0));
3415 SKIP_LOSSLESS_BAND_RESET_HITS.with(|c| c.set(0));
3416}
3417
3418/// How many 16x4/4x16 chroma pairs took a different `intra_edge_filter_type`
3419/// from the pair's base mi than the strip's own mi would have given.
3420pub fn rect4_16_uv_pair_filt_hits() -> usize {
3421 RECT4_16_UV_PAIR_FILT_HITS.with(|c| c.get())
3422}
3423
3424/// How many lossless 16x4/4x16 chroma pairs walked two TX_4X4s per plane.
3425pub fn rect4_16_lossless_chroma_hits() -> usize {
3426 RECT4_16_LOSSLESS_CHROMA_HITS.with(|c| c.get())
3427}
3428
3429/// How many 16x4/4x16 strips reconstructed as intra block copy.
3430pub fn rect4_16_intrabc_hits() -> usize {
3431 RECT4_16_INTRABC_HITS.with(|c| c.get())
3432}
3433
3434/// Zero the lane-av1-rect14 pair counters so a gate measures one stream.
3435pub fn reset_rect4_16_pair_hits() {
3436 RECT4_16_LOSSLESS_CHROMA_HITS.with(|c| c.set(0));
3437 RECT4_16_INTRABC_HITS.with(|c| c.set(0));
3438}
3439
3440// lane-reelckf r1: the two chroma defects ReelC's key frames exposed --
3441// CHROMA_SKIP_CFL counts skipped intra blocks whose chroma is `UV_CFL_PRED`
3442// (prediction still runs, libaom `predict_and_reconstruct_intra_block`), and
3443// RECT4_16_CHROMA_DIR counts 1:4 chroma pairs predicted directionally (whose
3444// intra-edge filter type must come from the chroma-reference position).
3445thread_local! {
3446 pub(super) static CHROMA_SKIP_CFL_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3447 pub(super) static RECT4_16_CHROMA_DIR_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3448}
3449
3450/// `(skipped UV_CFL_PRED blocks, directional 1:4 chroma pairs)` -- lane-reelckf.
3451pub fn reelc_chroma_counters() -> (usize, usize) {
3452 (
3453 CHROMA_SKIP_CFL_HITS.with(|c| c.get()),
3454 RECT4_16_CHROMA_DIR_HITS.with(|c| c.get()),
3455 )
3456}
3457
3458/// Current values of the 16x16-level 1:4 counters: `(16x4 strips, 4x16
3459/// strips, chroma-reference strips, strips with a coded residual, strips
3460/// whose luma transform is split)`.
3461pub fn rect4_16_counters() -> (usize, usize, usize, usize, usize) {
3462 (
3463 RECT4_16_HORZ_HITS.with(|c| c.get()),
3464 RECT4_16_VERT_HITS.with(|c| c.get()),
3465 RECT4_16_CHROMA_HITS.with(|c| c.get()),
3466 RECT4_16_COEFF_HITS.with(|c| c.get()),
3467 RECT4_16_SPLIT_HITS.with(|c| c.get()),
3468 )
3469}
3470
3471/// Current value of `RECT4_32_HORZ_HITS` (32x8 strips decoded).
3472pub(crate) fn rect4_32_horz_hits() -> usize {
3473 RECT4_32_HORZ_HITS.with(|c| c.get())
3474}
3475
3476/// Current value of `RECT4_32_VERT_HITS` (8x32 strips decoded).
3477pub(crate) fn rect4_32_vert_hits() -> usize {
3478 RECT4_32_VERT_HITS.with(|c| c.get())
3479}
3480
3481/// Current value of `RECT4_32_HORZ_INTER_HITS` (32x8 inter strips decoded).
3482pub(crate) fn rect4_32_horz_inter_hits() -> usize {
3483 RECT4_32_HORZ_INTER_HITS.with(|c| c.get())
3484}
3485
3486/// Current value of `RECT4_32_VERT_INTER_HITS` (8x32 inter strips decoded).
3487pub(crate) fn rect4_32_vert_inter_hits() -> usize {
3488 RECT4_32_VERT_INTER_HITS.with(|c| c.get())
3489}
3490
3491/// Current value of `INTER_SB_HORZ_HITS` (64x32 inter strips decoded).
3492pub(crate) fn inter_sb_horz_hits() -> usize {
3493 INTER_SB_HORZ_HITS.with(|c| c.get())
3494}
3495
3496/// Current value of `INTER_SB_VERT_HITS` (32x64 inter strips decoded).
3497pub(crate) fn inter_sb_vert_hits() -> usize {
3498 INTER_SB_VERT_HITS.with(|c| c.get())
3499}
3500
3501/// Current value of `INTER_SB_HORZ4_HITS` (64x16 inter strips decoded).
3502pub(crate) fn inter_sb_horz4_hits() -> usize {
3503 INTER_SB_HORZ4_HITS.with(|c| c.get())
3504}
3505
3506/// Current value of `INTER_SB_VERT4_HITS` (16x64 inter strips decoded).
3507pub(crate) fn inter_sb_vert4_hits() -> usize {
3508 INTER_SB_VERT4_HITS.with(|c| c.get())
3509}
3510
3511// lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane
3512// dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the
3513// running-vs-stale-snapshot bug this round fixed is exercised by a gate, not
3514// just inert-compiled. Zero forever on a passing gate means that gate's
3515// stream never carries `delta_q_present=1` through a rect64 block.
3516thread_local! {
3517 pub(super) static RECT64_QIDX_DRIFT_HITS: std::cell::Cell<usize> =
3518 const { std::cell::Cell::new(0) };
3519}
3520
3521/// Current value of [`RECT64_QIDX_DRIFT_HITS`].
3522#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3523pub(crate) fn rect64_qidx_drift_hits() -> usize {
3524 RECT64_QIDX_DRIFT_HITS.with(|c| c.get())
3525}
3526
3527// lane-partab r1: how many 32x32 quadrants decoded an AB partition
3528// (PARTITION_HORZ_A / VERT_A / VERT_B -- two 16x16 squares plus one
3529// 16x32/32x16 strip). Like [`RECT_PARTITION_HITS`], this is the
3530// free-partition gate's proof this round's arms actually fired.
3531thread_local! {
3532 pub(super) static PARTAB_HITS: std::cell::Cell<usize> =
3533 const { std::cell::Cell::new(0) };
3534}
3535
3536/// Current value of [`PARTAB_HITS`].
3537#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3538pub(crate) fn partab_hits() -> usize {
3539 PARTAB_HITS.with(|c| c.get())
3540}
3541
3542// lane-part32 r1: how many 32x32 quadrants decoded each INTRA AB/4-way arm,
3543// one counter per arm rather than one shared total -- the gate hard-asserts
3544// each of these individually nonzero so a recipe that only ever fires
3545// HORZ_A can't silently stand in for the whole set.
3546thread_local! {
3547 pub(super) static INTRA_HORZ_A_HITS: std::cell::Cell<usize> =
3548 const { std::cell::Cell::new(0) };
3549 pub(super) static INTRA_HORZ_B_HITS: std::cell::Cell<usize> =
3550 const { std::cell::Cell::new(0) };
3551 pub(super) static INTRA_VERT_A_HITS: std::cell::Cell<usize> =
3552 const { std::cell::Cell::new(0) };
3553 pub(super) static INTRA_VERT_B_HITS: std::cell::Cell<usize> =
3554 const { std::cell::Cell::new(0) };
3555}
3556
3557/// Current value of [`INTRA_HORZ_A_HITS`].
3558#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3559pub(crate) fn intra_horz_a_hits() -> usize {
3560 INTRA_HORZ_A_HITS.with(|c| c.get())
3561}
3562
3563/// Current value of [`INTRA_HORZ_B_HITS`].
3564#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3565pub(crate) fn intra_horz_b_hits() -> usize {
3566 INTRA_HORZ_B_HITS.with(|c| c.get())
3567}
3568
3569/// Current value of [`INTRA_VERT_A_HITS`].
3570#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3571pub(crate) fn intra_vert_a_hits() -> usize {
3572 INTRA_VERT_A_HITS.with(|c| c.get())
3573}
3574
3575/// Current value of [`INTRA_VERT_B_HITS`].
3576#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3577pub(crate) fn intra_vert_b_hits() -> usize {
3578 INTRA_VERT_B_HITS.with(|c| c.get())
3579}
3580
3581// How many [`read_inter_compound_mode`] reads actually happened
3582// (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own
3583// `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound
3584// mvstack build), not just that `comp_mode` fired. Still refused right
3585// after (no MV assignment or MC wired), so this only counts attempted
3586// reads.
3587thread_local! {
3588 pub(super) static COMPOUND_MODE_HITS: std::cell::Cell<usize> =
3589 const { std::cell::Cell::new(0) };
3590}
3591
3592/// Current value of [`COMPOUND_MODE_HITS`].
3593#[allow(dead_code)] // reader is test-only (the 12-bit compound witness); dead in non-test builds
3594pub(crate) fn compound_mode_hits() -> usize {
3595 COMPOUND_MODE_HITS.with(|c| c.get())
3596}
3597
3598/// How many query blocks folded in at least one temporal MV candidate
3599/// (spec 7.10.2.8's `add_tpl_ref_mv`) so far in this process -- the
3600/// temporal-MV gate's own firing counter (lane-av1tmvp).
3601///
3602/// # HANDOFF (lane-av1tmvp): not yet wired to a live stream
3603/// [`crate::mvstack::find_mv_stack_with_sign_bias`]'s only call site in
3604/// this file (`decode_inter_block`) still passes `tpl: None` -- this
3605/// counter compiles and the projection math it counts is unit-tested
3606/// ([`crate::motion_field`]), but nothing in [`crate::stream::decode_stream`]
3607/// builds a per-DPB-slot [`crate::motion_field::MotionField`] or calls
3608/// [`crate::motion_field::setup_motion_field`] yet, so this will read `0`
3609/// against any real stream today. See the module doc on
3610/// `crate::motion_field` and this crate's ledger for the remaining wiring.
3611#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3612pub(crate) fn tmv_hits() -> usize {
3613 crate::mvstack::tmv_hits()
3614}
3615
3616/// Current value of [`crate::mc::inter_pred_hits`] -- inter predictions
3617/// produced on this thread, the 10-bit inter gate's firing proof.
3618#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3619pub(crate) fn inter_pred_hits() -> usize {
3620 crate::mc::inter_pred_hits()
3621}
3622
3623/// Current value of the counter for `ref_frame` (`LAST2_FRAME`..=`ALTREF_FRAME`;
3624/// panics on `LAST_FRAME`/`INTRA_FRAME`/`NONE`, which have no counter here).
3625#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3626pub(crate) fn ref_hits(ref_frame: i8) -> usize {
3627 let c = match ref_frame {
3628 LAST2_FRAME => &LAST2_HITS,
3629 LAST3_FRAME => &LAST3_HITS,
3630 GOLDEN_FRAME => &GOLDEN_HITS,
3631 BWDREF_FRAME => &BWDREF_HITS,
3632 ALTREF2_FRAME => &ALTREF2_HITS,
3633 ALTREF_FRAME => &ALTREF_HITS,
3634 other => panic!("ref_hits: no per-reference counter for ref_frame {other}"),
3635 };
3636 c.with(|v| v.get())
3637}
3638
3639/// Current value of [`ANGLE_DELTA_HITS`].
3640#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3641pub(crate) fn angle_delta_hits() -> usize {
3642 ANGLE_DELTA_HITS.with(|c| c.get())
3643}
3644
3645/// Current value of [`TX_CLASS1_HITS`].
3646#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3647pub(crate) fn tx_class1_hits() -> usize {
3648 TX_CLASS1_HITS.with(|c| c.get())
3649}
3650
3651// How many `PARTITION_SPLIT` decisions below an 8x8 block (four independent
3652// `BLOCK_4X4` leaves, spec `decode_partition`'s `bSize < BLOCK_8X8` recursion
3653// bottom) this thread's decode actually reconstructed -- the same
3654// before/after counter pattern as [`TX_CLASS1_HITS`], proving a stream
3655// genuinely exercised the sub-8x8 leaf path rather than every attempt
3656// coincidentally landing on `PARTITION_NONE`.
3657thread_local! {
3658 pub(super) static SUB8_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3659 /// How many 8x8 groups an INTER frame split into four BLOCK_4X4 inter
3660 /// sub-blocks (lane-intersub8).
3661 pub(super) static SUB8_INTER_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3662 /// How many 8x8 groups an INTER frame split into two rectangular sub-8x8
3663 /// inter leaves (lane-intersub8 r3), indexed `[0] = HORZ` (two BLOCK_8X4),
3664 /// `[1] = VERT` (two BLOCK_4X8).
3665 pub(super) static SUB8_INTER_RECT_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
3666 /// lane-sub8intra: INTRA leaves decoded inside an inter frame's sub-8x8
3667 /// HORZ/VERT partition -- `[0]` 8x4, `[1]` 4x8, `[2]` of those that were
3668 /// the chroma reference (so coded the group's 4x4 chroma intra), `[3]`
3669 /// MIXED groups whose chroma reference is INTER while its sibling is
3670 /// intra (the `is_sub8x8_inter` false path), `[4]` INTRA `BLOCK_4X4`
3671 /// leaves of an inter frame's sub-8x8 `PARTITION_SPLIT` (lane-sub8x4 r2 --
3672 /// the second lifted refusal's own witness; `[0]`/`[1]` count those too,
3673 /// so only this cell separates the split arm from the HORZ/VERT one).
3674 pub(super) static SUB8_INTRA_RECT_HITS: std::cell::Cell<[usize; 5]> = const { std::cell::Cell::new([0; 5]) };
3675}
3676
3677/// Current value of [`SUB8_INTRA_RECT_HITS`]: `(8x4, 4x8, chroma-reference,
3678/// mixed groups, split 4x4 leaves)`.
3679pub fn sub8_intra_rect_hits() -> (usize, usize, usize, usize, usize) {
3680 SUB8_INTRA_RECT_HITS.with(|c| {
3681 let h = c.get();
3682 (h[0], h[1], h[2], h[3], h[4])
3683 })
3684}
3685
3686/// Current value of [`SUB8_INTER_RECT_HITS`]: `(8x4 groups, 4x8 groups)`.
3687pub fn sub8_inter_rect_hits() -> (usize, usize) {
3688 SUB8_INTER_RECT_HITS.with(|c| {
3689 let h = c.get();
3690 (h[0], h[1])
3691 })
3692}
3693
3694// lane-cdef r1: (a) how many 8x8 CDEF units `apply_cdef` EXCLUDED because all
3695// four of their mi cells are `skip_txfm` (libaom `cdef.c:29-38`
3696// `is_8x8_block_skip` / `av1_cdef_compute_sb_list`'s dlist test), and (b) how
3697// many 8x8 inter leaves (`decode_inter_block8`) wrote that skip band at all.
3698// (b) was 0 for every stream before this round -- the leaf path never touched
3699// the band, so an all-skip 8x8 group kept the PREVIOUS frame's flags and got
3700// filtered where libaom skips it. A gate asserts both are non-zero.
3701thread_local! {
3702 pub(super) static INTER8_SKIP_BAND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3703 // lane-cdefstrip r1: (d) skip RECTANGULAR blocks (every strip arm: 32x8,
3704 // 8x32, 16x8, 32x16, 64x16, AB/1:4 pieces...) that wrote the CDEF skip
3705 // band, and (e) 8x8 CDEF units whose four mi cells do NOT agree on skip --
3706 // the shape libaom's `is_8x8_block_skip` (`cdef.c:29-38`) exists for: an
3707 // 8-tall strip pair where only one half is skip must still be FILTERED.
3708 pub(super) static RECT_SKIP_BAND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3709}
3710
3711/// Current value of `RECT_SKIP_BAND_HITS`.
3712pub fn rect_skip_band_hits() -> usize {
3713 RECT_SKIP_BAND_HITS.with(|c| c.get())
3714}
3715
3716/// Current value of `INTER8_SKIP_BAND_HITS`.
3717#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3718pub(crate) fn inter8_skip_band_hits() -> usize {
3719 INTER8_SKIP_BAND_HITS.with(|c| c.get())
3720}
3721
3722/// Current value of [`SUB8_SPLIT_HITS`].
3723#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3724pub(crate) fn sub8_split_hits() -> usize {
3725 SUB8_SPLIT_HITS.with(|c| c.get())
3726}
3727
3728/// Current value of [`SUB8_INTER_SPLIT_HITS`].
3729pub fn sub8_inter_split_hits() -> usize {
3730 SUB8_INTER_SPLIT_HITS.with(|c| c.get())
3731}
3732
3733// lane-t900 r7: sub-8x8 inter groups whose one chroma unit inherits a
3734// `tx_type` DIFFERENT from the group's FIRST sub-block -- the only shape that
3735// tells the two rules apart (`av1_get_tx_type` indexes `xd->tx_type_map`,
3736// which `set_mi_offsets` re-points to the CHROMA-REFERENCE sub-block, so the
3737// first sub-block's type is never the one). Reading it off sub-block 0
3738// inverted one 4x4 chroma unit on the wrong basis with the entropy stream
3739// perfectly in sync (no chroma `tx_type` symbol is coded), so a gate can only
3740// see this rule through this counter.
3741thread_local! {
3742 pub(super) static SUB8_CHROMA_TX_FROM_REF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3743}
3744
3745/// Current value of `SUB8_CHROMA_TX_FROM_REF_HITS`.
3746pub fn sub8_chroma_tx_from_ref_hits() -> usize {
3747 SUB8_CHROMA_TX_FROM_REF_HITS.with(|c| c.get())
3748}
3749
3750// How many 4x8 / 8x4 leaves (lane-tx4x8's `PARTITION_VERT`/`PARTITION_HORZ`
3751// of an 8x8 block) this thread's decode reconstructed with REAL coefficients
3752// -- a skipped leaf exercises the prediction and the mi bookkeeping but never
3753// the rect transform, the 32-position `eob_pt` or the rect scan, so the gate
3754// asserts on these two rather than a plain leaf count.
3755thread_local! {
3756 pub(super) static TX4X8_CODED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3757 pub(super) static TX8X4_CODED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3758 /// Sub-8x8 rect leaves whose `tx_depth` symbol resolved to 1 -- the leaf's
3759 /// two 4x4 transform units, predicted one after the other. A separate
3760 /// counter from [`TX_DEPTH_HITS`] (which every square path also bumps) so
3761 /// the gate can prove THIS path fired.
3762 pub(super) static RECT8_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3763 /// 16x8/8x16 intra strips whose prediction actually read past the block's
3764 /// own width (above-right) or height (below-left) -- the samples
3765 /// `Reach::of_rect` decides on, and the only ones a wrong `has_tr_*`/
3766 /// `has_bl_*` table row can corrupt (lane-tx4x8 r3).
3767 pub(super) static RECT_STRIP_REACH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3768 /// Every 16x8/8x16 intra strip predicted, reaching or not -- the
3769 /// denominator [`RECT_STRIP_REACH_HITS`] is a fraction of.
3770 pub(super) static RECT_STRIP_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3771}
3772
3773/// Current value of [`RECT8_SPLIT_TX_HITS`].
3774#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3775pub(crate) fn rect8_split_tx_hits() -> usize {
3776 RECT8_SPLIT_TX_HITS.with(|c| c.get())
3777}
3778
3779/// Current value of [`RECT_STRIP_PRED_HITS`].
3780#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3781pub(crate) fn rect_strip_pred_hits() -> usize {
3782 RECT_STRIP_PRED_HITS.with(|c| c.get())
3783}
3784
3785/// Current value of [`RECT_STRIP_REACH_HITS`].
3786#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3787pub(crate) fn rect_strip_reach_hits() -> usize {
3788 RECT_STRIP_REACH_HITS.with(|c| c.get())
3789}
3790
3791/// Current value of [`TX4X8_CODED_HITS`].
3792#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3793pub(crate) fn tx4x8_coded_hits() -> usize {
3794 TX4X8_CODED_HITS.with(|c| c.get())
3795}
3796
3797/// Current value of [`TX8X4_CODED_HITS`].
3798#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3799pub(crate) fn tx8x4_coded_hits() -> usize {
3800 TX8X4_CODED_HITS.with(|c| c.get())
3801}
3802
3803// How many CHROMA coefficient blocks read their `eob_pt` from the class-1
3804// (`TX_CLASS_HORIZ`/`VERT`) row, across every call on the current thread.
3805// Chroma never codes a `tx_type` symbol -- it inherits the colocated luma
3806// type verbatim (`av1_get_tx_type`, `blockd.h:1291`) -- so this fires only on
3807// an inter leaf whose luma picked a 1D type, the path lane-eobc1 wired
3808// (`eob_pt_{16,64,128,256}_chroma_class1`).
3809thread_local! {
3810 pub(super) static CHROMA_EOB_CLASS1_HITS: std::cell::Cell<usize> =
3811 const { std::cell::Cell::new(0) };
3812}
3813
3814/// Current value of [`CHROMA_EOB_CLASS1_HITS`].
3815#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
3816pub(crate) fn chroma_eob_class1_hits() -> usize {
3817 CHROMA_EOB_CLASS1_HITS.with(|c| c.get())
3818}
3819
3820/// Enabled by `EC_AV1_PLANE_SENTINEL` (there is no separate flag for it): print
3821/// an EXACT census of the samples the tile walk never wrote -- with it, every
3822/// plane still holding [`plane_poison`] at this point is a sample no block
3823/// reconstructed, and no legal sample can equal the poison (reconstruction
3824/// clamps to `(1 << bit_depth) - 1`, at most 4095).
3825///
3826/// Coverage, stated as the code has it: this census runs at TWO of the four
3827/// places [`apply_deblock`] is entered from -- the key-frame path and the
3828/// non-pipelined inter path, both immediately before that frame's deblock. The
3829/// two it does NOT cover are the encoder's filter search ([`replay_filters`],
3830/// which runs the filters over a CAPTURED copy, not a live decode) and the
3831/// pipelined inter branch, where deblock has already run band by band inside
3832/// `par` by the time this tail is reached. A zero count therefore means "no hole
3833/// on the paths that reach this call", not "no hole on any path". It is EXACT
3834/// over the extent it scans -- the scan itself reads every sample of that
3835/// extent, unlike the older [`dump_stage`] pair, which truncates to `as u8`.
3836///
3837/// This is the shipped form of the four-line temporary scan the
3838/// `lane/av1422seed` census used: it replaces a wrong-sample diff (which says
3839/// where the OUTPUT is wrong, not whether the block was written at all) with a
3840/// direct count plus the coordinates of every hole, grouped into per-row
3841/// spans so a large hole stays readable.
3842///
3843/// It scans TWO regions per plane, because they answer different questions and
3844/// the earlier revision only scanned one of them:
3845/// * the TRUE EXTENT -- each plane over its own `true_width` x `true_height`,
3846/// PER AXIS (`true_width.min(p.width)`), so a 4:2:2 frame's chroma is scanned
3847/// at its own `fw/2 x fh` shape rather than the 4:2:0 `div_ceil(2)` crop the
3848/// older [`dump_stage16`] used. A hole here can reach the caller, and it is
3849/// the region lane/av1unwritten's 224 samples sat in.
3850/// * the PADDED TAIL -- everything outside that extent, out to the block-aligned
3851/// coding surface -- counted separately into [`PAD_UNWRITTEN_SAMPLES`]. The
3852/// earlier revision's doc comment asserted "past that is the padded coding
3853/// surface's invented tail, which no decoder ever reads". That assertion is
3854/// exactly what a tail that is never written and never read looks like, so it
3855/// was self-certifying; the tail is now scanned and counted like any other
3856/// region. `EC_AV1_PLANE_ALLOC=padzero`/`extzero` attribute a read to one
3857/// side or the other (see [`fresh_plane`]).
3858pub(super) fn census_unwritten(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) {
3859 if !plane_sentinel_on() {
3860 return;
3861 }
3862 let poison = plane_poison();
3863 let idx = PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst);
3864 for (name, p) in [("Y", y), ("U", u), ("V", v)] {
3865 let (w, h) = (p.true_width.min(p.width), p.true_height.min(p.height));
3866 let mut total = 0usize;
3867 let mut spans: Vec<(usize, usize, usize)> = Vec::new();
3868 for row in 0..h {
3869 let mut run: Option<(usize, usize)> = None;
3870 for col in 0..w {
3871 if p.data[row * p.width + col] == poison {
3872 total += 1;
3873 run = Some(match run {
3874 None => (col, col),
3875 Some((a, _)) => (a, col),
3876 });
3877 }
3878 if run.is_some() && (col + 1 == w || p.data[row * p.width + col + 1] != poison) {
3879 let (a, b) = run.take().expect("a run is open here");
3880 spans.push((row, a, b));
3881 }
3882 }
3883 }
3884 // The padded tail: columns `w..width` on rows `0..h`, plus every column
3885 // on rows `h..height`.
3886 let mut pad_total = 0usize;
3887 let mut pad_scanned = 0usize;
3888 for row in 0..p.height {
3889 let (from, to) = if row < h { (w, p.width) } else { (0, p.width) };
3890 if from >= to {
3891 continue;
3892 }
3893 pad_scanned += to - from;
3894 pad_total += p.data[row * p.width + from..row * p.width + to]
3895 .iter()
3896 .filter(|&&s| s == poison)
3897 .count();
3898 }
3899 UNWRITTEN_SAMPLES.fetch_add(total, std::sync::atomic::Ordering::SeqCst);
3900 CENSUS_SCANNED.fetch_add(w * h, std::sync::atomic::Ordering::SeqCst);
3901 PAD_UNWRITTEN_SAMPLES.fetch_add(pad_total, std::sync::atomic::Ordering::SeqCst);
3902 PAD_CENSUS_SCANNED.fetch_add(pad_scanned, std::sync::atomic::Ordering::SeqCst);
3903 eprintln!(
3904 "SENTINEL_CENSUS idx={idx} plane={name} surface={}x{} extent={w}x{h} \
3905 pad_scanned={pad_scanned} unwritten={total} pad_unwritten={pad_total}",
3906 p.width, p.height,
3907 );
3908 if total == 0 {
3909 continue;
3910 }
3911 let body: Vec<String> = spans
3912 .iter()
3913 .map(|&(r, a, b)| format!("y{r} x{a}..={b}"))
3914 .collect();
3915 eprintln!(
3916 "SENTINEL_CENSUS idx={idx} plane={name} surface={}x{} extent={w}x{h} \
3917 unwritten={total} spans={}: {}",
3918 p.width,
3919 p.height,
3920 spans.len(),
3921 body.join(" ")
3922 );
3923 }
3924}
3925
3926/// Samples [`census_unwritten`] has looked at since the last
3927/// [`take_census_scanned`]. A gate that only asserts
3928/// [`take_unwritten_samples`] == 0 passes on a decode that never scanned
3929/// anything, so it reads THIS too: a census that scanned nothing has proved
3930/// nothing.
3931pub(super) static CENSUS_SCANNED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
3932
3933/// Reads and clears [`CENSUS_SCANNED`]; see [`take_unwritten_samples`] for the
3934/// pairing.
3935pub fn take_census_scanned() -> usize {
3936 CENSUS_SCANNED.swap(0, std::sync::atomic::Ordering::SeqCst)
3937}
3938
3939/// Samples [`census_unwritten`] scanned in the padded tail, paired with
3940/// [`PAD_UNWRITTEN_SAMPLES`] for the same reason as [`CENSUS_SCANNED`].
3941pub(super) static PAD_CENSUS_SCANNED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
3942
3943/// Reads and clears [`PAD_CENSUS_SCANNED`].
3944pub fn take_pad_census_scanned() -> usize {
3945 PAD_CENSUS_SCANNED.swap(0, std::sync::atomic::Ordering::SeqCst)
3946}
3947
3948/// Samples [`census_unwritten_final`] has looked at since the last
3949/// [`take_final_census_scanned`]. A gate that only asserts
3950/// [`take_final_unwritten_samples`] == 0 passes on a build whose census call was
3951/// deleted, so it reads THIS too -- the same pairing
3952/// [`CENSUS_SCANNED`] documents for the pre-deblock census.
3953pub(super) static FINAL_CENSUS_SCANNED: std::sync::atomic::AtomicUsize =
3954 std::sync::atomic::AtomicUsize::new(0);
3955
3956/// Reads and clears [`FINAL_CENSUS_SCANNED`]; the pairing is the reason it
3957/// exists, exactly as for [`take_census_scanned`].
3958pub fn take_final_census_scanned() -> usize {
3959 FINAL_CENSUS_SCANNED.swap(0, std::sync::atomic::Ordering::SeqCst)
3960}
3961
3962/// lane-unwritten-dep: the census at the pipeline's last point. Counts, over each
3963/// plane, how many samples still hold [`PLANE_SENTINEL`] once every filter has
3964/// run, and records how many samples it LOOKED at in [`FINAL_CENSUS_SCANNED`].
3965///
3966/// SCOPE, which lane-av1graincensus did not change but had to be true about:
3967/// this runs BEFORE `apply_grain`, over the PRE-grain planes. It does NOT and
3968/// never did measure the grained picture the caller receives -- that is
3969/// [`census_unwritten_grained`], a separate counter over a separate buffer.
3970///
3971/// Gated on [`plane_sentinel_on`] -- the SAME predicate as [`fresh_plane`] and as
3972/// the pre-deblock [`census_unwritten`]: the env flag OR the thread-local
3973/// [`set_plane_sentinel`] override. An earlier revision gated this on the raw env
3974/// var alone, which made the census silently inert for any in-process test using
3975/// the thread-local switch that the rest of the crate honours. The fill and both
3976/// censuses must agree on when they are live, or a "0" means nothing.
3977pub(crate) fn census_unwritten_final(y: &[u16], u: &[u16], v: &[u16]) {
3978 let Some((scanned, total)) = census_sentinels(y, u, v) else {
3979 return;
3980 };
3981 FINAL_CENSUS_SCANNED.fetch_add(scanned, std::sync::atomic::Ordering::SeqCst);
3982 FINAL_UNWRITTEN_SAMPLES.fetch_add(total, std::sync::atomic::Ordering::SeqCst);
3983}
3984
3985/// The `(scanned, unwritten)` pair both output-point censuses accumulate, or
3986/// `None` when the sentinel fill is not live.
3987///
3988/// Shared so the two censuses cannot drift into disagreeing about what counts
3989/// as unwritten -- the failure this crate's other paired counters exist to
3990/// prevent. `None` (rather than `(0, 0)`) is what keeps a caller from
3991/// publishing a meaningless zero when the fill was off.
3992fn census_sentinels(y: &[u16], u: &[u16], v: &[u16]) -> Option<(usize, usize)> {
3993 if !plane_sentinel_on() {
3994 return None;
3995 }
3996 // Both callers pass planes cropped to the true extent (no padding past it
3997 // reaches either point), so a flat count over each plane IS the
3998 // true-extent count.
3999 let (scanned, total): (usize, usize) = [y, u, v]
4000 .iter()
4001 .map(|p| (p.len(), p.iter().filter(|&&s| s == plane_poison()).count()))
4002 .fold((0, 0), |(a, b), (c, d)| (a + c, b + d));
4003 Some((scanned, total))
4004}
4005
4006/// The scanned half of the pairing for [`GRAINED_UNWRITTEN_SAMPLES`]. A gate
4007/// asserting only `== 0` passes on a build whose census call was deleted.
4008pub(super) static GRAINED_CENSUS_SCANNED: std::sync::atomic::AtomicUsize =
4009 std::sync::atomic::AtomicUsize::new(0);
4010
4011/// Reads and clears [`GRAINED_CENSUS_SCANNED`]; the pairing is the reason it
4012/// exists, exactly as for [`take_final_census_scanned`].
4013pub fn take_grained_census_scanned() -> usize {
4014 GRAINED_CENSUS_SCANNED.swap(0, std::sync::atomic::Ordering::SeqCst)
4015}
4016
4017/// lane-av1graincensus: the SECOND output-point census -- the one
4018/// [`census_unwritten_final`] structurally cannot be.
4019///
4020/// # WHY IT EXISTS
4021///
4022/// `census_unwritten_final` runs at `stream.rs`'s `EC_AV1_FINAL_DUMP` site, which
4023/// is BEFORE `apply_grain`. Every filter (deblock/CDEF/LR/superres) writes in
4024/// place into the same buffer that census scanned, so those stages cannot open a
4025/// hole outside its extent. `apply_grain` is the ONE stage after it that
4026/// allocates a fresh picture -- `uninit_plane`, `Vec::with_capacity` +
4027/// `set_len`, no fill -- and whose soundness rests on a band row partition
4028/// rather than on the type system. Its destination therefore reaches the caller
4029/// having never been looked at by any census, and `lanes/unwritten-dep.report.md`
4030/// §6/§8 explicitly declines to claim otherwise.
4031///
4032/// # WHAT IT IS WORTH ONLY IF THE FILL IS LIVE
4033///
4034/// Counting `== plane_poison()` over an uninitialised buffer is a census that
4035/// can only ever report ~0: garbage is arbitrary, so a hole survives with
4036/// probability ~1/65536 rather than always. `uninit_plane` therefore fills with
4037/// the poison when [`plane_sentinel_on`] -- under the SAME predicate
4038/// [`fresh_plane`] honours -- so "the band copy wrote every sample" becomes a
4039/// measurement instead of an assumption. With the sentinel off (every shipped
4040/// build) nothing here runs and `uninit_plane` keeps its corner-cut.
4041pub(crate) fn census_unwritten_grained(y: &[u16], u: &[u16], v: &[u16]) {
4042 let Some((scanned, total)) = census_sentinels(y, u, v) else {
4043 return;
4044 };
4045 GRAINED_CENSUS_SCANNED.fetch_add(scanned, std::sync::atomic::Ordering::SeqCst);
4046 GRAINED_UNWRITTEN_SAMPLES.fetch_add(total, std::sync::atomic::Ordering::SeqCst);
4047}
4048
4049thread_local! {
4050 /// lane-sb128c r8: INTRA (key-frame) 128x64 blocks decoded at the 128
4051 /// root's HORZ arm, and 64x128 ones at its VERT arm.
4052 pub(crate) static INTRA_SB128_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4053 pub(crate) static INTRA_SB128_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4054 /// Those blocks by resolved intra `tx_depth` (0 = TX_64X64 units,
4055 /// 1 = TX_32X32, 2 = TX_16X16) -- proof the depth symbol is really read.
4056 pub(crate) static INTRA_SB128_DEPTH_HITS: std::cell::Cell<[usize; 3]> = const { std::cell::Cell::new([0; 3]) };
4057 /// lane-inter128intra r1: the same shapes decoded on the INTER block path
4058 /// (an intra-coded PARTITION_HORZ/VERT half of a 128 superblock inside an
4059 /// inter frame) -- (128x64, 64x128).
4060 pub(crate) static INTRA128_IN_INTER_HITS: std::cell::Cell<[usize; 2]> = const { std::cell::Cell::new([0; 2]) };
4061 /// lane-t900 r17: skipped INTER blocks whose `read_block_tx_size` still
4062 /// handed back var-tx leaves, so the per-transform-unit luma publication
4063 /// loop never ran and the block has to clear its own luma coefficient
4064 /// contexts (libaom `av1_reset_entropy_context`). Every 128 root under
4065 /// `TX_MODE_LARGEST` is one; the counter is what keeps that reset's gate
4066 /// non-vacuous.
4067 pub(crate) static SKIP_VARTX_LUMA_RESET_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4068 /// lane-lossless128: an intra 128-axis (BLOCK_128X64/64X128) block decoded
4069 /// on a LOSSLESS frame, where every plane is coded as TX_4X4 units (the
4070 /// frame's `tx_mode` is forced `ONLY_4X4`). Keeps the gate that owns this
4071 /// shape non-vacuous -- a stream that never codes one reads 0.
4072 pub(crate) static INTRA128_LOSSLESS_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4073 /// lane-av1-128rectspan: chroma transform units of a 128-root HORZ/VERT
4074 /// intra block re-stamped by the end-of-block replay
4075 /// (`record_split_luma_rect` clobbers the per-unit contexts the chroma
4076 /// walk published, so every unit replays its own state after it). A
4077 /// non-skip 128x64/64x128 block codes `nch_x * cn * 2 + nch_y * cn_h * 2`
4078 /// of them, so this reads 0 on any stream that never codes one -- the
4079 /// non-vacuity anchor for the replay's own gate.
4080 pub(crate) static SB128RECT_CHROMA_REPLAY_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4081 /// ... and the number of non-skip 128-root rect BLOCKS whose two LUMA-MI
4082 /// spans differ (`luma_span = chroma_tx << ss_x` vs
4083 /// `luma_span_h = chroma_tx << ss_y`). lane-av1422lift: the doc here used
4084 /// to read "Zero on every stream this decoder admits ... 4:2:2 ... is
4085 /// refused by name at the sequence header", and that was TRUE. Admitting
4086 /// 4:2:2 genuinely made this counter able to fire, and it does fire:
4087 /// measured, `422_intrabc_sb128_strip.obu` and
4088 /// `422_intrabc_sb128_strip_notxsearch.obu` each read
4089 /// `replay = 72, mismatch = 9`; the other 19 committed 4:2:2 cells read 0.
4090 ///
4091 /// lane-av1422mismatch9: the predicate is the span DIFFERENCE, which at
4092 /// ss (1, 0) is true BY CONSTRUCTION for every 128-root rect block -- so
4093 /// this is a shape test ("a 4:2:2-shaped block replayed"), NOT a
4094 /// divergence test, and it does not witness the lane-av1-128rectspan
4095 /// defect it was named for (that defect passed `luma_span` to both axes;
4096 /// the source-scan arm in
4097 /// `the_422_block_128rect_chroma_chunk_gather_stays_per_axis` is what
4098 /// pins the per-axis spelling). It is not a pixel-miss signature either:
4099 /// the replay re-stamps with the same per-axis pair the in-loop walk
4100 /// stamped with, and `record_mi_chroma` writes only the `left`/`above`
4101 /// context arrays -- zero pixel samples. Both pins are byte-exact against
4102 /// ffmpeg (`the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_
4103 /// exact`, all five frames, every plane).
4104 ///
4105 /// **Nothing asserts zero here, and nothing should**: a zero assert would
4106 /// red on a provably correct cell. The measured NINE is asserted instead,
4107 /// in `the_422_block_128rect_chroma_chunk_gather_stays_per_axis` (with
4108 /// this reasoning in its message), so a change in the count is a red gate
4109 /// rather than a silent drift.
4110 ///
4111 /// The pair's other reader is `sb128rect_chroma_replay_hits` on a 4:4:4
4112 /// stream, where the unit's luma width and height are equal so the
4113 /// mismatch half is structurally zero -- a zero that is a statement about
4114 /// that stream, not about the format.
4115 pub(crate) static SB128RECT_REPLAY_SPAN_MISMATCH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4116}
4117
4118/// [`SKIP_VARTX_LUMA_RESET_HITS`], for a gate's own before/after delta.
4119pub fn skip_vartx_luma_reset_hits() -> usize {
4120 SKIP_VARTX_LUMA_RESET_HITS.with(std::cell::Cell::get)
4121}
4122
4123/// [`INTRA128_LOSSLESS_HITS`], for a gate's own before/after delta.
4124pub(crate) fn intra128_lossless_hits() -> usize {
4125 INTRA128_LOSSLESS_HITS.with(std::cell::Cell::get)
4126}
4127
4128/// [`INTRA128_IN_INTER_HITS`], for a gate's own before/after delta.
4129pub(crate) fn intra128_in_inter_hits() -> [usize; 2] {
4130 INTRA128_IN_INTER_HITS.with(std::cell::Cell::get)
4131}
4132
4133/// [`INTRA_SB128_HORZ_HITS`] / [`INTRA_SB128_VERT_HITS`] /
4134/// [`INTRA_SB128_DEPTH_HITS`], for a gate's own before/after delta.
4135pub(crate) fn intra_sb128_hits() -> (usize, usize, [usize; 3]) {
4136 (
4137 INTRA_SB128_HORZ_HITS.with(std::cell::Cell::get),
4138 INTRA_SB128_VERT_HITS.with(std::cell::Cell::get),
4139 INTRA_SB128_DEPTH_HITS.with(std::cell::Cell::get),
4140 )
4141}
4142
4143/// [`SB128RECT_CHROMA_REPLAY_HITS`] (chroma units re-stamped by
4144/// `decode_block_128rect`'s end-of-block replay) and
4145/// [`SB128RECT_REPLAY_SPAN_MISMATCH_HITS`] (replays whose stamped height was
4146/// not the unit's own), for a gate's own before/after delta.
4147pub(crate) fn sb128rect_chroma_replay_hits() -> (usize, usize) {
4148 (
4149 SB128RECT_CHROMA_REPLAY_HITS.with(std::cell::Cell::get),
4150 SB128RECT_REPLAY_SPAN_MISMATCH_HITS.with(std::cell::Cell::get),
4151 )
4152}
4153
4154/// Records one block's shape. The table is ordered by measured frequency over
4155/// the three witnesses the census gate decodes, so the common square shapes
4156/// leave the scan on their first comparison.
4157pub(super) fn census_inter_block_shape(side: usize, w: usize, h: usize) {
4158 let bit = match INTER_BLOCK_SHAPES.iter().position(|&s| s == (side, w, h)) {
4159 Some(i) => 1u32 << i,
4160 None => INTER_BLOCK_SHAPE_UNLISTED,
4161 };
4162 let seen = inter_block_shape_mask();
4163 if seen & bit == 0 {
4164 INTER_BLOCK_SHAPE_MASK.with(|c| c.set(seen | bit));
4165 }
4166}
4167
4168/// lane-cdefstrip r1 instrument, run for every frame BEFORE either of
4169/// [`apply_cdef`]'s early returns.
4170pub(super) fn cdef_scan_counters(skip_grid: &Neighbours) {
4171 let _ = skip_grid;
4172 hit_do! {
4173 let mut r = 0usize;
4174 while r < skip_grid.mi_rows {
4175 let mut c = 0usize;
4176 while c < skip_grid.mi_cols {
4177 if (0..2).any(|rr| {
4178 (0..2).any(|cc| {
4179 !skip_grid
4180 .blk_grid
4181 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))
4182 .is_none_or(|x| x.written)
4183 })
4184 }) {
4185 hit!(CDEF_UNWRITTEN_SKIP_UNITS);
4186 if crate::envflags::env_flag!("EC_AV1_DEBUG_CDEF_BAND") {
4187 eprintln!("cdef band unwritten at mi ({r},{c}) px ({},{})", r * 4, c * 4);
4188 }
4189 }
4190 let cell = |rr: usize, cc: usize| {
4191 skip_grid
4192 .blk_grid
4193 .get((r + rr) * skip_grid.skip_grid_cols_mi + (c + cc))
4194 .is_some_and(|x| x.skip)
4195 };
4196 let first = cell(0, 0);
4197 if (0..2).any(|rr| (0..2).any(|cc| cell(rr, cc) != first)) {
4198 hit!(CDEF_MIXED_SKIP_UNITS);
4199 }
4200 c += 2;
4201 }
4202 r += 2;
4203 }
4204 }
4205}
4206
4207// lane-sb128 r2: the 128x128 superblock root, shared by the key-frame and
4208// the inter tile loop. Its loop-restoration units are read once for the whole
4209// 128x128 (spec 5.11.57 is called with the superblock's own size), then one
4210// partition symbol off the `BLOCK_128X128` CDF (8 symbols, no HORZ_4/VERT_4)
4211// decides the root -- only SPLIT recurses into the four 64x64 quadrants this
4212// decoder codes, the other seven arms refuse by name.
4213thread_local! {
4214 /// How many 128x128 superblock roots resolved to `PARTITION_NONE` -- one
4215 /// whole 128x128 block (lane-sb128b r1's gate counter).
4216 pub(crate) static PART128_NONE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4217 /// 128 roots that resolved to PARTITION_HORZ (two 128x64 pieces, or one
4218 /// when the bottom half is out of frame) -- lane-sb128c r7.
4219 pub(crate) static PART128_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4220 /// 128 roots that resolved to PARTITION_VERT (two 64x128 pieces).
4221 pub(crate) static PART128_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4222 /// Of those, the ones decided by the GATHERED bit at a frame edge -- the
4223 /// only shape a 1080p (mi_rows = 270) stream reaches.
4224 pub(crate) static PART128_EDGE_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4225 pub(crate) static PART128_EDGE_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4226 /// lane-sb128c r9: 128 roots that resolved to one of the four AB shapes,
4227 /// in `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`, `_VERT_B` order.
4228 pub(crate) static PART128_AB_HITS: std::cell::Cell<[usize; 4]> = const { std::cell::Cell::new([0; 4]) };
4229}
4230
4231/// [`PART128_AB_HITS`], for a gate's own before/after delta.
4232pub(crate) fn part128_ab_hits() -> [usize; 4] {
4233 PART128_AB_HITS.with(std::cell::Cell::get)
4234}
4235
4236/// [`PART128_NONE_HITS`], for a gate's own before/after delta.
4237#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4238pub(crate) fn part128_none_hits() -> usize {
4239 PART128_NONE_HITS.with(std::cell::Cell::get)
4240}
4241
4242/// [`PART128_HORZ_HITS`], for a gate's own before/after delta.
4243#[allow(dead_code)] // gate counter accessor with no reader yet; the counter itself is live
4244pub(crate) fn part128_horz_hits() -> usize {
4245 PART128_HORZ_HITS.with(std::cell::Cell::get)
4246}
4247
4248/// [`PART128_VERT_HITS`], for a gate's own before/after delta.
4249#[allow(dead_code)] // gate counter accessor with no reader yet; the counter itself is live
4250pub(crate) fn part128_vert_hits() -> usize {
4251 PART128_VERT_HITS.with(std::cell::Cell::get)
4252}
4253
4254/// [`PART128_EDGE_HORZ_HITS`] -- gathered-bit HORZ at the bottom frame edge.
4255pub(crate) fn part128_edge_horz_hits() -> usize {
4256 PART128_EDGE_HORZ_HITS.with(std::cell::Cell::get)
4257}
4258
4259/// [`PART128_EDGE_VERT_HITS`] -- gathered-bit VERT at the right frame edge.
4260pub(crate) fn part128_edge_vert_hits() -> usize {
4261 PART128_EDGE_VERT_HITS.with(std::cell::Cell::get)
4262}
4263
4264thread_local! {
4265 /// How many CHROMA transform units were coded inside a block whose uv
4266 /// plane block is more than one unit (lane-sb128b r2 -- only a 128x128
4267 /// block, four per plane).
4268 pub(crate) static CHROMA_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4269}
4270
4271thread_local! {
4272 /// lane-av1h5: how many blocks had their leaf walk actually PERMUTED into
4273 /// libaom's chunk-major order by [`mu_chunk_order`] -- a block above 64
4274 /// whose sort was not a no-op. Deliberately not "took the order": a
4275 /// no-op ordering change must read 0 so a gate cannot look armed.
4276 pub(crate) static MU_CHUNK_ORDER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4277 /// lane-av1txctxband2: SQUARE lossless blocks on an INTER frame whose
4278 /// `set_txfm_ctxs` publish CHANGED at least one above-band cell it covers
4279 /// (the cell did not already hold the published size), so a later
4280 /// `get_tx_size_context` / `txfm_partition_context` reader in the same
4281 /// tile column reads a value this publish produced. Zero on an intra-only
4282 /// frame (where `fill_lf_grid_rect_inner` publishes the same 4x4 value at
4283 /// the same footprint).
4284 ///
4285 /// CORRECTED 2026-09-30 (refutation pass `lanes/refute-av1txctxband2`):
4286 /// this doc previously claimed the hit meant "overwrote a size some
4287 /// earlier block left" and that a wholly-lossless all-non-skip stream
4288 /// leaves it at zero. MEASURED FALSE -- `420_lossless_tallinter_8x16.obu`
4289 /// fires **48**, all of them first touches of a column still at
4290 /// `TXFM_CTX_INIT`; `420_lossless_arf_1to4_320x240_5f.obu` fires 320, 53 of
4291 /// them first touches. Of the pin's 944, **183 are first-touch**. The
4292 /// predicate tests "the cell did not already hold this value", which is
4293 /// the decision that matters (no reader, no intra-only frame, no unchanged
4294 /// column still reads 0), but it is NOT the strictly narrower causal claim
4295 /// the old text made.
4296 pub(crate) static LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4297}
4298
4299/// [`MU_CHUNK_ORDER_HITS`], for a gate's own before/after delta.
4300#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4301pub(crate) fn mu_chunk_order_hits() -> usize {
4302 MU_CHUNK_ORDER_HITS.with(std::cell::Cell::get)
4303}
4304
4305/// [`LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS`] -- square lossless inter blocks
4306/// whose `set_txfm_ctxs` publish overwrote a size an earlier block of the
4307/// same frame had left in the above band, for a gate's own before/after
4308/// delta.
4309#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4310pub(crate) fn lossless_sq_txfm_band_overwrite_hits() -> usize {
4311 LOSSLESS_SQ_TXFM_BAND_OVERWRITE_HITS.with(std::cell::Cell::get)
4312}
4313
4314/// [`CHROMA_SPLIT_TX_HITS`], for a gate's own before/after delta.
4315#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4316pub(crate) fn chroma_split_tx_hits() -> usize {
4317 CHROMA_SPLIT_TX_HITS.with(std::cell::Cell::get)
4318}
4319
4320thread_local! {
4321 /// How many INTRA leaves of an inter frame's 8x8 block ran the lossless
4322 /// 4:4:4 chroma walk ([`read_intra_chroma_lossless`], lane-av1-llintra8)
4323 /// -- one bump per leaf, four units per plane inside it. A gate proving
4324 /// the arm must see this nonzero; CHROMA_SPLIT_TX_HITS alone cannot
4325 /// attribute its bumps to THIS leaf.
4326 pub(crate) static LLINTRA8_CHROMA_WALK_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4327}
4328
4329/// [`LLINTRA8_CHROMA_WALK_HITS`]: lossless 4:4:4 chroma walks through an
4330/// inter frame's 8x8 INTRA leaf.
4331pub fn llintra8_chroma_walk_hits() -> usize {
4332 LLINTRA8_CHROMA_WALK_HITS.with(|c| c.get())
4333}
4334
4335thread_local! {
4336 /// lane-av1sub8rect444: how many of `decode_intra_sub8_leaf`'s 8x4/4x8
4337 /// INTRA leaves ran the lossless 4:4:4 per-unit chroma walk (two TX_4X4
4338 /// units per plane, plane-major) instead of one TX_8X4/TX_4X8 rect unit
4339 /// -- the shape whose unit count AND skip ctx the rect read got wrong.
4340 /// A gate proving the arm fired; CHROMA_SPLIT_TX_HITS cannot attribute
4341 /// its bumps to THIS leaf.
4342 pub(crate) static LLSUB8RECT444_CHROMA_WALK_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4343}
4344
4345/// [`LLSUB8RECT444_CHROMA_WALK_HITS`]: lossless 4:4:4 chroma walks through a
4346/// sub-8 8x4/4x8 INTRA leaf.
4347pub fn llsub8rect444_chroma_walk_hits() -> usize {
4348 LLSUB8RECT444_CHROMA_WALK_HITS.with(|c| c.get())
4349}
4350
4351thread_local! {
4352 /// lane-av1444chr: how many chroma units resolved their `tx_type` from the
4353 /// luma leaf covering their OWN quadrant instead of the block-level
4354 /// (`first_tx_type`) one -- the route this lane corrected.
4355 /// `CHROMA_SPLIT_TX_HITS` cannot attribute its bumps to it: every split
4356 /// chroma unit bumps that one.
4357 pub(crate) static CHROMA_QUAD_LEAF_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4358}
4359
4360thread_local! {
4361 /// Of those, how many resolved a type that DIFFERS from the block-level one
4362 /// -- the exact condition lane-av1444chr measured wrong: over a luma leaf
4363 /// that coded nothing the map cell is `DCT_DCT` while the top-left leaf's
4364 /// is `IDTX`. A gate proving the corrected route fired is NOT enough on
4365 /// its own (a block whose four leaves agree changes zero pixels); this is
4366 /// the number that says the route changed an answer.
4367 pub(crate) static CHROMA_QUAD_LEAF_TX_DIFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4368}
4369
4370thread_local! {
4371 /// lane-av1f9singleland: the SINGLE-REFERENCE copy of
4372 /// [`CHROMA_QUAD_LEAF_TX_HITS`], and the half of its
4373 /// [`CHROMA_QUAD_LEAF_TX_DIFF_HITS`] that belongs to that arm.
4374 ///
4375 /// Why a separate pair rather than trusting the shared counters: the
4376 /// shared ones are bumped from BOTH arms of the four-unit 4:4:4 chroma
4377 /// arm, so a green witness on them says nothing about which arm produced
4378 /// the hits. `decode_inter_block` has two textually parallel copies of
4379 /// that arm -- the compound prediction arm (the `build` closure) and the
4380 /// single-reference arm -- and a refactor can delete or revert either one
4381 /// while the other keeps the shared total non-zero. Measured on the pinned
4382 /// witness `fixtures/444_quad_leaf_tx_type.obu`: 96 units resolve through
4383 /// the covering leaf, and 88 of them are the single-reference arm's, so
4384 /// the shared counter is 92% single-reference and the compound arm alone
4385 /// would be a 4-unit sample of the route it appears to witness.
4386 pub(crate) static CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4387}
4388
4389thread_local! {
4390 /// Of [`CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS`], how many resolved a type
4391 /// that DIFFERS from the block-level one. This is the arm's own non-vacuity
4392 /// bar: a route count alone stays green through a no-op resolve, because
4393 /// on a block whose four luma leaves all agree the per-quadrant value and
4394 /// the block-level one are the same answer. Mutating only the
4395 /// single-reference arm's `Some(cu_tx_type)` back to `Some(luma_tx_type)`
4396 /// turns the witness red with 777 bytes differing in decode-order frame 1.
4397 pub(crate) static CHROMA_QUAD_LEAF_TX_SINGLEREF_DIFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4398}
4399
4400/// [`CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS`]: single-reference-arm chroma units
4401/// that took their type from the covering luma leaf.
4402#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4403pub(crate) fn chroma_quad_leaf_tx_singleref_hits() -> usize {
4404 CHROMA_QUAD_LEAF_TX_SINGLEREF_HITS.with(std::cell::Cell::get)
4405}
4406
4407/// [`CHROMA_QUAD_LEAF_TX_SINGLEREF_DIFF_HITS`]: of those, the units whose
4408/// covering leaf's type differs from the block-level one.
4409#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4410pub(crate) fn chroma_quad_leaf_tx_singleref_diff_hits() -> usize {
4411 CHROMA_QUAD_LEAF_TX_SINGLEREF_DIFF_HITS.with(std::cell::Cell::get)
4412}
4413
4414/// [`CHROMA_QUAD_LEAF_TX_HITS`]: chroma units that took their type from the
4415/// covering luma leaf.
4416#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4417pub(crate) fn chroma_quad_leaf_tx_hits() -> usize {
4418 CHROMA_QUAD_LEAF_TX_HITS.with(std::cell::Cell::get)
4419}
4420
4421/// [`CHROMA_QUAD_LEAF_TX_DIFF_HITS`]: chroma units whose covering leaf's type
4422/// differs from the block-level one.
4423#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4424pub(crate) fn chroma_quad_leaf_tx_diff_hits() -> usize {
4425 CHROMA_QUAD_LEAF_TX_DIFF_HITS.with(std::cell::Cell::get)
4426}
4427
4428thread_local! {
4429 /// lane-av1chrtx: chroma units of a RECT inter block
4430 /// ([`read_inter_rect_chroma`], the sibling of the 4:4:4 four-unit arms)
4431 /// that resolved their `tx_type` from the luma leaf covering their OWN
4432 /// quadrant instead of the block-level one. A SEPARATE counter from
4433 /// [`CHROMA_QUAD_LEAF_TX_HITS`] on purpose: that one gates a 4:2:0 control
4434 /// that must stay at exactly 0, and this route IS reachable at 4:2:0, so
4435 /// sharing the counter would destroy that control's meaning.
4436 pub(crate) static CHROMA_RECT_LEAF_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4437}
4438
4439thread_local! {
4440 /// Of those, how many resolved a type that DIFFERS from the block-level
4441 /// one -- the condition that changes pixels. A route counter alone fires
4442 /// on every multi-unit rect chroma read, including the blocks whose
4443 /// leaves all agree (the exact shape a no-op fix looks green on).
4444 pub(crate) static CHROMA_RECT_LEAF_TX_DIFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4445}
4446
4447/// [`CHROMA_RECT_LEAF_TX_HITS`]: rect chroma units that took their type from
4448/// the covering luma leaf.
4449#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4450pub(crate) fn chroma_rect_leaf_tx_hits() -> usize {
4451 CHROMA_RECT_LEAF_TX_HITS.with(std::cell::Cell::get)
4452}
4453
4454/// [`CHROMA_RECT_LEAF_TX_DIFF_HITS`]: of those, the units whose covering
4455/// leaf's type differs from the block-level one.
4456#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4457pub(crate) fn chroma_rect_leaf_tx_diff_hits() -> usize {
4458 CHROMA_RECT_LEAF_TX_DIFF_HITS.with(std::cell::Cell::get)
4459}