forge
Explore
Log in

Don't you dare go Hollow

Merge lane/av1floorshift: the floor-shift chroma planes were already per-axis

Browse files at this commit

853835e55559264e15515c58d43549286eb1e5d3Ahmet Kaan GümüşParent: 9ceb04635997f1
The two sites the earlier reports named as floor->> allocators had already been
ported. decode_key_frame_tile_with_cdfs and decode_inter_tile allocate
(width >> ss_x, height >> ss_y). width and height are multiples of 4 (block grid
times 32, or mi times 4) and ss is a 1-bit header field, so the shift equals
round_ss for every k and every ss in {0,1}. Structurally exact, not corpus luck.

The odd cell is where a floor would show: 420_odd65x65_key is 65x65, crop 33x33,
not a floored 32x32. Counted shortfall 0 and crop-disagreement 0 on that cell, on
422_key_64x64, and on a 4:4:4 witness, with the allocator actually invoked on all
three. A static gate exhausts mi 1..=512 and ss in {0,1} on both the coded and
true extents. 4:4:0 is uncodable (subsampling_y needs subsampling_x) and is spelled
out rather than swept. No production code changed. The other halving hits in the
file are not plane allocations, are already closed, or are test-only.
crates/ec-av1/src/decode.rsmodified+106 -0
@@ -2162,6 +2162,110 @@ pub(crate) fn skip_arm_chroma_rect_shapes() -> usize {
2162 SKIP_ARM_CHROMA_RECT_SHAPES.with(|c| c.get())2162 SKIP_ARM_CHROMA_RECT_SHAPES.with(|c| c.get())
2163 }2163 }
2164 2164
2165+// lane-av1floorshift: the two FRAME chroma plane allocators
2166+// (`decode_key_frame_tile_with_cdfs` and `decode_inter_tile`'s `PlaneBuf` trio)
2167+// size U and V as `(width >> ss_x) x (height >> ss_y)` with `width`/`height`
2168+// the 32-aligned coded size and `true_width`/`true_height` its `mi_cols * 4`
2169+// counterpart. `lanes/av1subsizesweep.report.md` named these "floor-`>>`
2170+// chroma plane allocators -- shape assumption at frame edges; not probed":
2171+// the `>>` FLOORS where libaom's own producer CROPS (`round_ss`), so the
2172+// question was whether an odd frame dimension makes the allocation one sample
2173+// short of the extent every chroma walk inside the tile indexes.
2174+//
2175+// `FRAME_CHROMA_ALLOC_SHORT_SAMPLES` is the measured answer: the number of
2176+// samples by which the allocated `cw * ch` fell SHORT of the `round_ss`
2177+// extent the tile's chroma walks may address, summed over every frame. It
2178+// reads the allocation's real length against a recomputed `round_ss` bound, so
2179+// it measures the shape rather than proxying a condition. Restoring a bare
2180+// `>> 1` on either axis drives it strictly positive at an odd dimension.
2181+thread_local! {
2182+ static FRAME_CHROMA_ALLOC_SHORT_SAMPLES: std::cell::Cell<usize> =
2183+ const { std::cell::Cell::new(0) };
2184+}
2185+
2186+// lane-av1floorshift: frames whose coded luma dimension made `>>` and
2187+// `round_ss` DISAGREE on a chroma axis -- i.e. the only frames on which the
2188+// floor-vs-crop question is even decidable. Zero on every even dimension,
2189+// which is why a gate asserting `FRAME_CHROMA_ALLOC_SHORT_SAMPLES == 0` is
2190+// vacuous without this: on an even frame the two forms are the same number
2191+// and the shortfall cannot move.
2192+thread_local! {
2193+ static FRAME_CHROMA_ALLOC_CROP_SHAPES: std::cell::Cell<usize> =
2194+ const { std::cell::Cell::new(0) };
2195+}
2196+
2197+// How many times a frame chroma plane allocator ran at all -- one per frame,
2198+// from either the key-frame or the inter call site. The non-vacuity arm: the
2199+// other two counters are ZERO on every input that exists (see
2200+// [`note_frame_chroma_alloc`]), so a gate that only asserted them would pass
2201+// with the instrument removed entirely.
2202+thread_local! {
2203+ static FRAME_CHROMA_ALLOC_CALLS: std::cell::Cell<usize> =
2204+ const { std::cell::Cell::new(0) };
2205+}
2206+
2207+/// Current value of [`FRAME_CHROMA_ALLOC_CALLS`].
2208+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2209+pub(crate) fn frame_chroma_alloc_calls() -> usize {
2210+ FRAME_CHROMA_ALLOC_CALLS.with(|c| c.get())
2211+}
2212+
2213+/// Current value of [`FRAME_CHROMA_ALLOC_SHORT_SAMPLES`].
2214+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2215+pub(crate) fn frame_chroma_alloc_short_samples() -> usize {
2216+ FRAME_CHROMA_ALLOC_SHORT_SAMPLES.with(|c| c.get())
2217+}
2218+
2219+/// Current value of [`FRAME_CHROMA_ALLOC_CROP_SHAPES`].
2220+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2221+pub(crate) fn frame_chroma_alloc_crop_shapes() -> usize {
2222+ FRAME_CHROMA_ALLOC_CROP_SHAPES.with(|c| c.get())
2223+}
2224+
2225+/// The census both frame chroma plane allocators share. `shape` is the frame's
2226+/// own 32-aligned coded `(width, height)`, `ss` its `(ss_x, ss_y)`.
2227+///
2228+/// `round_ss` is libaom's chroma CROP (`av1_round_shift`), the extent the
2229+/// committed reference planes are stored at and the bound every chroma walk
2230+/// inside the tile is clamped against.
2231+///
2232+/// `alloc` is the allocator's OWN `(cw, ch)` -- the numbers that size the
2233+/// `PlaneBuf` -- not a recomputation of them. That is what makes the gate
2234+/// bite: the shortfall is a difference between what was allocated and what the
2235+/// tile may address, so replacing the shift with a bare `>> 1` (the 4:2:0-only
2236+/// form this lane's target class is made of) moves it on the 4:2:2 and 4:4:4
2237+/// witnesses, where the correct shift and the hardcoded one are different
2238+/// numbers. A counter that recomputed `shape >> ss` beside the allocation
2239+/// would have read the same value either way and proved nothing.
2240+fn note_frame_chroma_alloc(shape: (usize, usize), alloc: (usize, usize), ss: (usize, usize)) {
2241+ hit!(FRAME_CHROMA_ALLOC_CALLS);
2242+ let (need_w, need_h) = (round_ss(shape.0, ss.0), round_ss(shape.1, ss.1));
2243+ // Decidability: the floor and the crop are the same number on this frame,
2244+ // so the shortfall below is the same number the two forms would have given.
2245+ if (need_w, need_h) != (shape.0 >> ss.0, shape.1 >> ss.1) {
2246+ hit!(FRAME_CHROMA_ALLOC_CROP_SHAPES);
2247+ if crate::envflags::env_flag!("EC_AV1_CHROMA_ALLOC_SWEEP") {
2248+ eprintln!(
2249+ "CHROMA_ALLOC luma={}x{} ss={:?} floor={}x{} round_ss={}x{} alloc={}x{}",
2250+ shape.0,
2251+ shape.1,
2252+ ss,
2253+ shape.0 >> ss.0,
2254+ shape.1 >> ss.1,
2255+ need_w,
2256+ need_h,
2257+ alloc.0,
2258+ alloc.1,
2259+ );
2260+ }
2261+ }
2262+ let want = need_w * need_h;
2263+ let got = alloc.0 * alloc.1;
2264+ if want > got {
2265+ hit_do!(FRAME_CHROMA_ALLOC_SHORT_SAMPLES.with(|c| c.set(c.get() + want - got)));
2266+ }
2267+}
2268+
2165 /// Current value of [`CHROMA422_SQUARE_HITS`].2269 /// Current value of [`CHROMA422_SQUARE_HITS`].
2166 // lane-av1-422b: `pub` so `examples/decode_probe.rs` can census it the way2270 // lane-av1-422b: `pub` so `examples/decode_probe.rs` can census it the way
2167 // it does every other capability counter.2271 // it does every other capability counter.
@@ -36280,6 +36384,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
36280 plane: 0,36384 plane: 0,
36281 };36385 };
36282 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));36386 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));
36387+ note_frame_chroma_alloc((width, height), (cw, ch), (ss_x(fctx), ss_y(fctx)));
36283 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));36388 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));
36284 let mut u = PlaneBuf {36389 let mut u = PlaneBuf {
36285 data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),36390 data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),
@@ -54059,6 +54164,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
54059 plane: 0,54164 plane: 0,
54060 };54165 };
54061 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));54166 let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));
54167+ note_frame_chroma_alloc((width, height), (cw, ch), (ss_x(fctx), ss_y(fctx)));
54062 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));54168 let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));
54063 let mut u = PlaneBuf {54169 let mut u = PlaneBuf {
54064 data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),54170 data: std::borrow::Cow::Owned(fresh_plane(cw * ch, ctw, cth, cw, ch)),
crates/ec-av1/src/stream.rsmodified+163 -0
@@ -3208,6 +3208,169 @@ pub(crate) mod tests {
3208 );3208 );
3209 }3209 }
3210 3210
3211+ /// lane-av1floorshift: the two FRAME chroma plane allocators
3212+ /// (`decode_key_frame_tile_with_cdfs`, `decode_inter_tile`) size U and V as
3213+ /// `(width >> ss_x) x (height >> ss_y)`. `lanes/av1subsizesweep.report.md`
3214+ /// named them "floor-`>>` chroma plane allocators -- shape assumption at
3215+ /// frame edges; not probed" and left them open. This is the probe.
3216+ ///
3217+ /// **The verdict is ALREADY CORRECT, and it is structural, not
3218+ /// corpus-luck.** `width`/`height` are `block_grid(mi_cols, mi_rows) *
3219+ /// BLOCK` (`BLOCK == 32`) and the allocator is handed those, not the frame's
3220+ /// own `true_width`/`true_height`: both axes are multiples of 32, and
3221+ /// `ss_x`/`ss_y` are the sequence header's single-bit subsampling fields,
3222+ /// so `ss <= 1` on every stream that exists. `32k >> ss == round_ss(32k, ss)`
3223+ /// for every `k` and every `ss <= 1` -- the `>>` can never floor one sample
3224+ /// short of libaom's own chroma crop, at a frame edge or anywhere else. The
3225+ /// static half of the gate below proves that exhaustively over every
3226+ /// `mi_cols`/`mi_rows` this decoder admits.
3227+ ///
3228+ /// The corpus half keeps the instrument honest: it decodes one frame per
3229+ /// selectable subsampling cell and asserts the allocators were REACHED
3230+ /// (`frame_chroma_alloc_calls` moved), so a green run cannot be the census
3231+ /// having been wired to nothing.
3232+ ///
3233+ /// Witnesses, all byte-pinned (`size`, `fnv1a64`), chosen to cover all
3234+ /// three selectable cells and both allocators:
3235+ ///
3236+ /// | file | cell | frame | covers |
3237+ /// |---|---|---|---|
3238+ /// | `420_odd65x65_key.obu` | 4:2:0, **odd** 65x65 | key | key allocator, the odd-dimension cell where a floor WOULD show |
3239+ /// | `422_key_64x64.obu` | 4:2:2 (1,0) | key | key allocator, half-width/full-height |
3240+ /// | `444_intrabc_rect4_witness.obu` | 4:4:4 (0,0) | key | key allocator, the `ss == 0` cell where `>> ss` is the identity |
3241+ ///
3242+ /// 4:4:0 (`0,1`) is excluded and cannot be added: libaom's
3243+ /// `av1_read_color_config` asserts `subsampling_y == 0` when
3244+ /// `subsampling_x == 0`, and no of 256 header bytes reads back `(0,1)` --
3245+ /// the reader census at `the_reader_never_produces_440` names it.
3246+ #[test]
3247+ fn the_frame_chroma_planes_are_allocated_on_the_per_axis_floor_that_never_rounds() {
3248+ const NAME: &str =
3249+ "the_frame_chroma_planes_are_allocated_on_the_per_axis_floor_that_never_rounds";
3250+ let _gate_lock = lock_gate_counters();
3251+ for (file, bytes, fp, cell, ss) in [
3252+ (
3253+ "420_odd65x65_key.obu",
3254+ 2305usize,
3255+ 0xf55645c4b139e8f7u64,
3256+ "4:2:0",
3257+ (1usize, 1usize),
3258+ ),
3259+ (
3260+ "422_key_64x64.obu",
3261+ 755,
3262+ 0x87fc569cf53bcbc6,
3263+ "4:2:2",
3264+ (1, 0),
3265+ ),
3266+ (
3267+ "444_intrabc_rect4_witness.obu",
3268+ 1016,
3269+ 0x27c2fad540472994,
3270+ "4:4:4",
3271+ (0, 0),
3272+ ),
3273+ ] {
3274+ let data = std::fs::read(crate_pin(file))
3275+ .unwrap_or_else(|e| panic!("{NAME}: the committed pin {file} is missing ({e})"));
3276+ assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted");
3277+ assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted");
3278+ let calls_before = crate::decode::frame_chroma_alloc_calls();
3279+ let short_before = crate::decode::frame_chroma_alloc_short_samples();
3280+ let crop_before = crate::decode::frame_chroma_alloc_crop_shapes();
3281+ let frames = decode_stream(&data)
3282+ .unwrap_or_else(|e| panic!("{NAME}: {file} ({cell}) refused: {e}"));
3283+ let calls = crate::decode::frame_chroma_alloc_calls() - calls_before;
3284+ assert!(
3285+ calls >= frames.len(),
3286+ "{NAME}: {file} ({cell}) decoded {} frames but the chroma plane allocator ran \
3287+ {calls} times -- the instrument is not on the path this gate claims to cover",
3288+ frames.len()
3289+ );
3290+ // The shape the allocator owes the tile, and the shape the output
3291+ // crop owes the caller: libaom's chroma CROP of the frame's own
3292+ // dimensions (`av1_round_shift`), which is what
3293+ // `decode_key_frame_tile_with_cdfs`'s `Picture` crop uses. At the
3294+ // odd 65x65 4:2:0 cell this is 33x33 -- 1089 samples, NOT the
3295+ // floor 32x32 an `>>` short of the true extent would have left.
3296+ for (i, f) in frames.iter().enumerate() {
3297+ let (cw, ch) = (
3298+ crate::decode::round_ss(f.width, ss.0),
3299+ crate::decode::round_ss(f.height, ss.1),
3300+ );
3301+ assert_eq!(
3302+ (f.u.len(), f.v.len()),
3303+ (cw * ch, cw * ch),
3304+ "{NAME}: {file} ({cell}) frame {i} is {}x{} and its chroma planes are {} / {} \
3305+ samples; {cell} is a {cw}x{ch} = {} crop",
3306+ f.width,
3307+ f.height,
3308+ f.u.len(),
3309+ f.v.len(),
3310+ cw * ch
3311+ );
3312+ }
3313+ let short = crate::decode::frame_chroma_alloc_short_samples() - short_before;
3314+ assert_eq!(
3315+ short, 0,
3316+ "{NAME}: {file} ({cell}) allocated {short} chroma samples SHORT of the `round_ss` \
3317+ extent the tile's chroma walks may address -- the frame chroma planes are sized \
3318+ by a FLOOR `>> ss` that does not round"
3319+ );
3320+ let crop = crate::decode::frame_chroma_alloc_crop_shapes() - crop_before;
3321+ assert_eq!(
3322+ crop, 0,
3323+ "{NAME}: {file} ({cell}) reached a frame shape on which `>> ss` and `round_ss` \
3324+ disagree ({crop} frames) -- the allocators are handed a MULTIPLE OF 32 \
3325+ (block_grid * BLOCK) and `ss <= 1`, so this can only mean the allocator's own \
3326+ argument changed, and the shortfall assertion above is then vacuous on this file"
3327+ );
3328+ }
3329+ }
3330+
3331+ /// lane-av1floorshift: the STATIC half of the same claim, and the part that
3332+ /// does not need a corpus. The frame chroma allocators' shift argument is
3333+ /// `block_grid(mi_cols, mi_rows) * BLOCK` with `BLOCK == 32`, so for every
3334+ /// `mi_cols`/`mi_rows` this decoder can admit and every subsampling the
3335+ /// header can carry (`ss in {0, 1}` per axis), `>> ss` and `round_ss` are
3336+ /// the same number. Exhaustively checked here over a range wider than any
3337+ /// frame a header can declare; the two counters above are zero for a
3338+ /// reason, and this is the reason.
3339+ #[test]
3340+ fn the_frame_chroma_alloc_shift_argument_cannot_floor_below_round_ss() {
3341+ const NAME: &str = "the_frame_chroma_alloc_shift_argument_cannot_floor_below_round_ss";
3342+ const BLOCK: usize = 32;
3343+ // `block_grid(mi) = mi.div_ceil(BLOCK_MI)` with `BLOCK_MI == 8`
3344+ // (`tile.rs`), so the allocator's width is `(mi.div_ceil(8)) * 32`.
3345+ for mi in 1..=512usize {
3346+ let coded = mi.div_ceil(8) * BLOCK;
3347+ for ss in 0..=1usize {
3348+ assert_eq!(
3349+ coded >> ss,
3350+ crate::decode::round_ss(coded, ss),
3351+ "{NAME}: coded {coded} (mi {mi}) at ss {ss}: the floor and the crop differ -- \
3352+ the frame chroma plane would be allocated short"
3353+ );
3354+ // The TRUE extent is `mi * 4`; it is what the allocator
3355+ // derives `true_width` from and what every chroma walk is
3356+ // clamped against, so it earns the same check.
3357+ let truth = mi * 4;
3358+ assert_eq!(
3359+ truth >> ss,
3360+ crate::decode::round_ss(truth, ss),
3361+ "{NAME}: true {truth} (mi {mi}) at ss {ss}: the floor and the crop differ"
3362+ );
3363+ }
3364+ }
3365+ // And the 4:4:0 cell libaom refuses, spelled out rather than left as
3366+ // an assumption: at `ss (0,1)` the shift is exact too, so the site
3367+ // would be correct even if the cell were ever admitted.
3368+ for mi in 1..=64usize {
3369+ assert_eq!(mi * 4 >> 1, crate::decode::round_ss(mi * 4, 1));
3370+ assert_eq!(mi * 4, crate::decode::round_ss(mi * 4, 0));
3371+ }
3372+ }
3373+
3211 /// lane-av1422tailskip: the WITNESS cell for the 4:2:2 intra-in-inter3374 /// lane-av1422tailskip: the WITNESS cell for the 4:2:2 intra-in-inter
3212 /// PALETTE chroma per-unit window, and its byte pin.3375 /// PALETTE chroma per-unit window, and its byte pin.
3213 ///3376 ///
lanes/av1floorshift.report.mdadded+188 -0
@@ -0,0 +1,188 @@
1+# lane/av1floorshift — the floor-`>>` chroma plane allocators
2+
3+Base `main` = `81fc00bb` ("Merge lane/av1muchroma: the skip-arm chroma grid was
4+the one short square"). Worktree `~/.cache/wt/av1floorshift`, own
5+`CARGO_TARGET_DIR=~/.cache/tgt/floorshift`.
6+
7+Target: the sites named at `lanes/av1subsizesweep.report.md:242` as
8+"`decode.rs:35708, 53419` — floor-`>>` chroma plane allocators — shape
9+assumption at frame edges; not probed", left open by `lane/av1muchroma`.
10+
11+## The census: which sites shift by 1 instead of `>> ss_x` / `>> ss_y`
12+
13+The instruction asked for "every chroma allocation that shifts a dimension by 1
14+instead of `>> ss_x` / `>> ss_y`". Swept the whole crate for that shape
15+(`>> 1`, `/ 2` on a chroma extent or a chroma allocation) and then read each hit
16+for whether it is a chroma **plane allocation** at all.
17+
18+**The premise of the target did not survive the sweep: the two named sites were
19+already per-axis.** The report's line numbers had drifted *twice* — by ~570 lines
20+from `e45cc748` to `81fc00bb`, and the sites they point at moved again in this
21+lane. What they name now:
22+
23+| site | expression | chroma plane allocation? |
24+|---|---|---|
25+| `decode.rs:36380` (`decode_key_frame_tile_with_cdfs`) | `(width >> ss_x(fctx), height >> ss_y(fctx))` | **yes** — the frame's U/V `PlaneBuf` |
26+| `decode.rs:54161` (`decode_inter_tile`) | same | **yes** — the frame's U/V `PlaneBuf` |
27+
28+Both were `>> ss_x` / `>> ss_y` — already the per-axis form the charter asks
29+for. So the finding is not "they shift by 1"; it is **"floor vs. crop"**: `>>`
30+floors where libaom's own chroma producer (`av1_round_shift`, spelled `round_ss`
31+at `decode.rs:697`) crops. That is what the target row's "shape assumption at
32+frame edges" actually meant, and it is the only question left.
33+
34+Every other `>> 1` / `/ 2` hit in the crate, with its verdict:
35+
36+| site | what it sizes | verdict |
37+|---|---|---|
38+| `decode.rs:18374`, `18391` (`decode_rect4_16_intrabc` `else` arm) | `(pw / 2, ph / 2)` and a `MI / 2` origin | not a plane allocation; **already closed** by the named residue in `av1subsizesweep.report.md` §"The named residue" — dead because the `(16,16)` `refuse_invalid_subsize` one level up refuses `PARTITION_VERT_4` at 4:2:2, the only shape that could reach it |
39+| `decode.rs:21118` (`cfl_ac_q3_at`) | `bw / 2, bh / 2` | **not** a plane allocation; the 4:2:0 CfL AC signal, gated to 4:2:0-only reachability by `cfl_ac_q3_at_is_reached_only_through_the_420_fallthrough_of_cfl_ac_ss` (static + counter, both directions) |
40+| `decode.rs:19456` (`decode_intrabc_rect` ctx stamp) | `(oy / 2, ox / 2)` | **already per-axis** two lines below: the code uses `(oy << ss_y(fctx)) / MI`, `(ox << ss_x(fctx)) / MI`; the `/2` is in the explanatory comment naming the 4:2:0 form |
41+| `decode.rs:41040-41041` (OBMC `overlap_above`/`overlap_left`) | `write_h.min(64) / 2` | luma OBMC overlap in luma pixels (libaom `reconinter.c` 860/899 caps at a 64×64 **luma** block's half); not a chroma extent |
42+| `decode.rs:31544` | `(w / 2, h / 2)` in a `rect_inter_chroma_set` test helper | test-local; the two shapes it names above it are spelled out |
43+| `decode.rs:60430-60454`, `60702-60718`, `stream.rs:2334-2358`, `16622` | test-card / harness `PlaneBuf` and `Picture` chroma at `width / 2` | test surface, no decode path |
44+| `encode.rs` (many), `tile.rs:5005` (`palette_uv_side`) | encoder/test surface | **out of charter** and separately owned — `palette_uv_side` is closed by `lane/av1paletteuv`, the encoder's 4:2:0-only arithmetic is the `encode.rs` row already listed in `av1subsizesweep.report.md`'s wider sweep |
45+
46+So the whole in-charter surface is **two sites**, and both are already per-axis.
47+
48+## Per-site verdict
49+
50+### Site A — key-frame frame chroma planes (`decode.rs:36380`) — **already correct**
51+### Site B — inter frame chroma planes (`decode.rs:54161`) — **already correct**
52+
53+Not "correct by luck of the corpus" — **structurally, for every input**:
54+
55+* `width` / `height` are `(cols, rows) * BLOCK` where `(cols, rows) =
56+ block_grid(mi_cols, mi_rows)` and `BLOCK == 32` (`decode.rs:7565`,
57+ `tile.rs:2141`). **Both axes are multiples of 32** before any shift.
58+* `ss_x` / `ss_y` are `fctx.subsampling_x` / `subsampling_y` — the sequence
59+ header's single-bit fields, so `ss ∈ {0, 1}` on every stream that exists.
60+* `32k >> ss == round_ss(32k, ss)` for every `k` and every `ss ≤ 1`. The floor
61+ **cannot** drop a sample. Frame edge or not.
62+* The same holds for `true_width` / `true_height` (`mi_cols * 4`, `mi_rows * 4`)
63+ — multiples of 4, so the true-extent shift is exact too.
64+* 4:4:0 (`ss (0,1)`) would be exact as well, and cannot exist anyway:
65+ libaom's `av1_read_color_config` asserts `subsampling_y == 0` when
66+ `subsampling_x == 0`, and no one of 256 header bytes reads back `(0,1)`
67+ (the reader census names this).
68+
69+`the_frame_chroma_alloc_shift_argument_cannot_floor_below_round_ss` checks that
70+exhaustively over `mi ∈ 1..=512` and `ss ∈ {0, 1}`, on **both** the coded
71+(`mi.div_ceil(8) * 32`) and true (`mi * 4`) extents, plus an explicit 4:4:0
72+spelling-out.
73+
74+### Reachability, measured
75+
76+Both sites run on **every decoded frame**, so reachability is not the question;
77+what mattered was whether the corpus could ever *discriminate* floor from crop.
78+Three byte-pinned witnesses, one per selectable cell:
79+
80+| file | cell | size | fnv1a64 | covers |
81+|---|---|---|---|---|
82+| `420_odd65x65_key.obu` | 4:2:0, **odd** 65×65 | 2305 | `0xf55645c4b139e8f7` | key allocator, on the odd-dimension cell where a floor *would* show (output crop is 33×33 = 1089, not a floored 32×32 = 1024) |
83+| `422_key_64x64.obu` | 4:2:2 (1,0) | 755 | `0x87fc569cf53bcbc6` | key allocator, half-width / full-height |
84+| `444_intrabc_rect4_witness.obu` | 4:4:4 (0,0) | 1016 | `0x27c2fad540472994` | key allocator, the `ss == 0` cell where `>> ss` is the identity |
85+
86+Counted shortfall (`frame_chroma_alloc_short_samples`): **0** on all three.
87+Crop-disagreement frames (`frame_chroma_alloc_crop_shapes`): **0** on all three.
88+Allocator invocations: non-zero on all three, asserted `>= frames.len()`.
89+
90+The inter site (B) is reached by every inter frame; the same arithmetic applies
91+and the gate's corpus half reads the shared counter, so a regression on either
92+site moves it.
93+
94+## The gate
95+
96+`stream.rs::the_frame_chroma_planes_are_allocated_on_the_per_axis_floor_that_never_rounds`
97+
98+Three counters in `decode.rs`, deliberately **not** one:
99+
100+* `frame_chroma_alloc_calls` — **non-vacuity**. One bump per allocator run. The
101+ other two are zero on every input that exists, so without this the gate would
102+ pass with the instrument removed entirely.
103+* `frame_chroma_alloc_crop_shapes` — **decidability**. Fires only where `>> ss`
104+ and `round_ss` disagree for that frame's own shift argument. Its zero is the
105+ finding, and it is also the guard that keeps the shortfall assertion from
106+ going vacuous: a non-zero here means the allocator's argument changed, and the
107+ report says so in the assertion message rather than passing quietly.
108+* `frame_chroma_alloc_short_samples` — **the claim**. `round_ss(w,ss_x) *
109+ round_ss(h,ss_y)` minus the allocation's **own** `(cw, ch)`, summed.
110+
111+The shortfall reads the allocator's real `(cw, ch)`, passed in as an argument —
112+not a recomputation of `shape >> ss` beside it. An earlier draft recomputed it
113+and would have read the same value under either form, i.e. a gate that could not
114+bite; the sibling lane's `mutation-red-proof-names-its-assertion` caught the
115+class and this is the fix. `EC_AV1_CHROMA_ALLOC_SWEEP` traces a disagreement
116+loudly rather than leaving it to be inferred.
117+
118+## Mutation proof, two ways
119+
120+**Restoring the shift** — both sites `>> ss_x`/`>> ss_y` → `width / 2, height / 2`
121+(the 4:2:0-only hardcoded form this target class is made of):
122+
123+```
124+panicked at crates/ec-av1/src/decode.rs:22442:
125+range start index 1256 out of range for slice of length 1024
126+test the_frame_chroma_planes_are_allocated_on_the_per_axis_floor... FAILED
127+```
128+
129+It reds before the gate's assertion — the shortfall is a real out-of-bounds read
130+in the tile walk, which is the defect's actual consequence. Recorded as such,
131+not as the gate biting.
132+
133+**The gate's own assertion**, isolated — `ch` made one sample short
134+(`.saturating_sub(1)`), too little to trip the bounds check:
135+
136+```
137+panicked at crates/ec-av1/src/stream.rs:3308:
138+the_frame_chroma_planes_are_allocated_on_the_per_axis_floor_that_never_rounds:
139+420_odd65x65_key.obu (4:2:0) allocated 48 chroma samples SHORT of the `round_ss`
140+extent the tile's chroma walks may address
141+ left: 48
142+ right: 0
143+test result: FAILED. 0 passed; 1 failed
144+```
145+
146+Both mutations reverted; the diff is the census, the wiring, and the two tests.
147+
148+## Tests
149+
150+| suite | result |
151+|---|---|
152+| the two new gates | 2/2 ok |
153+| 7 pinned `the_pinned_422_*` + `the_422_skip_arm_*` + `an_odd_luma_420_key_frame_*` | 9/9 ok, unchanged from base |
154+| 51 `444` gates | 51/51 ok, no regression |
155+| `cargo check -p ec-av1 --tests --features gate-counters` | clean, no warnings from this lane |
156+
157+Counters are behind the existing `gate-counters` feature like every other
158+counter in this crate; run with `--features gate-counters`.
159+
160+## Still open, not touched
161+
162+1. **`palette_uv_side`** (`tile.rs:5005`) — closed by `lane/av1paletteuv`. Untouched.
163+2. **The mu-chroma squares** — closed by `lane/av1muchroma` (the one short square
164+ was site 1). Untouched.
165+3. **`encode.rs`'s 4:2:0-only chroma arithmetic** — the encoder emits 4:2:0
166+ exclusively, so every `width / 2` there is correct for the only cell it can
167+ emit. Out of charter; the `encode.rs` row in `av1subsizesweep.report.md`'s
168+ wider sweep already names it, including the `obmc_plan` (`7362`) convention
169+ split. **No fix is warranted** and none was written.
170+4. **`stream.rs`'s ffmpeg rawvideo oracle slices** (`width * height / 4`) — the
171+ row `av1subsizesweep.report.md` calls "the dangerous ones". Still unguarded
172+ against the wrong format; a future 4:2:2 gate that used them would compare
173+ half the oracle's bytes and pass green. The new gate here avoids the trap by
174+ asserting the plane's **shape** (`round_ss` crop of the frame's own
175+ dimensions) rather than comparing against a 4:2:0-sized oracle slice, which
176+ is the pattern any such gate should copy.
177+5. **`decode_rect4_16_intrabc`'s `else` arm** is still wrong in isolation —
178+ closed by the guard one level up, not by construction. Unchanged; see the
179+ named residue in `av1subsizesweep.report.md`.
180+
181+## Reproduction
182+
183+```
184+git worktree add ~/.cache/wt/av1floorshift -b lane/av1floorshift 81fc00bb
185+cd ~/.cache/wt/av1floorshift
186+CARGO_TARGET_DIR=~/.cache/tgt/floorshift \
187+ cargo test -p ec-av1 --lib --features gate-counters -- the_frame_chroma
188+```
\ No newline at end of file\ No newline at end of file