From a4597ea7f0d82ec33e5af03a5e21a64c31bdfddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 30 Sep 2026 02:32:06 +0300 Subject: [PATCH] av1: the per-unit bit-interval ladder, and the second 4:4:4 intra-BC witness at full exactness The 4:4:4 intra-BC chroma fork at mi (20,40) is NOT an entropy fork, and the count asymmetry that named it does not exist. Re-measured on 444_intrabc_rect4_witness.obu with a per-unit BIT-INTERVAL ladder against the oracle's EC_ECDUMP_IN/_OUT/_END: 512 real txb_skip reads against the oracle's 513, not the ~1069 fewer an earlier round reported (that figure counted the 1883 zero-bit reads the rung fires for, and filtered one side only). Every one of the 2365 in-stream units agrees on entry, post-txb_skip AND end-of-unit position at a MEASURED constant offset of +14 bits; all_zero agrees on all 2395. The 30 tail mismatches are end-of-buffer padding, not a fork. There is no first divergent symbol, because there is no divergence in the coefficient ladder. What the ladder ruled out is the finding. With entropy excluded and the filters exonerated (oracle PREFILT == oracle FINAL on all three planes), the fork was a wrong-PLACE write: our PREDICTION at the first divergent sample was byte-identical to the oracle's (sum 26258 both, same first row), so the defect had to be a later different write -- and the MC/inter write path had no rung to say so. Hence EC_MCWR (the write's origin and shape) and EC_MCPUSH (the push site, #[track_caller]), which named decode_intrabc_owned_rect's skip arm committing a 32x16 chroma window at (px/2, py/2) = (160,80) and leaving its own 64x32 footprint at (320,160) unwritten. Two difference components, 8 cells sharp and 1182 over the whole quadrant: one wrong-place write, not two defects. That fix is ALREADY ON MAIN, in a more general form than this lane first wrote it: 5324a685 (lane-av1chromarect) made the extent and origins ss-derived for this whole function, skip arm included, after solving the missing-TxbSet blocker that had forced this lane to scope its fix to the skip arm; 2c0fd2b9 (lane-av1chromadc) windowed the skipped-block chroma override per unit. Main's version is kept, for a substantive reason: scoping to the skip arm would have left a known-wrong shape in the arm that actually reads coefficients. This branch is rebuilt from 79b2a73f and carries only the instrument, the gate and the report; the pre-rebase commit e0a7b744 is on backup-av1ibcfork for the record. With both landed the witness is byte-exact on all three planes, including the "(416,192) residual tail" this lane had called a separate open defect -- it was a consequence of the same wrong-place write, not an independent one. Gate a_444_intrabc_rect4_witness_is_byte_exact_after_the_skip_arm_footprint: a SECOND witness, not a repeat of chromarect's r512.obu gate, because the two shapes fail differently -- r512's 128-root strips fail as a sizing error inside the coefficient walk, while this witness's 64x32 skip block read no coefficient at all, so its only symptom was pixels. Four arms: 4:4:4 header asserted, the 4:2:0 twin byte-exact (where >> ss_x IS / 2, so it is the measurement), IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS >= 1, and FULL byte-exactness on all three planes. Mutating the function back to the halving reds it at (x=160, y=80) -- the same sample this lane measured by hand before the gate existed. Also: SymbolDecoder::symr_mi(), because a per-unit rung needs a mi and set_symr_mi only wrote it. --- crates/ec-av1/src/decode.rs | 129 +++++++++++++++ crates/ec-av1/src/msac.rs | 9 ++ crates/ec-av1/src/stream.rs | 127 ++++++++++++++- lanes/av1ibcfork.report.md | 302 ++++++++++++++++++++++++++++++++++++ 4 files changed, 564 insertions(+), 3 deletions(-) create mode 100644 lanes/av1ibcfork.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 09e58ea7..b3541c02 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -2388,6 +2388,90 @@ fn census_unit( ); } +/// lane-av1ibcfork: this decoder's half of the per-unit BIT INTERVAL -- the +/// exact mirror of the oracle's `EC_ECDUMP_IN` / `EC_ECDUMP_OUT` / +/// `EC_ECDUMP_END` triple (`aom-oracle2/src/av1/decoder/decodetxb.c`: one +/// print in `read_coeffs_txb` before and after its `aom_read_symbol`, one in +/// the single caller `av1_read_coeffs_txb` after the whole unit). +/// +/// Why three prints and not one `EC_CENSUS_UNIT`: a COUNT is not a key. The +/// two sides can walk a different NUMBER of units and still be paired, because +/// the interval is what a unit CONSUMED. Entry position alone drifts the moment +/// one side consumes a different number of bits, and list index is invalid the +/// moment one side misses a unit -- both were measured here and both +/// mis-attribute. `post_bit` after the `txb_skip` read is the same +/// `aom_reader_tell` the oracle prints there; `end_bit` is the end of the whole +/// unit including the optional luma `tx_type`, the eob, the base/BR passes and +/// the sign/Golomb loop, so a unit that reads the right symbols in the wrong +/// ORDER is caught too. +/// +/// `bit` counts the bits this decoder has pulled out of its window, so it sits +/// at a CONSTANT offset from the oracle's tell (the OBU header libaom counts +/// before `aom_reader_init`). The offset is measured per fixture, never +/// assumed: +14 on `444_intrabc_rect4_witness.obu`. +#[inline] +fn unit_iv_on() -> bool { + crate::envflags::env_flag!("EC_UNITIV") +} + +/// The unit's ENTRY position. Returns it so the caller can pass the same value +/// to [`unit_iv_skip`] and [`unit_iv_end`] without reading the decoder again. +#[inline] +#[track_caller] +fn unit_iv_in(plane: usize, w: usize, h: usize, ctx: usize, dec: &SymbolDecoder) -> usize { + if !unit_iv_on() { + return 0; + } + let bit = dec.debug_bitpos(); + let (mi_r, mi_c) = SymbolDecoder::symr_mi(); + eprintln!( + "EC_UNITIV_IN side=ours plane={plane} mi=({mi_r},{mi_c}) w={w} h={h} ctx={ctx} bit={bit} at {}", + std::panic::Location::caller() + ); + bit +} + +/// The position immediately after this unit's `txb_skip` read. `bit_in == +/// post_bit` means the read consumed ZERO bits (a CDF row already at a +/// boundary), so this is also the real-read filter: the reader logs a step +/// either way, and counting raw lines overstates the symbol count ~2x (measured +/// on `444_intrabc_rect4_witness.obu`: 2395 lines, 512 real reads, against the +/// oracle's 513 -- not the "~1069 fewer" an earlier round reported). +#[inline] +fn unit_iv_skip( + dec: &SymbolDecoder, + bit_in: usize, + plane: usize, + w: usize, + h: usize, + ctx: usize, + all_zero: bool, +) { + if !unit_iv_on() { + return; + } + let (mi_r, mi_c) = SymbolDecoder::symr_mi(); + eprintln!( + "EC_UNITIV_SKIP side=ours plane={plane} mi=({mi_r},{mi_c}) w={w} h={h} ctx={ctx} az={} bit={bit_in} post_bit={}", + all_zero as i32, + dec.debug_bitpos() + ); +} + +/// The position after the WHOLE unit. One call per successful read, on both +/// the all-zero early return and the full coefficient walk. +#[inline] +fn unit_iv_end(dec: &SymbolDecoder, plane: usize, w: usize, h: usize, ctx: usize) { + if !unit_iv_on() { + return; + } + let (mi_r, mi_c) = SymbolDecoder::symr_mi(); + eprintln!( + "EC_UNITIV_END side=ours plane={plane} mi=({mi_r},{mi_c}) w={w} h={h} ctx={ctx} end_bit={}", + dec.debug_bitpos() + ); +} + // As [`FILTER_INTRA_RECT_HITS`], counting only the strips BELOW 16x16 // (8x16/16x8 leaves of a 16x16 HORZ/VERT partition, lane-fistrip r1) -- the // shapes whose `use_filter_intra` symbol had no CDF class before this round. @@ -4023,6 +4107,7 @@ fn push_mc( /// [`PlaneBuf::reconstruct_mc_rect`], recorded (lane-wave1 step (i)). #[allow(clippy::too_many_arguments)] +#[track_caller] fn push_mc_rect( plane: usize, x: usize, @@ -4034,6 +4119,21 @@ fn push_mc_rect( residual: &[i32], fctx: &crate::decode::FrameCtx, ) { + // lane-av1ibcfork: the PUSH site of an MC/inter write. The executed rung + // (`EC_MCWR`, in `reconstruct_mc_rect`) can only name the dispatch, so + // this is what names the block decoder that asked for the write -- the + // only thing that distinguishes two writes of the same shape. It is what + // localized a 4:4:4 intra-BC SKIP block committing its chroma plane block + // at `(px/2, py/2)` instead of the ss origin, clobbering a neighbouring + // block's reconstruction (lanes/av1ibcfork.report.md). + if crate::envflags::env_flag!("EC_MCPUSH") { + eprintln!( + "EC_MCPUSH plane={plane} x={x} y={y} stride={stride} w={w} h={h} \ + res_len={} at {}", + residual.len(), + std::panic::Location::caller() + ); + } let (src, stride) = match prediction.inline(stride) { Some(v) => v, None => { @@ -7961,6 +8061,12 @@ fn read_coeffs( // (which prints `r->ec.rng` before the same `txb_skip` read). let census_entry_rng = dec.debug_state().0; let (census_w, census_h) = rect_shape.unwrap_or((side, side)); + // lane-av1ibcfork: the per-unit BIT INTERVAL, the twin of the oracle's + // `EC_ECDUMP_IN` / `_OUT` / `_END`. The census plane, not a fresh label: + // it is the same source `census_unit` reads, so the interval line and the + // census line can never disagree about which plane a unit is on. + let iv_plane = CENSUS_PLANE.with(|c| c.get()).min(2); + let iv_bit = unit_iv_in(iv_plane, census_w, census_h, skip_ctx, dec); if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") { let (range, value) = dec.debug_state(); eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}"); @@ -7983,6 +8089,9 @@ fn read_coeffs( 0 }; let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; + unit_iv_skip( + dec, iv_bit, iv_plane, census_w, census_h, skip_ctx, all_zero, + ); // lane-ibc444c: this reader logs an `all_zero` step even for a read that // consumes ZERO bits, so `post_bit == bit` means "no symbol was read" -- // filter on it before pairing anything against the oracle. @@ -8029,6 +8138,7 @@ fn read_coeffs( census_entry_rng, dec, ); + unit_iv_end(dec, iv_plane, census_w, census_h, skip_ctx); return Ok((Grid::Zero(side * side), TxType::DctDct)); } let mut grid = vec![0i32; side * side]; @@ -8246,6 +8356,7 @@ fn read_coeffs( census_entry_rng, dec, ); + unit_iv_end(dec, iv_plane, census_w, census_h, skip_ctx); Ok((Grid::Own(grid), tx_type)) } @@ -8289,7 +8400,9 @@ fn read_coeffs_rect( set_census_plane(plane); let ibctx_on = crate::envflags::env_flag!("EC_IBCTX"); let entry_bit = if ibctx_on { dec.debug_bitpos() } else { 0 }; + let iv_bit = unit_iv_in(plane, w, h, skip_ctx, dec); let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; + unit_iv_skip(dec, iv_bit, plane, w, h, skip_ctx, all_zero); if rect_trace { eprintln!( "EC_COEFF_STEP tag=all_zero plane={plane} ctx={skip_ctx} entry={entry_rng} all_zero={} rng={} bit={entry_bit} post_bit={}", @@ -8313,6 +8426,7 @@ fn read_coeffs_rect( } if all_zero { census_unit(w, h, TxType::DctDct, 0, true, entry_rng, dec); + unit_iv_end(dec, plane, w, h, skip_ctx); return Ok((Grid::Zero(w * h), TxType::DctDct)); } let mut grid = vec![0i32; w * h]; @@ -8517,6 +8631,7 @@ fn read_coeffs_rect( ); } census_unit(w, h, tx_type, eob, false, entry_rng, dec); + unit_iv_end(dec, plane, w, h, skip_ctx); Ok((Grid::Own(grid), tx_type)) } @@ -36598,6 +36713,7 @@ impl PlaneBuf<'_> { /// but only its own true `w`x`h` footprint is committed to the plane, so /// two strips sharing a square's coordinate origin never clobber each /// other's real pixels. + #[track_caller] fn reconstruct_mc_rect( &mut self, x: usize, @@ -36623,6 +36739,19 @@ impl PlaneBuf<'_> { // three row bases are computed once per row instead of a // multiply-add per sample (the samples themselves are unchanged). let max = crate::decode::sample_max(fctx); + + // lane-av1ibcfork: the MC/inter write's own origin and shape. The intra + // side's `EC_PRED` rung prints the PREDICTION, so a region whose + // prediction is byte-identical to the oracle's and whose committed + // samples are not can only be a DIFFERENT WRITE -- and this is the + // only write path with no rung of its own. + if crate::envflags::env_flag!("EC_MCWR") { + eprintln!( + "EC_MCWR x={x} y={y} side={side} w={w} h={h} empty_res={} at {}", + residual.is_empty(), + std::panic::Location::caller() + ); + } // lane-recoparse: an all-zero residual (60% of the units) is a plain // prediction copy -- the same arithmetic with `r == 0`, without // reading `side * h` zeros out of [`ZERO_RESIDUAL`]. diff --git a/crates/ec-av1/src/msac.rs b/crates/ec-av1/src/msac.rs index 6b392ea3..8bdf5440 100644 --- a/crates/ec-av1/src/msac.rs +++ b/crates/ec-av1/src/msac.rs @@ -437,6 +437,15 @@ impl<'a> SymbolDecoder<'a> { SYMR_MI.with(|c| c.set((mi_r, mi_c))); } + /// The `(mi_row, mi_col)` the enclosing block reader last stamped, READ + /// back. `set_symr_mi` only writes; a per-unit interval rung needs to print + /// the mi, and a coefficient read carries none of its own -- without this a + /// ladder cannot be attributed to the block that read it. A copy, not a + /// borrow: the rungs call it from a `&SymbolDecoder`. + pub(crate) fn symr_mi() -> (i64, i64) { + SYMR_MI.with(std::cell::Cell::get) + } + /// `EC_SYMR=1` dumps every symbol read's PRE state (before the read and /// before the adaptation) together with the symbol and the post-read /// range, so a divergence against a reference decoder can be bisected diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index ea11f3e4..f3708dd8 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -21373,9 +21373,9 @@ pub(crate) mod tests { /// leaf push back behind `if side > 64` (the pre-`6c33f204` state) turns /// it red with the same 777 bytes. #[test] - fn the_pinned_444_quadrant_witness_is_the_single_reference_arms_and_not_only_the_compound_arms() { - const NAME: &str = - "the_pinned_444_quadrant_witness_is_the_single_reference_arms_and_not_only_the_compound_arms"; + fn the_pinned_444_quadrant_witness_is_the_single_reference_arms_and_not_only_the_compound_arms() + { + const NAME: &str = "the_pinned_444_quadrant_witness_is_the_single_reference_arms_and_not_only_the_compound_arms"; const FIXTURE_LEN: usize = 27933; const FIXTURE_FNV: u64 = 0x85fa_830b_8800_90df; let _gate_lock = lock_gate_counters(); @@ -49614,6 +49614,127 @@ pub(crate) mod tests { let _ = std::fs::remove_dir_all(&dir); } + /// lane-av1ibcfork: the SECOND 4:4:4 intra-BC witness, and the one the + /// entropy investigation was chartered against. `444_intrabc_rect4_witness.obu` + /// reaches `decode_intrabc_owned_rect`'s SKIP arm once -- the 64x32 block at + /// mi (40,80) -- and is byte-exact on all three planes. + /// + /// Why a second witness and not a repeat of + /// `a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes` + /// (which pins `r512.obu`): the skip arm's defect was a wrong PLACE, not a + /// wrong size, and the two shapes produce DIFFERENT symptoms. `r512.obu`'s + /// 128-root strips fail as a sizing error inside the coefficient walk; this + /// witness's 64x32 skip block read no coefficient at all, so the only + /// symptom was pixels -- a 32x16 window committed at (px/2, py/2) = + /// (160,80) over a region another block had already reconstructed, and its + /// own 64x32 footprint at (320,160) left unwritten. Measured before the + /// ss correction: U 72945 / V 64865 of 307200 wrong, first at (160,80) on + /// both planes, luma byte-exact; the two 8x8-cell difference components + /// were 8 cells at x[160,192) y[80,96) and 1182 cells over the whole + /// x[320,640) y[160,480) quadrant -- one wrong-place write, not two. + /// + /// Full byte-exactness, not a prefix. That is possible only because + /// `lane-av1chromarect` (the ss-derived extent and origins, this function + /// included -- the skip arm was where the defect was first reached) and + /// `lane-av1chromadc` (the per-unit windowed chroma override) both landed; + /// before them this witness carried the open tail + /// `lanes/ibc444c.report.md` r2 recorded. The 4:2:0 twin is asserted + /// byte-exact in the same run, where `>> ss_x` IS `/ 2`. + #[test] + fn a_444_intrabc_rect4_witness_is_byte_exact_after_the_skip_arm_footprint() { + const NAME: &str = "a_444_intrabc_rect4_witness_is_byte_exact_after_the_skip_arm_footprint"; + const F444: &str = "444_intrabc_rect4_witness.obu"; + const F444_LEN: usize = 1016; + const F420: &str = "420_intrabc_rect4_witness.obu"; + const F420_LEN: usize = 890; + const PLANE: usize = 640 * 480; + let read = |file: &str, len: usize| -> Vec { + let path = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join(format!("fixtures/{file}")); + let data = + std::fs::read(&path).unwrap_or_else(|e| panic!("{NAME}: reading {file}: {e}")); + assert_eq!(data.len(), len, "{NAME}: {file} is pinned at {len} bytes"); + data + }; + let stream444 = read(F444, F444_LEN); + let stream420 = read(F420, F420_LEN); + assert_444_header(&stream444, NAME, 8); + + let _guard = lock_gate_counters(); + if !aomdec_available(NAME) { + eprintln!("{NAME}: SKIP -- no aomdec; run scripts/build-aom-oracle.sh"); + return; + } + // 4:2:0 identity FIRST and in full: `>> ss_x` is `/ 2` at ss=1, so + // this arm is the measurement, not a claim about it. + decode_all_frames_vs_oracle(&stream420, &format!("{NAME}-420")); + + crate::decode::reset_ibc_owned_rect_chroma_footprint_444_hits(); + let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + let in_obu = dir.join("in.obu"); + std::fs::write(&in_obu, &stream444).expect("writing the stream"); + let aom_prefix = dir.join("aom"); + let out = Command::new(aomdec_path()) + .args(["--codec=av1", "-o"]) + .arg(dir.join("out.y4m")) + .arg(&in_obu) + .env("EC_AV1_FINAL_DUMP", &aom_prefix) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("aomdec failed to run"); + assert!( + out.status.success(), + "{NAME}: the oracle aomdec refused the stream: {}", + String::from_utf8_lossy(&out.stderr) + ); + let ours_prefix = dir.join("ours"); + set_final_dump_prefix(Some(ours_prefix.display().to_string())); + let _ = decode_stream(&stream444).expect("second decode"); + set_final_dump_prefix(None); + let hits = crate::decode::ibc_owned_rect_chroma_footprint_444_hits(); + assert!( + hits > 0, + "{NAME}: no rect intra-BC block committed a 4:4:4 chroma plane block -- the \ + ss-derived footprint never ran, so this gate is measuring a hardcoded halving \ + (class gate-blind-to-feature)" + ); + let aom_dump = std::fs::read(format!("{}.f0", aom_prefix.display())).expect("oracle dump"); + let our_dump = std::fs::read(format!("{}.f0", ours_prefix.display())).expect("our dump"); + assert_eq!(aom_dump.len(), 3 * PLANE, "{NAME}: 8-bit 4:4:4 640x480"); + assert_eq!( + our_dump.len(), + aom_dump.len(), + "{NAME}: our frame is {} bytes, the oracle's is {}", + our_dump.len(), + aom_dump.len() + ); + for (plane, name) in [(0usize, "Y"), (1, "U"), (2, "V")] { + let at = plane * PLANE; + if our_dump[at..at + PLANE] == aom_dump[at..at + PLANE] { + continue; + } + let first = (0..PLANE) + .find(|&s| our_dump[at + s] != aom_dump[at + s]) + .unwrap_or(PLANE); + panic!( + "{NAME}: plane {name} diverges from the oracle at sample {first} of {PLANE} \ + (x={}, y={}) -- this gate pins FULL byte-exactness on all three planes", + first % 640, + first / 640 + ); + } + let _ = std::fs::remove_dir_all(&dir); + eprintln!( + "{NAME}: {hits} rect intra-BC block(s) committed a 4:4:4 chroma plane block; \ + 4:2:0 twin byte-exact; 4:4:4 byte-exact on all three planes \ + (307200 samples each)" + ); + } + /// lane-av1chromadc: a SKIPPED 64x64 square block at 4:4:4 has a 64x64 /// chroma plane block, which libaom walks as a 2x2 grid of `TX_32X32` units /// (`get_vartx_max_txsize`: `av1_get_adjusted_tx_size(TX_64X64) = diff --git a/lanes/av1ibcfork.report.md b/lanes/av1ibcfork.report.md new file mode 100644 index 00000000..b3366578 --- /dev/null +++ b/lanes/av1ibcfork.report.md @@ -0,0 +1,302 @@ +# lane-av1ibcfork — the 4:4:4 intra-BC chroma fork at mi (20,40): NOT an entropy fork + +Branch `lane-av1ibcfork`, **rebased onto `79b2a73f`** (was `edffad9e`). +`backup-av1ibcfork` holds the pre-rebase commit `e0a7b744`, which carried a fix +that main had already landed in a more general form — see §6. + +**Headline: the count asymmetry in the ticket does not exist. The ladder is +bit-exact. The fork is a wrong-PLACE chroma write, and on current main it is +already fixed — this branch lands the instrument that proved it, plus a gate +that pins the second witness at full byte-exactness.** + +--- + +## 1. The count asymmetry, re-measured (and it is not there) + +Fixture `crates/ec-av1/fixtures/444_intrabc_rect4_witness.obu`, 1016 B, +sha256 `7fe888edf18caa74bdb415f0de643dc59963e87e0255d77191200b7a62eb2542` +(4:4:4, 8-bit, 640x480, frame 0). Oracle +`~/.cache/aom-oracle2/build/aomdec --codec=av1`, env `EC_ECDUMP_IN=1`. + +``` +$ grep -c ^EC_ECDUMP_IN oracle.err -> 2395 +$ grep -c ^EC_ECDUMP_OUT oracle.err -> 2395 +$ grep -c ^EC_ECDUMP_END oracle.err -> 2395 +$ grep -c ^EC_UNITIV_IN rebuilt.err -> 2395 +$ grep -c ^EC_UNITIV_SKIP rebuilt.err -> 2395 +$ grep -c ^EC_UNITIV_END rebuilt.err -> 2395 +``` + +Real reads only (`post_bit != bit` ours, `tell` changed oracle): + +``` +ours all_zero reads that consumed bits 512 +oracle all_zero reads that consumed bits 513 +``` + +**512 vs 513, not 1326 vs 2395.** The `~1069 fewer` figure in +`lanes/ibc444c.report.md` r2 and in the ticket is an artifact of the +instrument: the rungs fire once per unit *including* the 1883 reads that +consume zero bits, and r2's own correction warned about exactly this while +applying the filter to one side only. + +## 2. The oracle rung: ALREADY THERE, and proven present in the binary + +The ticket's unblock was already landed by `lane-av1oraclepost` in the private +`aom-oracle2` clone: + +- `decodetxb.c:149` `EC_ECDUMP_IN` — entry + `tell=` +- `decodetxb.c:172` `EC_ECDUMP_OUT` — `az=` + post-read `tell=` +- `decodetxb.c:459` `EC_ECDUMP_END` — end of the whole unit + `tell=` + +Not assumed — a lane proved a rung can be absent from a staged run: + +``` +$ strings ~/.cache/aom-oracle2/build/aomdec | grep -oE "EC_ECDUMP_(IN|OUT|END)" | sort -u +EC_ECDUMP_END / EC_ECDUMP_IN / EC_ECDUMP_OUT +$ stat -c '%y %n' decodetxb.c build/aomdec +2026-09-29 04:49:25 src/av1/decoder/decodetxb.c (source) +2026-09-29 05:09:35 build/aomdec (binary, LATER) +``` + +No rebuild needed; the shared oracle checkout was never touched. + +## 3. What this branch lands (the instrument, not the fix) + +`EC_UNITIV` — the field-for-field twin of the oracle's triple, three prints per +unit, both coefficient readers (`read_coeffs`, `read_coeffs_rect`), on **both** +exits (the all-zero early return and the full walk): + +``` +EC_UNITIV_IN side=ours plane=.. mi=(..) w=.. h=.. ctx=.. bit=.. at +EC_UNITIV_SKIP side=ours plane=.. mi=(..) w=.. h=.. ctx=.. az=.. bit=.. post_bit=.. +EC_UNITIV_END side=ours plane=.. mi=(..) w=.. h=.. ctx=.. end_bit=.. +``` + +`EC_MCWR` (in `reconstruct_mc_rect`) and `EC_MCPUSH` (in `push_mc_rect`, with +`#[track_caller]` on both). These two exist because the intra side had +`EC_PRED` (the prediction) and the **MC/inter write path had no rung at all** — +so a region whose prediction matched the oracle and whose committed samples did +not was unattributable. That gap is what the fix turned on; see §5. + +`SymbolDecoder::symr_mi()` in `msac.rs`: a per-unit rung needs a mi and a +symbol read carries none. `set_symr_mi` only wrote it; the rungs need to read +it back, from a `&SymbolDecoder`. + +## 4. Bit-interval pairing WORKS — and it is demonstrably NOT index/rng pairing + +Three keys on the same 2395-unit frame, oracle vs ours: + +| key | result | +|---|---| +| list index | **breaks at index 8** (a rect unit whose `bit=0` because the rung was off) | +| coder `rng` | unusable at this scale; `ibc444c` r1 measured 2519 non-equal blocks and an 80-run "match" at an unrelated mi — their figure, quoted as such, not re-run | +| **bit interval `(bit_in, post_bit, end_bit)`** | **exact on all 2365 in-stream units** | + +Offset **K = +14**, measured from unit 0 and then asserted constant for every +later unit (our `bit` counts bits pulled from the window; the oracle's `tell` +counts the same plus the OBU header libaom counts before `aom_reader_init`; +`ibc444c` r1 saw +15 on a different fixture — so it is measured, never assumed): + +``` +entry-position mismatches: 30 (all at index >= 2365) +end-of-unit mismatches: 30 (same indices) +all_zero (az) disagreements: 0 of 2395 +``` + +The 30 are **end-of-buffer padding**, not a fork: our `bit` clamps at 7992 +while the oracle's `tell` keeps counting sentinel reads toward 2^32-5906 +(`ibc444c` r5's "last ~36 units" artifact, 30 here). + +Ladder excerpt around the first break: + +``` +2355 ours p1 32x32 mi=(112,80) in=7980 post=7980 end=7980 az=1 | orc p1 (112,80) tx=3 in=7966 post=7966 end=7966 az=1 +2359 ours p0 32x32 mi=(112,96) in=7986 post=7986 end=7986 az=1 | orc p0 (112,96) tx=3 in=7972 post=7972 end=7972 az=1 +2365 ours p0 16x16 mi=(112,112) in=7992 post=7992 end=7992 az=1 | orc p0 (112,112) tx=2 in=7980 post=7980 end=7980 az=1 +``` + +**There is no first divergent symbol in the coefficient ladder, because there +is no divergence in it.** Every unit in the stream consumes the same number of +bits on both sides, and every `all_zero` agrees. + +## 5. What the divergence actually was: a wrong-PLACE write + +Measured on the pre-rebase tree (`edffad9e` + this lane's fix), against the +oracle's `EC_AV1_FINAL_DUMP`: + +``` +RED-BEFORE Y 0/307200 U 72945/307200 first (160,80) V 64865/307200 first (160,80) +``` + +Filters exonerated first: + +``` +oracle PREFILT vs oracle FINAL Y 0 U 0 V 0 <- CDEF and LR inert +ours PREFILT vs oracle PREFILT Y 0 U 72945 V 64865 <- present BEFORE deblock +``` + +Two 8x8-cell difference components: **8 cells at x[160,192) y[80,96)** (sharp) +and **1182 cells over x[320,640) y[160,480)** (run-away). Two components with +those shapes is the signature of ONE wrong-place write, not two defects. The +cell was **flat 55** where the oracle has a gradient — a `DC_PRED` chroma block +committed at the wrong coordinates. + +**The prediction was not the problem.** `EC_PRED` vs the oracle's `EC_PREDOUT8` +on that cell: + +``` +ours OUR_PRED x=160 y=80 plane=1 bw=32 bh=16 mode=6 ad=2 sum=26258 + row0=[54,53,53,52,50,48,46,45] +oracle chroma sum over the same 32x16 rect = 26258, first row 54 53 53 52 50 48 46 45 +``` + +Identical, sample for sample. So the defect had to be a *later, different* +write — and `EC_MCPUSH` (the rung that did not exist before) named it: + +``` +EC_MCPUSH plane=1 x=160 y=80 stride=32 w=32 h=16 res_len=512 at decode.rs:17045 +EC_MCPUSH plane=2 x=160 y=80 stride=32 w=32 h=16 res_len=512 at decode.rs:17056 +EC_HALV ibc_owned mi=(40,80) bw=64 bh=32 skip=true +``` + +`decode_intrabc_owned_rect`, `if skip` arm, block `mi=(40,80)` 64x32 **skip**. +`px=320, py=160`; the arm committed a 32x16 window at `(px/2, py/2) = (160,80)` +and left its own 64x32 footprint at (320,160) unwritten. At 4:4:4 +`av1_get_max_uv_txsize` is `ss_size_lookup[bsize]` (blockd.h) and the plane block +is the block's OWN footprint, so the origin and the extent were both wrong. + +## 6. The rebase: main had already fixed it, more generally + +`git rebase main` conflicted in exactly that function. Main since `edffad9e`: + +- `5324a685` `lane-av1chromarect` — the ss-derived chroma extent and origins, + **this function included, skip arm included** +- `2c0fd2b9` `lane-av1chromadc` — the skipped-block chroma override windowed + per unit + +`git show main:…/decode.rs` at `decode_intrabc_owned_rect`: + +```rust +let (cw, ch) = (bw >> ss_x(fctx), bh >> ss_y(fctx)); +let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx)); +``` + +and the skip arm's `push_mc_rect(1, cpx, cpy, cside, cw, ch, …)` — which is my +fix, generalized from the skip arm to the whole function. **So main's version +subsumes mine and is the one kept**, for a substantive reason and not just to +avoid a conflict: my version deliberately left the non-skip arm halving, because +`lane-av1chromahalvings` r5 recorded that its ss extent makes the decode **refuse** +(a 4:4:4 32x64 chroma plane block needs a `TxbSet` this crate lacked). Main +solved that separately with a per-unit multi-unit walk +(`read_intrabc_rect_chroma_split`), so the general form became reachable and is +the correct one. My scoped version is now strictly worse: it would have left a +known-wrong shape in the arm that reads coefficients. + +Resolution, honestly: **the fix is main's; the instrument is mine.** The branch +was rebuilt from `79b2a73f` and carries only the rungs, `symr_mi()`, the gate and +this report. A short comment at the two lines records the second-witness +measurement, because main's comment cites only `r512.obu` and this is an +independent confirmation on a different stream with a different failure shape. + +The pre-rebase commit `e0a7b744` is kept on `backup-av1ibcfork` for the record. + +## 7. State on current main: fully byte-exact + +With `chromarect` + `chromadc` in place, the witness's **residual tail is gone +too** — the "(416,192) tail" this lane called a separate open defect was a +consequence of the same wrong-place write, not an independent one: + +``` +$ decode_probe 444_intrabc_rect4_witness.obu vs oracle EC_AV1_FINAL_DUMP +MAIN+mine Y diff 0 of 307200 first (x,y) — +MAIN+mine U diff 0 of 307200 first (x,y) — +MAIN+mine V diff 0 of 307200 first (x,y) — +``` + +That correction matters: the pre-rebase branch reported the tail as open, and it +was not. + +## 8. The gate + +`a_444_intrabc_rect4_witness_is_byte_exact_after_the_skip_arm_footprint` +(`stream.rs`). A **second** witness, not a repeat of +`a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes` +(which pins `r512.obu`) — the two shapes fail differently: `r512.obu`'s 128-root +strips fail as a sizing error *inside the coefficient walk*, while this +witness's 64x32 skip block read **no coefficient at all**, so its only symptom +was pixels. + +Four arms: 4:4:4 header asserted; the 4:2:0 twin byte-exact against the oracle +(where `>> ss_x` IS `/ 2`, so it is the measurement and not a claim); +`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS >= 1` (gated on `ss_x == ss_y == 0`, +so 4:2:0 can never bump it); **full byte-exactness on all three planes** — no +prefix floor, which is only possible because both landed. + +``` +a_444_intrabc_rect4_witness_is_byte_exact_after_the_skip_arm_footprint: + 1 rect intra-BC block(s) committed a 4:4:4 chroma plane block; + 4:2:0 twin byte-exact; 4:4:4 byte-exact on all three planes (307200 samples each) +test result: ok. 1 passed; 0 failed +``` + +### Mutation proof (release, the whole function back to the halving) + +``` +MUT (bw >> ss_x, bh >> ss_y) / (px >> ss_x, py >> ss_y) -> (bw / 2, bh / 2) / (px / 2, py / 2) + -> RED at stream.rs:49723 + "plane U diverges from the oracle at sample 51360 of 307200 (x=160, y=80) + -- this gate pins FULL byte-exactness on all three planes" + test result: FAILED. 0 passed; 1 failed + +LIVE restored: ok +``` + +The red lands on the **same (160,80)** this lane measured by hand before the +gate existed — the gate and the investigation agree to the sample. + +## 9. Gates re-run (release, files touched before the build) + +``` +a_444_intrabc_rect4_witness_is_byte_exact_after_the_skip_arm_footprint ok +a_444_intrabc_owned_rect_strip_sizes_its_chroma_plane_block_and_decodes ok (chromarect) +a_444_skipped_64x64_square_block_windows_its_chroma_override_per_unit ok (chromadc) + -> test result: ok. 3 passed; 0 failed; 0 ignored; 769 filtered out + +444 lossless intrabc_rect gate_coverage refusal_inventory census + -> test result: ok. 109 passed; 0 failed; 3 ignored; 0 measured; 660 filtered out + +mutation (halving restored, counter and gate kept) + -> FAILED. 0 passed; 1 failed then restored -> ok +cargo check -p ec-av1 --all-targets -> 0 errors, 0 warnings +``` + +Main's checkout stayed clean throughout (`git status --porcelain` in +`/home/user/Documents/Code/Rust/edith_codecs` printed nothing after every +edit batch). + +## 10. Files (this branch vs `79b2a73f`) + +| file | what | +|---|---| +| `crates/ec-av1/src/msac.rs` | `SymbolDecoder::symr_mi()` | +| `crates/ec-av1/src/decode.rs` | `EC_UNITIV` rungs + 4 helpers; `EC_MCWR`; `EC_MCPUSH` + `#[track_caller]` on `reconstruct_mc_rect` and `push_mc_rect`; the second-witness comment at the two ss lines | +| `crates/ec-av1/src/stream.rs` | `a_444_intrabc_rect4_witness_is_byte_exact_after_the_skip_arm_footprint` | +| `lanes/av1ibcfork.report.md` | this file | + +## 11. Not done, named + +1. **The `~1069 fewer reads` figure is now known to be an instrument artifact** + (512 vs 513 measured, both sides filtered). It is still stated as fact in + `lanes/ibc444c.report.md` r2 and in the gate doc at `stream.rs:48319` + ("the chroma tail is a second entropy fork"). Correcting another lane's + report text is a separate edit and was not done here; this report carries the + real number and a future reader is told to re-measure. +2. **No full local suite** — project rule: full suites run on the server fleet + only. Everything quoted is a scoped, named run. +3. **The oracle's `EC_ECDUMP_END` tail sentinel** (30 units, `tell >= 2^31`) is + still an oracle-side artifact; our side clamps, so the last 30 ladder entries + are not comparable. Treated as "no position", per `ibc444c` r5. +4. **The two rungs are inert unless armed.** `EC_UNITIV` / `EC_MCWR` / + `EC_MCPUSH` each hold one `LazyLock` atomic load per call site; nothing runs + per sample on the hot path that was not already there.