From 5e7ae321c0c39fb6ae42fcfb98811a20c75b654b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 28 Sep 2026 12:53:54 +0300 Subject: [PATCH] lane-av1422warp: instrument -- EC_SYMR names its own block (mi on every read) No behaviour change: the three `set_symr_mi` calls and the new thread-local only feed an env-gated print. Identity re-proved after the edit: 4:2:0 control a420.obu byte-identical to aomdec --rawvideo, 4:4:4 444_sb128rect_lr_witness.obu byte-identical to the pre-lane build, pinned 422_allskip_2f.obu and 422_sb128_3f.obu still pixel-exact. A symbol read carries no mi, so the per-read stream could only be located by correlating it against a SEPARATE trace. That correlation is what mis-attributed reads in rounds 22 and 23: the divergence was pinned on a 4x4 leaf at mi(24,57) that the EC_SYMR stream shows is nowhere near it. With mi on every read the same divergence names its OWN block, and the answer changes: it is the 32x32 intra block at **mi(64,56)** -- the frame's bottom-right corner at 4:2:2 -- whose mode-info reads pair exactly (skip/cdef/dq/mode=3/angle_y=-2/uv_mode=8/angle_uv=-1) and whose COEFFICIENT reads diverge. The oracle side is the same edit, already snapshotted in the oracle tree as 35d97e5, so both sides carry mi and the streams are directly comparable read for read. `mi` is a LABEL for attribution and is deliberately NOT part of the divergence criterion: the oracle publishes it one read later than we do, so requiring equality on it would report a spurious divergence at read 5. --- crates/ec-av1/src/decode.rs | 3 +++ crates/ec-av1/src/msac.rs | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index d2dee2b7..d005ebc6 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -9981,6 +9981,7 @@ fn read_intra_mode_rect( // `palette_uv` even on a chroma-reference strip. Fold the plane count // into the same `has_chroma` this reader already gates on. let has_chroma = has_chroma && !mono(fctx); + crate::msac::SymbolDecoder::set_symr_mi(mi_r as i64, mi_c as i64); let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); if ec_istep { // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line @@ -16581,6 +16582,7 @@ fn read_intra_mode( // shape the oracle's own `ec_read_intra_frame_mode_info_impl` prints // under `EC_TRACE_MODE_STEP`) so a range ladder can be diffed line for // line against the instrumented aomdec, not just `tell()`. + crate::msac::SymbolDecoder::set_symr_mi(mi_r as i64, mi_c as i64); let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); if ec_istep { // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line @@ -20330,6 +20332,7 @@ fn read_intra_mode_sub8( let has_chroma = has_chroma && !mono(fctx); let trace = crate::envflags::env_flag!("EC_AV1_TRACE"); let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); + crate::msac::SymbolDecoder::set_symr_mi(mi_r as i64, mi_c as i64); if ec_istep { eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", dec.debug_state().0); } diff --git a/crates/ec-av1/src/msac.rs b/crates/ec-av1/src/msac.rs index c0e66234..c127ed01 100644 --- a/crates/ec-av1/src/msac.rs +++ b/crates/ec-av1/src/msac.rs @@ -321,6 +321,16 @@ impl Drop for SymbolDecoder<'_> { } } +thread_local! { + /// The `(mi_row, mi_col)` the enclosing block reader is inside, for the + /// `EC_SYMR` trace. A symbol read carries no mi of its own, so without it + /// the per-read stream can only be located by correlating it against a + /// SEPARATE trace -- and that correlation is what mis-attributed reads in + /// rounds 22 and 23. Set by the mode readers at entry; `(-1,-1)` outside. + pub(crate) static SYMR_MI: std::cell::Cell<(i64, i64)> = + const { std::cell::Cell::new((-1, -1)) }; +} + impl<'a> SymbolDecoder<'a> { /// `init_symbol` (spec 8.2.2). #[must_use] @@ -397,6 +407,10 @@ impl<'a> SymbolDecoder<'a> { /// `decode_symbol` (spec 8.2.6), with the adaptation of 8.3.2. /// + pub(crate) fn set_symr_mi(mi_r: i64, mi_c: i64) { + SYMR_MI.with(|c| c.set((mi_r, mi_c))); + } + /// `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 @@ -431,7 +445,9 @@ impl<'a> SymbolDecoder<'a> { } if symr { eprintln!( - "EC_SYMR pre=({},{},{}) cdf0={} n={} s={} post_rng={}", + "EC_SYMR mi=({},{}) pre=({},{},{}) cdf0={} n={} s={} post_rng={}", + SYMR_MI.with(std::cell::Cell::get).0, + SYMR_MI.with(std::cell::Cell::get).1, pre_value, pre_range, pre_bit,