From 056185da446c49b8804d56285b2038292a049deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 28 Aug 2026 17:59:36 +0300 Subject: [PATCH] wip(av1): range-state ladder FALSIFIES r8's partition-CDF-skew theory; real divergence narrowed to block(0,0)'s own tail (interintra/motion_mode/ interp_filter/coeffs). Round 9, capped at budget. STEP 1 (the r8 caveat, resolved): dumped od_ec_dec's tell-offset math from libaom entdec.c by hand -- od_ec_dec_init's own refill loop leaves od_ec_dec_tell() at 1 immediately after init for this stream's tile (3 bytes pulled into the window: cnt goes -15->-7->1->9, bptr advances 3, tell = 3*8-9+(-14) = 1), while our SymbolDecoder::new's debug_bitpos() sits at 15 after its own init read (f(15) always advances self.bit by 15). That is a CONSTANT 14-bit baseline difference between the two tell() implementations, not a per-symbol cost -- confirmed by measuring it at FOUR independent checkpoints (post_is_inter, post_ref_frame, post_assign_mv, each for two different blocks): every one showed exactly tell_ours - tell_aomdec = 14. r8's "~15 more bits for the same two partition symbols" was 100% tell-baseline accounting, not a CDF skew. CLOSES the partition_w64/partition_w32 CDF-forwarding suspect from r8's handoff -- no further investigation needed there. STEP 2 (range-state ladder, the real proof): added `range=` to every TELL checkpoint on both sides (ours: msac debug_state().0, decode.rs block_entry/post_is_inter/post_ref_frame/post_assign_mv, new tile_init and block_end checkpoints; aomdec: r->ec.rng on the mirrored decodemv.c TELL lines, EC_PART, and the existing per-block EC_TOK line in decodeframe.c's parse_decode_block, rebuilt at /tmp/libaom-src/build/decoder-debug/aomdec). Range is representation- independent (unlike tell/value, which differ by each decoder's own window convention) so an exact range match is a hard sync proof, not a units coincidence. Result for the pin's frame-1 tile, block mi(0,0) (decode-order frame 1, first real leaf, LAST_FRAME single-ref inter): tile_init: ours range=32768 aomdec range=32768 MATCH post_is_inter: ours range=54894 aomdec range=54894 MATCH post_ref_frame: ours range=52050 aomdec range=52050 MATCH post_assign_mv: ours range=50720 aomdec range=50720 MATCH <- exact block_end: ours range=33843 aomdec range=37806 MISMATCH Every read up through and including assign_mv (partition x2, skip_mode, skip, intra_inter, ref_frame, the whole MV/DRL path) is bit-for-bit, range-for-range identical to aomdec on this stream. The FIRST real divergence is strictly between post_assign_mv and block_end of THIS SAME block -- i.e. inside decode_inter_block's tail: interintra gate/wedge, motion_mode (OBMC/warped), interp_filter, or the block's own plane coefficient decode (txb_skip/tx_type/coeffs for luma+chroma). It is NOT a later block, NOT a CDF-forwarding artifact, and NOT (per r8, already closed) the interintra eligibility gate's *logic* -- but the interintra READ itself, motion_mode, interp_filter, and first-txb_skip are all now back in scope as the concrete next checkpoints since the "same-value skewed-cost" theory that ruled interintra out is dead. Class for memory: `instrument-measures-itself` kin -- two independently- implemented tell()/bit-position counters can disagree by a fixed accounting constant (od_ec's window-refill bookkeeping vs a straight consumed-bit counter) with zero relationship to real desync; RANGE is the comparable quantity across two independent arithmetic-coder implementations, TELL is not, unless first proven to share a baseline. NEXT (round 10): checkpoint range after each of interintra-read, motion_mode-read, interp_filter-read, and first txb_skip-read for block mi(0,0) specifically (both sides -- aomdec's read_interintra_mode / read_motion_mode / read_ref_mv_idx... / av1_read_frame_reference_mode equivalents in decodemv.c, and decodetxb.c's very first coeffs call); first range mismatch among those four names the element. TELL_AV1 checkpoints already left in place for all of block_entry/post_is_inter/ post_ref_frame/post_assign_mv/block_end (ours) and the mirrored decodemv.c + decodeframe.c prints (aomdec, both range-augmented, rebuild with `make -j12 aomdec` in /tmp/libaom-src/build/decoder-debug). Repro: EC_AV1_TELL=1 EC_AV1_PIN= EC_AV1_PIN_N=24 cargo test -p ec-av1 --release --lib scratch_isolate_pinned_mismatch -- --ignored --nocapture aomdec side: EC_AV1_TELL=1 /tmp/libaom-src/build/decoder-debug/aomdec --codec=av1 -o /tmp/out.yuv .obu 2>&1 | grep -E "^TELL|^EC_PART|^EC_TOK" (frame 1's block is the SECOND "bsize=15" cycle in the trace) --- crates/ec-av1/src/decode.rs | 38 +++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 485ce8ec..b5c0feed 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4662,8 +4662,8 @@ fn decode_inter_block( if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( - "TELL mi_row={} mi_col={} label=block_entry side={side} tell={}", - r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos() + "TELL mi_row={} mi_col={} label=block_entry side={side} tell={} range={}", + r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 ); } let skip_mode_ctx = @@ -4697,8 +4697,8 @@ fn decode_inter_block( let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1; if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( - "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={}", - r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos() + "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}", + r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 ); } @@ -5293,8 +5293,8 @@ fn decode_inter_block( if std::env::var_os("EC_AV1_TELL").is_some() { let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); eprintln!( - "TELL mi_row={mi_row} mi_col={mi_col} label=post_ref_frame ref={ref_frame} tell={}", - dec.debug_bitpos() + "TELL mi_row={mi_row} mi_col={mi_col} label=post_ref_frame ref={ref_frame} tell={} range={}", + dec.debug_bitpos(), dec.debug_state().0 ); } // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own @@ -5409,8 +5409,8 @@ fn decode_inter_block( }; if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( - "TELL mi_row={mi_row} mi_col={mi_col} label=post_assign_mv tell={}", - dec.debug_bitpos() + "TELL mi_row={mi_row} mi_col={mi_col} label=post_assign_mv tell={} range={}", + dec.debug_bitpos(), dec.debug_state().0 ); } // lane-sb128 r4: `interintra` (spec 5.11.24; libaom @@ -5834,6 +5834,18 @@ fn decode_inter_block( )?; } } + // lane-comppin r9: end-of-block checkpoint -- everything between + // post_assign_mv and here (interintra, motion_mode, interp_filter, then + // every plane's coeffs) is unproven; a range mismatch here vs aomdec's + // equivalent post-content point (added at the matching call site) + // narrows the ladder to this block's own tail instead of the next + // block's partition read. + if std::env::var_os("EC_AV1_TELL").is_some() { + eprintln!( + "TELL mi_row={} mi_col={} label=block_end tell={} range={}", + r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 + ); + } neighbours.record(at, side, mode_for_tx, &[luma_grid, u_grid, v_grid]); neighbours.record_inter(at, side, skip, is_inter, ref_frame_for_lf, block_filter, skip_mode); if let Some((ref1, group_idx, idx)) = compound_ctx { @@ -6962,6 +6974,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( let mut cdfs = initial_cdfs.unwrap_or_else(|| Cdfs::new(q_ctx_of(base_q_idx))); let mut dec = SymbolDecoder::new(data); + // lane-comppin r9: tile-entry range, the earliest point comparable + // against aomdec's own `r->ec.rng` right after `aom_reader_init` -- the + // first ladder rung before any symbol (partition or otherwise) is read. + if std::env::var_os("EC_AV1_TELL").is_some() { + eprintln!( + "TELL label=tile_init tell={} range={}", + dec.debug_bitpos(), + dec.debug_state().0 + ); + } let mut neighbours = Neighbours::new( cols as usize * 2, rows as usize * 2,