diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 9c82a1f6..906d4623 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4429,6 +4429,12 @@ fn exec_intra( 1 => &mut *u, _ => &mut *v, }; + // lane-av1cmpaudit: label the in-flight reconstruction's plane for the + // `EC_PRED` rung (aomdec's `EC_PREDOUT8`/`EC_PREDND` print `plane=`). + // Saved and restored so the rung reports THIS call's plane even under + // nesting, and so both of exec_intra's return paths need no cleanup. + let prev_plane = RECON_PLANE.with(|c| c.replace(plane)); + let _plane_guard = PlaneGuard(prev_plane); if rect { target.reconstruct_rect( x, @@ -6996,6 +7002,31 @@ fn note_chroma_class1(plane_idx: usize, tx_type: TxType) { } } +// Which plane the in-flight INTRA reconstruction is writing (0=Y, 1=U, 2=V). +// lane-av1cmpaudit: aomdec's `EC_PREDOUT8`/`EC_PREDND` print `plane=`, and +// without the same field on our side an `EC_PREDOUT8` vs `OUR_PRED` diff of a +// per-plane prediction cannot be read off ours -- a luma/chroma disagreement +// looked identical to a same-plane disagreement. Set by `exec_intra` (the +// single place a `PlaneBuf::reconstruct{,_rect}` is reached from) and read only +// by the `EC_PRED` rung, so it cannot change a decode. +thread_local! { + static RECON_PLANE: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// The plane index the `EC_PRED` rung prints as `plane=`. +fn recon_plane() -> usize { + RECON_PLANE.with(std::cell::Cell::get) +} + +/// Restores [`RECON_PLANE`] on drop, so `exec_intra` needs no cleanup path on +/// either of its two early returns. +struct PlaneGuard(usize); +impl Drop for PlaneGuard { + fn drop(&mut self) { + RECON_PLANE.with(|c| c.set(self.0)); + } +} + const SUB_MI: u32 = 4; const MI: usize = 4; const SB: usize = 64; @@ -20240,8 +20271,9 @@ impl PlaneBuf<'_> { let row0: Vec = prediction[..bw.min(8)].to_vec(); let col0: Vec = (0..bh.min(8)).map(|r| prediction[r * bw]).collect(); eprintln!( - "@{} OUR_PRED x={x} y={y} bw={bw} bh={bh} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}", + "@{} OUR_PRED x={x} y={y} plane={} bw={bw} bh={bh} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller(), + recon_plane(), i32::from(smooth_neighbor) ); } @@ -20379,8 +20411,9 @@ impl PlaneBuf<'_> { let row0: Vec = prediction[..side.min(8)].to_vec(); let col0: Vec = (0..side.min(8)).map(|r| prediction[r * side]).collect(); eprintln!( - "@{} OUR_PRED x={x} y={y} side={side} side={side} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}", + "@{} OUR_PRED x={x} y={y} plane={} side={side} side={side} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}", std::panic::Location::caller(), + recon_plane(), i32::from(smooth_neighbor) ); } diff --git a/lanes/av1rungs17.report.md b/lanes/av1rungs17.report.md new file mode 100644 index 00000000..7ddd17d8 --- /dev/null +++ b/lanes/av1rungs17.report.md @@ -0,0 +1,236 @@ +# lane-av1rungs17 — script rungs 16/17 (EC_PREDOUT8, EC_PREDND) + +Base: `f33b9d41` (main, `lanes/av1merge-wave3c-b`). Branch: `lane-av1rungs17`. +Method: **reconstruction** onto the current script, not replay of the old one. + +## 1. What was actually absent from main + +The task brief said "main's `decode.rs` already prints `OUR_PRED … plane=`-style +lines, so the C-side may be ahead of the script-side". **That premise is wrong, and +the correction matters because it changes the size of the hole:** + +``` +$ grep -c 'OUR_PRED x={x} y={y} plane=' crates/ec-av1/src/decode.rs # on main +0 +$ git merge-base --is-ancestor 3d0001bc HEAD # lane-av1cmpaudit's commit +NOT ancestor +``` + +Main has **zero** `plane=` on `OUR_PRED` (both sites are the lane's pre-change form +`OUR_PRED x={x} y={y} bw=…` / `… side={side} …`), and no `RECON_PLANE` thread-local +or `PlaneGuard` — main's `recon_planes` hits are an unrelated `ReconPlanes` Y/U/V +struct. So **the whole of commit `3d0001bc` is absent from main, not just its script +half**: the Rust twin field as well as the two rungs. + +Genuinely absent, in full: + +| item | where it lived | on main | +|---|---|---| +| `RECON_PLANE` / `recon_plane()` / `PlaneGuard`, `plane=` on both `OUR_PRED` sites | `3d0001bc` | absent | +| rung 16 — `EC_PREDOUT8` at both 8-bit prediction sites, with `mode=` | `3d0001bc` | absent (`grep -c 'EC_PREDOUT8\|EC_PREDND' scripts/instrument-aom-oracle.sh` → `0`) | +| rung 17 — `EC_PREDND`, the hbd non-directional site | staged, uncommitted in `av1cmpaudit` | absent | + +Present on main and **deliberately not touched**: rungs 1–15, the HBD repair block +(`ec_dump_narrow_row`, `ec_dump_finish`, the halved-pointer fix) and +`scripts/check-aom-oracle-rungs.sh`. + +### `stash@{0}` is a false lead — nothing of rung 16 is in it + +The stash message claims *"EC_PREDOUT8 rung 16 in `scripts/instrument-aom-oracle.sh`"*. +Its actual content is two Rust files from an unrelated lane: + +``` +$ git stash show --stat stash@{0} + crates/ec-av1/src/decode.rs | 106 ++++++++++++----- + crates/ec-av1/src/stream.rs | 185 ++++++++++++++++++++++++++++ +$ git ls-tree -r stash@{0}^3 +100644 blob ec4a3e66… lanes/ibc444c.report.md # the lane it came from +``` + +No script file, no `RECON_PLANE`, no `plane=` in its `OUR_PRED`. The stash's byte-copy +(`/tmp/foreign-instrument-aom-oracle.sh.keep`) is already gone. **Nothing was lost +twice**: the rung-16 script change exists once, in `3d0001bc`, and the rung-17 change +exists once, staged in `av1cmpaudit`. Both are now reconstructed here. + +## 2. Reconstruction + +`~/.cache/wt/av1rungs17`, branched at `f33b9d41`. Nothing was cherry-picked or +`git apply`'d; the rung bodies were re-applied to the **current** files. + +* `scripts/instrument-aom-oracle.sh` — rungs 16 and 17 appended **after** the repair + block. The diff against main is a *single* hunk, `@@ -1076,0 +1077,153 @@`, i.e. pure + append with zero deletions: the repair block cannot have been overwritten, because + `git diff` shows not one of its lines changing. +* `crates/ec-av1/src/decode.rs` — the `RECON_PLANE` thread-local, `recon_plane()`, + `PlaneGuard`, the set-and-restore in `exec_intra`, and `plane=` on both `OUR_PRED` + sites. Re-derived against current main: `exec_intra` is still the single caller of + `PlaneBuf::reconstruct{,_rect}` (`reconstruct_rect` @4439, `reconstruct` @4455, both + inside `fn exec_intra` @4405), so the thread-local is still set for every call that + reaches a `reconstruct`. +* `scripts/check-aom-oracle-rungs.sh` — extended, see §3. + +## 3. The checker: 10 ok preserved, 4 added, all non-vacuous + +The checker previously restored only `av1/decoder/decodeframe.c` to pristine, so a +rung living in `reconintra.c` was never exercised by it — it would have taken the +"already instrumented" branch and asserted nothing. It now also restores +`av1/common/reconintra.c` from the base ref before deriving. + +``` +$ bash scripts/check-aom-oracle-rungs.sh +ok legacy u8 row loops left in the derived file 0 +ok ec_dump_narrow_row call sites (4 rungs x 3 planes) 12 +ok ec_dump_finish call sites (one per narrowing rung) 4 +ok byte-count check wired into EC_AV1_PREFILT_DUMP 1 +ok byte-count check wired into EC_AV1_POSTDEBLOCK_DUMP 1 +ok byte-count check wired into EC_AV1_PREFILT_WIDE_DUMP 1 +ok byte-count check wired into EC_AV1_POSTCDEF_DUMP 1 +ok rung 12 still converts plane pointers 1 +ok rung 12 not routed through the narrowing checker 0 +ok rung 16 EC_PREDOUT8 install sites (both 8-bit paths) 2 +ok rung 16 EC_PREDOUT8 sites carry mode= (EC_PREDND field order) 2 +ok rung 17 EC_PREDND install sites (hbd non-directional) 1 +ok rung 17 EC_PREDND site carries mode= 1 +ok instrument-aom-oracle.sh derives the depth-correct, byte-checked rungs (base v3.13.3) +exit 0 +``` + +All ten pre-existing checks still print `ok` and the exit code is still 0. The four new +ones are the ones a rebuild must not lose: rung 16 at **both** 8-bit sites (a one-site +install looks fine on the directional arm and prints nothing for every non-directional +block), `mode=` surviving on both, rung 17 present, and rung 17's `mode=`. + +A fifth, non-`check` assertion covers the claim in rung 16's own comment that it is +idempotent in **both** directions: the checker synthesises the no-`mode=` form the +oracle tree's git HEAD carries, re-derives, and requires the result to land back on the +identical bytes. + +**Non-vacuity** (each mutation run against the real checker; every one reds on the +specific assertion, exit 1): + +| mutation | result | +|---|---| +| rung 17 deleted from the script | `FAIL rung 17 EC_PREDND install sites … got 0, want 1` | +| rung 16 installs only the non-directional site | `FAIL rung 16 EC_PREDOUT8 install sites … got 1, want 2` | +| rung 16's directional site loses `mode=` | `FAIL rung 16 EC_PREDOUT8 sites carry mode= … got 1, want 2` | + +## 4. Idempotence and correct derivation from pristine + +Starting from a copy of the oracle tree with **both** files restored to `v3.13.3` +(`reconintra.c` has 0 rung sites): + +``` +$ bash scripts/instrument-aom-oracle.sh +EC_PREDOUT8 installed (both 8-bit paths, with mode=) +EC_PREDND instrumented (non-directional, high bitdepth) +``` + +* **Insert-only on pristine**: derived `reconintra.c` vs pristine is **41 added lines, + 0 removed**, every one of them inside the two rung bodies. No stray edits. +* **Second run is a no-op** — both files byte-unchanged: + ``` + EC_PREDOUT8 already carries mode= (no-op) + EC_PREDND already instrumented (no-op) + reconintra.c: NO-OP decodeframe.c: NO-OP + ``` +* **Fidelity to the live hand-patched tree**: the derived `reconintra.c` is + byte-identical to `~/.cache/aom-oracle/src/av1/common/reconintra.c` on the rung + bodies; the only differences are the two comment lines (mine say + `EC_INSTRUMENTED_PREDOUT8 …`, the hand-patch says `EC_PREDOUT8 … (lane-d792)`) and + three instruments that belong to *other* lanes and are in neither this script nor + main's (see §7). + +## 5. (a) insert-only on pristine / no-op when already instrumented + +Covered in §4: 41 insertions, 0 deletions on pristine; second run no-op; the checker +now asserts both, plus the no-`mode=` upgrade round-trip. + +## 6. (b) and (c) — the whole reason these rungs exist + +One configure, two `aomdec` binaries, differing **only** in `av1/common/reconintra.c` +(the second is one recompile plus a relink, not a second libaom build). Built from +`$P/src` after `scripts/instrument-aom-oracle.sh` derived it; then `reconintra.c` was +replaced with the pristine `v3.13.3` file and rebuilt. + +### (b) WITH rungs — 12-bit `fixtures/av112bit-key.obu` + +``` +$ EC_PRED=1 ./aomdec-with-rungs --rawvideo -o out-with.yuv av112bit-key.obu +EC_PREDND lines: 118 +EC_PREDOUT8 lines: 0 +``` + +``` +EC_PREDND mi_row=0 mi_col=0 plane=0 row_off=0 col_off=0 txw=16 txh=8 mode=0 n_top=0 n_left=0 sum=262144 row0=2048,2048,… +EC_PREDND mi_row=0 mi_col=0 plane=1 row_off=0 col_off=0 txw=8 txh=4 mode=0 n_top=0 n_left=0 sum=65536 row0=2048,… +EC_PREDND mi_row=0 mi_col=0 plane=2 row_off=0 col_off=0 txw=8 txh=4 mode=0 n_top=0 n_left=0 sum=65536 row0=2048,… +``` + +Note `EC_PREDOUT8` prints **0** on a 12-bit stream — that is the point of rung 17, not +a defect in it. + +### (c) WITHOUT rungs — same build recipe, same stream + +``` +$ EC_PRED=1 ./aomdec-no-rungs --rawvideo -o out-without.yuv av112bit-key.obu +stderr lines total: 0 +EC_PREDND lines: 0 +``` + +Completely silent. Nothing is printed, so nothing can be diffed. + +### Rung 16 on the 8-bit arm, `fixtures/ii-flake-1.obu` + +``` +WITH rungs: EC_PREDOUT8 15 carrying mode= 15/15 + EC_PREDOUT8 mi_row=0 mi_col=0 plane=0 row_off=0 col_off=0 txw=32 txh=32 mode=0 sum=131072 row0=128,… + EC_PREDOUT8 mi_row=0 mi_col=0 plane=1 row_off=0 col_off=0 txw=16 txh=16 mode=0 sum=32768 row0=128,… +WITHOUT rungs: EC_PREDOUT8 0 +``` + +### The rungs do not change the decode + +``` +6b29cc506f88c8c89afd8b999f218947 out-with.yuv (12-bit) +6b29cc506f88c8c89afd8b999f218947 out-without.yuv +482b5e04208ad5ff077e970c8cee6439 f8-with.yuv (8-bit) +482b5e04208ad5ff077e970c8cee6439 f8-without.yuv +``` + +### The Rust twin now pairs with the oracle + +`decode_probe` on the same 12-bit fixture: **177 `OUR_PRED` lines, 177 of them carrying +`plane=`**, values `plane=0 plane=1 plane=2`. The first three pair field-for-field with +the first three `EC_PREDND` lines above — same `plane`, same `16x8`/`8x4` extent, same +`mode=0`, same `sum=262144`/`65536`: + +``` +@…/decode.rs:4439:16 OUR_PRED x=0 y=0 plane=0 bw=16 bh=8 mode=0 ad=0 ft=0 sum=262144 row0=[2048, …] +@…/decode.rs:4439:16 OUR_PRED x=0 y=0 plane=1 bw=8 bh=4 mode=0 ad=0 ft=0 sum=65536 row0=[2048, …] +@…/decode.rs:4439:16 OUR_PRED x=0 y=0 plane=2 bw=8 bh=4 mode=0 ad=0 ft=0 sum=65536 row0=[2048, …] +``` + +Build is clean: `cargo check -p ec-av1 --lib` → `Finished`, no warnings, no errors. + +## 7. Left standing, deliberately + +`EC_DR` / `EC_DR_OUT` (4 sites) are in the live oracle tree and in **no** rung of the +script — main's or this one. Same class, different lane's instrument; out of scope here. +Worth a lane of its own. + +The rung-gap census from `av1cmpaudit`'s staged report (preserved verbatim at +`~/.cache/tmp/r17proof/av1cmpaudit.report.staged.md`) puts the wider class at +**84 rung/env names in the live tree, 40 covered by the script, 48 dropped by a +rebuild before this round; rungs 16/17 close 2, 46 remain.** That number is +attributed, not re-derived here. + +## 8. Disposition of `~/.cache/wt/av1cmpaudit` + +Worktree left intact and untouched at `3d0001bc`; nothing was deleted. + +| uncommitted item | disposition | +|---|---| +| staged `scripts/instrument-aom-oracle.sh` (rung 17) | **landed here** as rung 17 | +| staged `lanes/av1cmpaudit.report.md` (+87 lines) | **not landed** — superseded by this report. Its rung-gap census is carried forward in §7 with attribution; byte copy preserved at `~/.cache/tmp/r17proof/av1cmpaudit.report.staged.md` (327 lines) | +| `stash@{0}` in the primary checkout | **untouched.** Its message is wrong — it holds `decode.rs`/`stream.rs` from `ibc444c`, not rung 16. Not mine to land | +| committed `3d0001bc` | not merged as a commit (it predates the HBD repair block, so a replay would clobber it); its content is reconstructed here | diff --git a/scripts/check-aom-oracle-rungs.sh b/scripts/check-aom-oracle-rungs.sh index 7cc67ac6..df613363 100755 --- a/scripts/check-aom-oracle-rungs.sh +++ b/scripts/check-aom-oracle-rungs.sh @@ -10,10 +10,16 @@ # aomdec crash during a decode is found late; this reds on the DERIVATION # instead, in seconds, without a build. # +# The same class of loss applies to the prediction rungs: EC_PREDOUT8 (rung +# 16) and EC_PREDND (rung 17) lived only in the hand-patched oracle tree, so +# a rebuild from the script dropped the only probe that prints on a 10/12-bit +# stream (both, and the pre-existing EC_PREDOUT, sit after an `is_hbd` early +# return). Those are asserted here too, from a PRISTINE reconintra.c. +# # What it does: copies the oracle source tree to a scratch dir, replaces -# av1/decoder/decodeframe.c with the PRISTINE upstream file, runs the -# instrument script over the copy, and asserts the derived file's shape. The -# real oracle tree is never written to. +# av1/decoder/decodeframe.c and av1/common/reconintra.c with the PRISTINE +# upstream files, runs the instrument script over the copy, and asserts the +# derived files' shape. The real oracle tree is never written to. # # Usage: # scripts/check-aom-oracle-rungs.sh [SRC_DIR] [BASE_REF] @@ -25,8 +31,10 @@ SRC="${1:-${AOM_ORACLE_SRC:-$HOME/.cache/aom-oracle/src}}" BASE="${2:-${AOM_ORACLE_BASE_REF:-v3.13.3}}" HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" DERIVED="$SRC/av1/decoder/decodeframe.c" +RECONINTRA="$SRC/av1/common/reconintra.c" [ -f "$DERIVED" ] || { echo "no oracle source at $DERIVED" >&2; exit 1; } +[ -f "$RECONINTRA" ] || { echo "no oracle source at $RECONINTRA" >&2; exit 1; } git -C "$SRC" rev-parse --verify "$BASE^{commit}" >/dev/null 2>&1 || { echo "base ref '$BASE' is not a commit in $SRC" >&2 exit 1 @@ -36,6 +44,7 @@ WORK="$(mktemp -d "${TMPDIR:-$HOME/.cache/tmp}/aom-rung-check.XXXXXX")" trap 'rm -rf "$WORK"' EXIT cp -a "$SRC" "$WORK/src" git -C "$SRC" show "$BASE:av1/decoder/decodeframe.c" > "$WORK/src/av1/decoder/decodeframe.c" +git -C "$SRC" show "$BASE:av1/common/reconintra.c" > "$WORK/src/av1/common/reconintra.c" AOM_ORACLE_SRC="$WORK/src" bash "$HERE/instrument-aom-oracle.sh" > "$WORK/derive.log" 2>&1 || { echo "FAIL: instrument-aom-oracle.sh errored on a pristine tree:" >&2 @@ -43,6 +52,7 @@ AOM_ORACLE_SRC="$WORK/src" bash "$HERE/instrument-aom-oracle.sh" > "$WORK/derive exit 1 } cp "$WORK/src/av1/decoder/decodeframe.c" "$WORK/derived.c" +cp "$WORK/src/av1/common/reconintra.c" "$WORK/derived-intra.c" # Re-running must be a no-op, or the repair pass is not idempotent and a # second run would rewrite a tree under someone's feet. @@ -51,6 +61,10 @@ cmp -s "$WORK/derived.c" "$WORK/src/av1/decoder/decodeframe.c" || { echo "FAIL: a second instrument-aom-oracle.sh run changed the derived file" >&2 exit 1 } +cmp -s "$WORK/derived-intra.c" "$WORK/src/av1/common/reconintra.c" || { + echo "FAIL: a second instrument-aom-oracle.sh run changed reconintra.c" >&2 + exit 1 +} fail=0 check() { # description, actual, expected @@ -85,8 +99,65 @@ check "rung 12 still converts plane pointers" "$conv" "1" r12=$(grep -c 'ec_dump_finish(ec_f, "EC_AV1_FINAL_DUMP"' "$WORK/derived.c" || true) check "rung 12 not routed through the narrowing checker" "$r12" "0" +# --- rungs 16/17: the prediction rungs (lane-av1rungs17) -------------------- +# EC_PREDOUT8 must be installed at BOTH 8-bit prediction sites in +# reconintra.c -- the non-directional early return (DC, SMOOTH*, PAETH) and +# the directional / filter-intra tail. A one-site install would look fine on +# the directional arm and print nothing at all for every non-directional +# block, which is most of an intra frame. +p8=$(grep -c 'EC_PREDOUT8 mi_row=%d' "$WORK/derived-intra.c" || true) +check "rung 16 EC_PREDOUT8 install sites (both 8-bit paths)" "$p8" "2" + +# `mode=` is what makes a non-directional diff attributable at all; a rebuild +# that lost it would still install two sites and still pass the count above. +p8m=$(grep -c 'EC_PREDOUT8 mi_row=%d.*txh=%d mode=%d sum=%ld' "$WORK/derived-intra.c" || true) +check "rung 16 EC_PREDOUT8 sites carry mode= (EC_PREDND field order)" "$p8m" "2" + +# EC_PREDND is the hbd twin and the ONLY prediction probe that fires on a +# 10/12-bit stream. One site, at the non-directional early return. +pnd=$(grep -c 'EC_PREDND mi_row=%d' "$WORK/derived-intra.c" || true) +check "rung 17 EC_PREDND install sites (hbd non-directional)" "$pnd" "1" +pndm=$(grep -c 'txw=%d txh=%d mode=%d n_top=%d n_left=%d' "$WORK/derived-intra.c" || true) +check "rung 17 EC_PREDND site carries mode=" "$pndm" "1" + +# Rung 16 claims to be idempotent in BOTH directions: an install on a +# pristine file, AND an upgrade of the no-`mode=` form the oracle tree's git +# HEAD carries. Rebuild the no-mode form, re-derive, and require the result to +# land back on the same bytes -- an upgrade path that silently no-ops (or +# double-writes) is exactly what a rebuild would hit. +python3 - "$WORK/derived-intra.c" "$WORK/nomode-intra.c" <<'PYUP' +import sys +s = open(sys.argv[1]).read() +# Strip `mode=` from the format string and `mode` from the argument list at +# both EC_PREDOUT8 sites only; EC_PREDND's own mode= must survive untouched. +for fmt_old, fmt_new in ( + ('txw=%d txh=%d mode=%d sum=%ld row0=", xd->mi_row', + 'txw=%d txh=%d sum=%ld row0=", xd->mi_row'), + ('txw=%d txh=%d mode=%d sum=%ld row0=", mi_row', + 'txw=%d txh=%d sum=%ld row0=", mi_row'), +): + assert fmt_old in s, "upgrade fixture: %r not found" % fmt_old + s = s.replace(fmt_old, fmt_new, 1) +assert s.count('col_off, txwpx, txhpx, mode, ec_sum);') == 2, "upgrade fixture: args" +s = s.replace('col_off, txwpx, txhpx, mode, ec_sum);', + 'col_off, txwpx, txhpx, ec_sum);') +assert 'EC_PREDOUT8 mi_row=%d' in s and s.count('txw=%d txh=%d sum=%ld row0=') == 2 +open(sys.argv[2], 'w').write(s) +PYUP +cp "$WORK/nomode-intra.c" "$WORK/src/av1/common/reconintra.c" +AOM_ORACLE_SRC="$WORK/src" bash "$HERE/instrument-aom-oracle.sh" > "$WORK/upgrade.log" 2>&1 || { + echo "FAIL: instrument-aom-oracle.sh errored on the no-mode reconintra.c:" >&2 + tail -20 "$WORK/upgrade.log" >&2 + exit 1 +} +cmp -s "$WORK/derived-intra.c" "$WORK/src/av1/common/reconintra.c" || { + echo "FAIL: re-deriving the no-mode EC_PREDOUT8 form did not land back on the derived bytes" >&2 + diff -u "$WORK/derived-intra.c" "$WORK/src/av1/common/reconintra.c" | head -30 >&2 + exit 1 +} + if [ "$fail" -ne 0 ]; then - echo "FAIL: derived decodeframe.c violates the rung contract (base $BASE)" >&2 + echo "FAIL: a derived file violates the rung contract (base $BASE)" >&2 exit 1 fi echo "ok instrument-aom-oracle.sh derives the depth-correct, byte-checked rungs (base $BASE)" diff --git a/scripts/instrument-aom-oracle.sh b/scripts/instrument-aom-oracle.sh index c016b23b..953cc279 100755 --- a/scripts/instrument-aom-oracle.sh +++ b/scripts/instrument-aom-oracle.sh @@ -1074,3 +1074,156 @@ else: print("dump byte-count check: every narrowing rung already checks its bytes") open(path, "w").write(s) PYN + +# --- rung 16: EC_PREDOUT8, the 8-bit predicted block (lane-av1cmpaudit) ---- +# This rung lived ONLY in the hand-patched oracle tree -- `instrument-aom- +# oracle.sh` never transcribed it -- so a rebuild from this script silently +# dropped it (class: instrument that lives only in a build tree, the same +# reason rung 13 exists). It is transcribed here at BOTH 8-bit prediction +# sites in reconintra.c: the non-directional early-return path (DC, SMOOTH*, +# PAETH) and the directional / filter-intra tail. lane-av1cmpaudit also grew +# `mode=` on both: without it, an agreeing-top / disagreeing-bottom pattern +# on a non-directional unit could not be attributed to a mode at all. +# `mode=` sits after `txh=`, matching EC_PREDND's own field order; every +# pre-existing field keeps its position. +# +# Idempotent, and an UPGRADE as well as an install: the oracle tree's git HEAD +# already carries the rung WITHOUT `mode=`, so the script has to rewrite that +# form too, not just insert the block into a pristine upstream file. +I="$SRC/av1/common/reconintra.c" +[ -f "$I" ] || { echo "no oracle source at $I" >&2; exit 1; } + +python3 - "$I" <<'PYRI' +import sys +path = sys.argv[1] +s = open(path).read() + +if 'EC_PREDOUT8' not in s: + # Pristine upstream: insert the rung at both 8-bit prediction sites. + nd_old = """ build_non_directional_intra_predictors(ref, ref_stride, dst, dst_stride, + mode, tx_size, n_top_px, n_left_px); + return; + }""" + nd_new = """ build_non_directional_intra_predictors(ref, ref_stride, dst, dst_stride, + mode, tx_size, n_top_px, n_left_px); + /* EC_INSTRUMENTED_PREDOUT8 (non-directional, 8-bit) */ + if (getenv("EC_PRED")) { + long ec_sum = 0; + for (int r = 0; r < txhpx; ++r) + for (int c = 0; c < txwpx; ++c) ec_sum += dst[r * dst_stride + c]; + fprintf(stderr, "EC_PREDOUT8 mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d txw=%d txh=%d mode=%d sum=%ld row0=", xd->mi_row, xd->mi_col, plane, row_off, col_off, txwpx, txhpx, mode, ec_sum); + for (int c = 0; c < txwpx && c < 8; ++c) fprintf(stderr, "%d,", dst[c]); + fprintf(stderr, " col0="); + for (int r = 0; r < txhpx && r < 8; ++r) fprintf(stderr, "%d,", dst[r * dst_stride]); + fprintf(stderr, "\\n"); + } + return; + }""" + assert nd_old in s, "non-directional intra predictor tail moved" + s = s.replace(nd_old, nd_new, 1) + + dir_old = """ build_directional_and_filter_intra_predictors( + ref, ref_stride, dst, dst_stride, mode, p_angle, filter_intra_mode, + tx_size, disable_edge_filter, n_top_px, n_topright_px, n_left_px, + n_bottomleft_px, intra_edge_filter_type); +}""" + dir_new = """ build_directional_and_filter_intra_predictors( + ref, ref_stride, dst, dst_stride, mode, p_angle, filter_intra_mode, + tx_size, disable_edge_filter, n_top_px, n_topright_px, n_left_px, + n_bottomleft_px, intra_edge_filter_type); + /* EC_INSTRUMENTED_PREDOUT8 (directional / filter-intra, 8-bit) */ + if (getenv("EC_PRED")) { + long ec_sum = 0; + for (int r = 0; r < txhpx; ++r) + for (int c = 0; c < txwpx; ++c) ec_sum += dst[r * dst_stride + c]; + fprintf(stderr, "EC_PREDOUT8 mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d txw=%d txh=%d mode=%d sum=%ld row0=", mi_row, mi_col, plane, row_off, col_off, txwpx, txhpx, mode, ec_sum); + for (int c = 0; c < txwpx && c < 8; ++c) fprintf(stderr, "%d,", dst[c]); + fprintf(stderr, " col0="); + for (int r = 0; r < txhpx && r < 8; ++r) fprintf(stderr, "%d,", dst[r * dst_stride]); + fprintf(stderr, "\\n"); + } +}""" + assert dir_old in s, "directional intra predictor tail moved" + s = s.replace(dir_old, dir_new, 1) + open(path, "w").write(s) + print("EC_PREDOUT8 installed (both 8-bit paths, with mode=)") + sys.exit(0) + +# Already present: upgrade the rung to carry `mode=` if it does not yet. +nd_fmt_old = 'txw=%d txh=%d sum=%ld row0=", xd->mi_row' +nd_fmt_new = 'txw=%d txh=%d mode=%d sum=%ld row0=", xd->mi_row' +dir_fmt_old = 'txw=%d txh=%d sum=%ld row0=", mi_row' +dir_fmt_new = 'txw=%d txh=%d mode=%d sum=%ld row0=", mi_row' +upgraded = 0 +arg_old = "col_off, txwpx, txhpx, ec_sum);" +arg_new = "col_off, txwpx, txhpx, mode, ec_sum);" +if nd_fmt_old in s: + s = s.replace(nd_fmt_old, nd_fmt_new, 1) + assert arg_old in s, "EC_PREDOUT8 non-directional argument list moved" + s = s.replace(arg_old, arg_new, 1) + upgraded += 1 +if dir_fmt_old in s: + s = s.replace(dir_fmt_old, dir_fmt_new, 1) + assert arg_old in s, "EC_PREDOUT8 directional argument list moved" + s = s.replace(arg_old, arg_new, 1) + upgraded += 1 +if upgraded: + open(path, "w").write(s) + print("EC_PREDOUT8 upgraded to mode= (%d site(s))" % upgraded) +else: + print("EC_PREDOUT8 already carries mode= (no-op)") +PYRI + +# --- rung 17: EC_PREDND, the hbd twin of EC_PREDOUT8 (lane-av1cmpaudit) ---- +# The 10/12-bit non-directional twin of rung 16, and like it this rung lived +# ONLY in the hand-patched oracle tree. Without it a rebuild drops the only +# prediction probe that fires on a high-bitdepth stream -- rung 16 and the +# pre-existing EC_PREDOUT both sit after the `is_hbd` early return and print +# nothing there. EC_PREDND already carried `mode=`, so unlike rung 16 this one +# is an INSTALL-ONLY rung: it is inserted into a pristine upstream file and is +# a no-op on the already-instrumented tree. +I="$SRC/av1/common/reconintra.c" +[ -f "$I" ] || { echo "no oracle source at $I" >&2; exit 1; } + +python3 - "$I" <<'PYND' +import sys +path = sys.argv[1] +s = open(path).read() +if "EC_PREDND" in s: + print("EC_PREDND already instrumented (no-op)") + sys.exit(0) + +old = """ highbd_build_non_directional_intra_predictors( + ref, ref_stride, dst, dst_stride, mode, tx_size, n_top_px, n_left_px, + xd->bd); + return; + }""" +new = """ highbd_build_non_directional_intra_predictors( + ref, ref_stride, dst, dst_stride, mode, tx_size, n_top_px, n_left_px, + xd->bd); + /* EC_INSTRUMENTED_PREDND (non-directional, high bitdepth) */ + if (getenv("EC_PRED")) { + const int ec_mi_row = -xd->mb_to_top_edge >> (3 + MI_SIZE_LOG2); + const int ec_mi_col = -xd->mb_to_left_edge >> (3 + MI_SIZE_LOG2); + const uint16_t *d16 = CONVERT_TO_SHORTPTR(dst); + long sum = 0; + for (int r = 0; r < txhpx; ++r) + for (int c = 0; c < txwpx; ++c) sum += d16[r * dst_stride + c]; + fprintf(stderr, + "EC_PREDND mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d " + "txw=%d txh=%d mode=%d n_top=%d n_left=%d sum=%ld row0=", + ec_mi_row, ec_mi_col, plane, row_off, col_off, txwpx, txhpx, + mode, n_top_px, n_left_px, sum); + for (int c = 0; c < txwpx && c < 8; ++c) fprintf(stderr, "%d,", d16[c]); + fprintf(stderr, " col0="); + for (int r = 0; r < txhpx && r < 8; ++r) + fprintf(stderr, "%d,", d16[r * dst_stride]); + fprintf(stderr, "\\n"); + } + return; + }""" +assert old in s, "highbd non-directional intra predictor tail moved" +s = s.replace(old, new, 1) +open(path, "w").write(s) +print("EC_PREDND instrumented (non-directional, high bitdepth)") +PYND