forge
Explore
Log in

Don't you dare go Hollow

rungs 16/17: script EC_PREDOUT8 (with mode=) and EC_PREDND onto current main

Browse files at this commit

079a7cdc9f6a58c788f9a67c7c19cc534a9b4acfAhmet Kaan GümüşParent: b207cf9
Reconstruction, not replay. lane-av1cmpaudit's commit 3d0001bc predates the HBD
repair block that has since landed on main, so re-applying it as a patch would
clobber that block; the rung bodies were re-applied to the CURRENT script instead.
The script diff is one insert-only hunk (@@ -1076,0 +1077,153 @@), zero deletions,
so the repair block provably survives.

What was actually absent from main is bigger than it looked: NOT just the script
half. `grep -c 'OUR_PRED x={x} y={y} plane=' crates/ec-av1/src/decode.rs` is 0 on
main, so the Rust twin field (RECON_PLANE / recon_plane() / PlaneGuard, `plane=` on
both OUR_PRED sites) is absent as well, and 3d0001bc is not an ancestor of main.

1. rung 16, EC_PREDOUT8 at BOTH 8-bit prediction sites in reconintra.c (the
   non-directional early return and the directional / filter-intra tail), with
   `mode=` on both. Install on a pristine file, and upgrade of the no-mode form the
   oracle tree's git HEAD carries, so a rebuild reproduces the live tree.

2. rung 17, EC_PREDND, the 10/12-bit non-directional site. This is the one that
   matters: rung 16 and the pre-existing EC_PREDOUT both sit after the is_hbd early
   return, so without rung 17 a rebuilt oracle prints NOTHING on a high-bitdepth
   stream -- the failure the rung exists to remove.

3. decode.rs gains `plane=` on both OUR_PRED sites so an EC_PREDOUT8/EC_PREDND vs
   OUR_PRED diff can tell a luma/chroma disagreement from a same-plane one. Behind
   the existing EC_PRED flag; RECON_PLANE is read only by that rung.

4. check-aom-oracle-rungs.sh now also restores reconintra.c to pristine before
   deriving (it previously only restored decodeframe.c, so a rung living in
   reconintra.c was never exercised at all), and asserts: rung 16 installed at both
   sites, mode= on both, rung 17 installed once, mode= present, plus a round-trip of
   the no-mode upgrade form. All ten pre-existing checks still print ok, exit 0.
   Mutation-proved: deleting rung 17, dropping rung 16's directional site, and
   dropping its mode= each red the corresponding assertion.

Evidence (one configure, two aomdec builds differing only in reconintra.c):
12-bit av112bit-key.obu -> 118 EC_PREDND lines with the rungs, 0 lines and empty
stderr without them. 8-bit ii-flake-1.obu -> 15 EC_PREDOUT8 lines, 15/15 with
mode=, 0 without. Decoded output byte-identical either way (md5 6b29cc50... /
482b5e04...). On ours, decode_probe prints 177 OUR_PRED lines, all 177 carrying
plane=, pairing field-for-field with the oracle's first three EC_PREDND lines.

cargo check -p ec-av1 --lib: clean, no warnings.
crates/ec-av1/src/decode.rsmodified+35 -2
@@ -4429,6 +4429,12 @@ fn exec_intra(
4429 1 => &mut *u,4429 1 => &mut *u,
4430 _ => &mut *v,4430 _ => &mut *v,
4431 };4431 };
4432+ // lane-av1cmpaudit: label the in-flight reconstruction's plane for the
4433+ // `EC_PRED` rung (aomdec's `EC_PREDOUT8`/`EC_PREDND` print `plane=`).
4434+ // Saved and restored so the rung reports THIS call's plane even under
4435+ // nesting, and so both of exec_intra's return paths need no cleanup.
4436+ let prev_plane = RECON_PLANE.with(|c| c.replace(plane));
4437+ let _plane_guard = PlaneGuard(prev_plane);
4432 if rect {4438 if rect {
4433 target.reconstruct_rect(4439 target.reconstruct_rect(
4434 x,4440 x,
@@ -6975,6 +6981,31 @@ fn note_chroma_class1(plane_idx: usize, tx_type: TxType) {
6975 }6981 }
6976 }6982 }
6977 6983
6984+// Which plane the in-flight INTRA reconstruction is writing (0=Y, 1=U, 2=V).
6985+// lane-av1cmpaudit: aomdec's `EC_PREDOUT8`/`EC_PREDND` print `plane=`, and
6986+// without the same field on our side an `EC_PREDOUT8` vs `OUR_PRED` diff of a
6987+// per-plane prediction cannot be read off ours -- a luma/chroma disagreement
6988+// looked identical to a same-plane disagreement. Set by `exec_intra` (the
6989+// single place a `PlaneBuf::reconstruct{,_rect}` is reached from) and read only
6990+// by the `EC_PRED` rung, so it cannot change a decode.
6991+thread_local! {
6992+ static RECON_PLANE: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
6993+}
6994+
6995+/// The plane index the `EC_PRED` rung prints as `plane=`.
6996+fn recon_plane() -> usize {
6997+ RECON_PLANE.with(std::cell::Cell::get)
6998+}
6999+
7000+/// Restores [`RECON_PLANE`] on drop, so `exec_intra` needs no cleanup path on
7001+/// either of its two early returns.
7002+struct PlaneGuard(usize);
7003+impl Drop for PlaneGuard {
7004+ fn drop(&mut self) {
7005+ RECON_PLANE.with(|c| c.set(self.0));
7006+ }
7007+}
7008+
6978 const SUB_MI: u32 = 4;7009 const SUB_MI: u32 = 4;
6979 const MI: usize = 4;7010 const MI: usize = 4;
6980 const SB: usize = 64;7011 const SB: usize = 64;
@@ -20174,8 +20205,9 @@ impl PlaneBuf<'_> {
20174 let row0: Vec<u16> = prediction[..bw.min(8)].to_vec();20205 let row0: Vec<u16> = prediction[..bw.min(8)].to_vec();
20175 let col0: Vec<u16> = (0..bh.min(8)).map(|r| prediction[r * bw]).collect();20206 let col0: Vec<u16> = (0..bh.min(8)).map(|r| prediction[r * bw]).collect();
20176 eprintln!(20207 eprintln!(
20177- "@{} OUR_PRED x={x} y={y} bw={bw} bh={bh} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}",20208+ "@{} OUR_PRED x={x} y={y} plane={} bw={bw} bh={bh} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}",
20178 std::panic::Location::caller(),20209 std::panic::Location::caller(),
20210+ recon_plane(),
20179 i32::from(smooth_neighbor)20211 i32::from(smooth_neighbor)
20180 );20212 );
20181 }20213 }
@@ -20313,8 +20345,9 @@ impl PlaneBuf<'_> {
20313 let row0: Vec<u16> = prediction[..side.min(8)].to_vec();20345 let row0: Vec<u16> = prediction[..side.min(8)].to_vec();
20314 let col0: Vec<u16> = (0..side.min(8)).map(|r| prediction[r * side]).collect();20346 let col0: Vec<u16> = (0..side.min(8)).map(|r| prediction[r * side]).collect();
20315 eprintln!(20347 eprintln!(
20316- "@{} OUR_PRED x={x} y={y} side={side} side={side} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}",20348+ "@{} OUR_PRED x={x} y={y} plane={} side={side} side={side} mode={mode} ad={angle_delta} ft={} sum={sum} row0={row0:?} col0={col0:?}",
20317 std::panic::Location::caller(),20349 std::panic::Location::caller(),
20350+ recon_plane(),
20318 i32::from(smooth_neighbor)20351 i32::from(smooth_neighbor)
20319 );20352 );
20320 }20353 }
lanes/av1rungs17.report.mdadded+236 -0
@@ -0,0 +1,236 @@
1+# lane-av1rungs17 — script rungs 16/17 (EC_PREDOUT8, EC_PREDND)
2+
3+Base: `f33b9d41` (main, `lanes/av1merge-wave3c-b`). Branch: `lane-av1rungs17`.
4+Method: **reconstruction** onto the current script, not replay of the old one.
5+
6+## 1. What was actually absent from main
7+
8+The task brief said "main's `decode.rs` already prints `OUR_PRED … plane=`-style
9+lines, so the C-side may be ahead of the script-side". **That premise is wrong, and
10+the correction matters because it changes the size of the hole:**
11+
12+```
13+$ grep -c 'OUR_PRED x={x} y={y} plane=' crates/ec-av1/src/decode.rs # on main
14+0
15+$ git merge-base --is-ancestor 3d0001bc HEAD # lane-av1cmpaudit's commit
16+NOT ancestor
17+```
18+
19+Main has **zero** `plane=` on `OUR_PRED` (both sites are the lane's pre-change form
20+`OUR_PRED x={x} y={y} bw=…` / `… side={side} …`), and no `RECON_PLANE` thread-local
21+or `PlaneGuard` — main's `recon_planes` hits are an unrelated `ReconPlanes` Y/U/V
22+struct. So **the whole of commit `3d0001bc` is absent from main, not just its script
23+half**: the Rust twin field as well as the two rungs.
24+
25+Genuinely absent, in full:
26+
27+| item | where it lived | on main |
28+|---|---|---|
29+| `RECON_PLANE` / `recon_plane()` / `PlaneGuard`, `plane=` on both `OUR_PRED` sites | `3d0001bc` | absent |
30+| 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`) |
31+| rung 17 — `EC_PREDND`, the hbd non-directional site | staged, uncommitted in `av1cmpaudit` | absent |
32+
33+Present on main and **deliberately not touched**: rungs 1–15, the HBD repair block
34+(`ec_dump_narrow_row`, `ec_dump_finish`, the halved-pointer fix) and
35+`scripts/check-aom-oracle-rungs.sh`.
36+
37+### `stash@{0}` is a false lead — nothing of rung 16 is in it
38+
39+The stash message claims *"EC_PREDOUT8 rung 16 in `scripts/instrument-aom-oracle.sh`"*.
40+Its actual content is two Rust files from an unrelated lane:
41+
42+```
43+$ git stash show --stat stash@{0}
44+ crates/ec-av1/src/decode.rs | 106 ++++++++++++-----
45+ crates/ec-av1/src/stream.rs | 185 ++++++++++++++++++++++++++++
46+$ git ls-tree -r stash@{0}^3
47+100644 blob ec4a3e66… lanes/ibc444c.report.md # the lane it came from
48+```
49+
50+No script file, no `RECON_PLANE`, no `plane=` in its `OUR_PRED`. The stash's byte-copy
51+(`/tmp/foreign-instrument-aom-oracle.sh.keep`) is already gone. **Nothing was lost
52+twice**: the rung-16 script change exists once, in `3d0001bc`, and the rung-17 change
53+exists once, staged in `av1cmpaudit`. Both are now reconstructed here.
54+
55+## 2. Reconstruction
56+
57+`~/.cache/wt/av1rungs17`, branched at `f33b9d41`. Nothing was cherry-picked or
58+`git apply`'d; the rung bodies were re-applied to the **current** files.
59+
60+* `scripts/instrument-aom-oracle.sh` — rungs 16 and 17 appended **after** the repair
61+ block. The diff against main is a *single* hunk, `@@ -1076,0 +1077,153 @@`, i.e. pure
62+ append with zero deletions: the repair block cannot have been overwritten, because
63+ `git diff` shows not one of its lines changing.
64+* `crates/ec-av1/src/decode.rs` — the `RECON_PLANE` thread-local, `recon_plane()`,
65+ `PlaneGuard`, the set-and-restore in `exec_intra`, and `plane=` on both `OUR_PRED`
66+ sites. Re-derived against current main: `exec_intra` is still the single caller of
67+ `PlaneBuf::reconstruct{,_rect}` (`reconstruct_rect` @4439, `reconstruct` @4455, both
68+ inside `fn exec_intra` @4405), so the thread-local is still set for every call that
69+ reaches a `reconstruct`.
70+* `scripts/check-aom-oracle-rungs.sh` — extended, see §3.
71+
72+## 3. The checker: 10 ok preserved, 4 added, all non-vacuous
73+
74+The checker previously restored only `av1/decoder/decodeframe.c` to pristine, so a
75+rung living in `reconintra.c` was never exercised by it — it would have taken the
76+"already instrumented" branch and asserted nothing. It now also restores
77+`av1/common/reconintra.c` from the base ref before deriving.
78+
79+```
80+$ bash scripts/check-aom-oracle-rungs.sh
81+ok legacy u8 row loops left in the derived file 0
82+ok ec_dump_narrow_row call sites (4 rungs x 3 planes) 12
83+ok ec_dump_finish call sites (one per narrowing rung) 4
84+ok byte-count check wired into EC_AV1_PREFILT_DUMP 1
85+ok byte-count check wired into EC_AV1_POSTDEBLOCK_DUMP 1
86+ok byte-count check wired into EC_AV1_PREFILT_WIDE_DUMP 1
87+ok byte-count check wired into EC_AV1_POSTCDEF_DUMP 1
88+ok rung 12 still converts plane pointers 1
89+ok rung 12 not routed through the narrowing checker 0
90+ok rung 16 EC_PREDOUT8 install sites (both 8-bit paths) 2
91+ok rung 16 EC_PREDOUT8 sites carry mode= (EC_PREDND field order) 2
92+ok rung 17 EC_PREDND install sites (hbd non-directional) 1
93+ok rung 17 EC_PREDND site carries mode= 1
94+ok instrument-aom-oracle.sh derives the depth-correct, byte-checked rungs (base v3.13.3)
95+exit 0
96+```
97+
98+All ten pre-existing checks still print `ok` and the exit code is still 0. The four new
99+ones are the ones a rebuild must not lose: rung 16 at **both** 8-bit sites (a one-site
100+install looks fine on the directional arm and prints nothing for every non-directional
101+block), `mode=` surviving on both, rung 17 present, and rung 17's `mode=`.
102+
103+A fifth, non-`check` assertion covers the claim in rung 16's own comment that it is
104+idempotent in **both** directions: the checker synthesises the no-`mode=` form the
105+oracle tree's git HEAD carries, re-derives, and requires the result to land back on the
106+identical bytes.
107+
108+**Non-vacuity** (each mutation run against the real checker; every one reds on the
109+specific assertion, exit 1):
110+
111+| mutation | result |
112+|---|---|
113+| rung 17 deleted from the script | `FAIL rung 17 EC_PREDND install sites … got 0, want 1` |
114+| rung 16 installs only the non-directional site | `FAIL rung 16 EC_PREDOUT8 install sites … got 1, want 2` |
115+| rung 16's directional site loses `mode=` | `FAIL rung 16 EC_PREDOUT8 sites carry mode= … got 1, want 2` |
116+
117+## 4. Idempotence and correct derivation from pristine
118+
119+Starting from a copy of the oracle tree with **both** files restored to `v3.13.3`
120+(`reconintra.c` has 0 rung sites):
121+
122+```
123+$ bash scripts/instrument-aom-oracle.sh
124+EC_PREDOUT8 installed (both 8-bit paths, with mode=)
125+EC_PREDND instrumented (non-directional, high bitdepth)
126+```
127+
128+* **Insert-only on pristine**: derived `reconintra.c` vs pristine is **41 added lines,
129+ 0 removed**, every one of them inside the two rung bodies. No stray edits.
130+* **Second run is a no-op** — both files byte-unchanged:
131+ ```
132+ EC_PREDOUT8 already carries mode= (no-op)
133+ EC_PREDND already instrumented (no-op)
134+ reconintra.c: NO-OP decodeframe.c: NO-OP
135+ ```
136+* **Fidelity to the live hand-patched tree**: the derived `reconintra.c` is
137+ byte-identical to `~/.cache/aom-oracle/src/av1/common/reconintra.c` on the rung
138+ bodies; the only differences are the two comment lines (mine say
139+ `EC_INSTRUMENTED_PREDOUT8 …`, the hand-patch says `EC_PREDOUT8 … (lane-d792)`) and
140+ three instruments that belong to *other* lanes and are in neither this script nor
141+ main's (see §7).
142+
143+## 5. (a) insert-only on pristine / no-op when already instrumented
144+
145+Covered in §4: 41 insertions, 0 deletions on pristine; second run no-op; the checker
146+now asserts both, plus the no-`mode=` upgrade round-trip.
147+
148+## 6. (b) and (c) — the whole reason these rungs exist
149+
150+One configure, two `aomdec` binaries, differing **only** in `av1/common/reconintra.c`
151+(the second is one recompile plus a relink, not a second libaom build). Built from
152+`$P/src` after `scripts/instrument-aom-oracle.sh` derived it; then `reconintra.c` was
153+replaced with the pristine `v3.13.3` file and rebuilt.
154+
155+### (b) WITH rungs — 12-bit `fixtures/av112bit-key.obu`
156+
157+```
158+$ EC_PRED=1 ./aomdec-with-rungs --rawvideo -o out-with.yuv av112bit-key.obu
159+EC_PREDND lines: 118
160+EC_PREDOUT8 lines: 0
161+```
162+
163+```
164+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,…
165+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,…
166+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,…
167+```
168+
169+Note `EC_PREDOUT8` prints **0** on a 12-bit stream — that is the point of rung 17, not
170+a defect in it.
171+
172+### (c) WITHOUT rungs — same build recipe, same stream
173+
174+```
175+$ EC_PRED=1 ./aomdec-no-rungs --rawvideo -o out-without.yuv av112bit-key.obu
176+stderr lines total: 0
177+EC_PREDND lines: 0
178+```
179+
180+Completely silent. Nothing is printed, so nothing can be diffed.
181+
182+### Rung 16 on the 8-bit arm, `fixtures/ii-flake-1.obu`
183+
184+```
185+WITH rungs: EC_PREDOUT8 15 carrying mode= 15/15
186+ 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,…
187+ 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,…
188+WITHOUT rungs: EC_PREDOUT8 0
189+```
190+
191+### The rungs do not change the decode
192+
193+```
194+6b29cc506f88c8c89afd8b999f218947 out-with.yuv (12-bit)
195+6b29cc506f88c8c89afd8b999f218947 out-without.yuv
196+482b5e04208ad5ff077e970c8cee6439 f8-with.yuv (8-bit)
197+482b5e04208ad5ff077e970c8cee6439 f8-without.yuv
198+```
199+
200+### The Rust twin now pairs with the oracle
201+
202+`decode_probe` on the same 12-bit fixture: **177 `OUR_PRED` lines, 177 of them carrying
203+`plane=`**, values `plane=0 plane=1 plane=2`. The first three pair field-for-field with
204+the first three `EC_PREDND` lines above — same `plane`, same `16x8`/`8x4` extent, same
205+`mode=0`, same `sum=262144`/`65536`:
206+
207+```
208+@…/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, …]
209+@…/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, …]
210+@…/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, …]
211+```
212+
213+Build is clean: `cargo check -p ec-av1 --lib` → `Finished`, no warnings, no errors.
214+
215+## 7. Left standing, deliberately
216+
217+`EC_DR` / `EC_DR_OUT` (4 sites) are in the live oracle tree and in **no** rung of the
218+script — main's or this one. Same class, different lane's instrument; out of scope here.
219+Worth a lane of its own.
220+
221+The rung-gap census from `av1cmpaudit`'s staged report (preserved verbatim at
222+`~/.cache/tmp/r17proof/av1cmpaudit.report.staged.md`) puts the wider class at
223+**84 rung/env names in the live tree, 40 covered by the script, 48 dropped by a
224+rebuild before this round; rungs 16/17 close 2, 46 remain.** That number is
225+attributed, not re-derived here.
226+
227+## 8. Disposition of `~/.cache/wt/av1cmpaudit`
228+
229+Worktree left intact and untouched at `3d0001bc`; nothing was deleted.
230+
231+| uncommitted item | disposition |
232+|---|---|
233+| staged `scripts/instrument-aom-oracle.sh` (rung 17) | **landed here** as rung 17 |
234+| 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) |
235+| `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 |
236+| committed `3d0001bc` | not merged as a commit (it predates the HBD repair block, so a replay would clobber it); its content is reconstructed here |
scripts/check-aom-oracle-rungs.shmodified+75 -4
@@ -10,10 +10,16 @@
10 # aomdec crash during a decode is found late; this reds on the DERIVATION10 # aomdec crash during a decode is found late; this reds on the DERIVATION
11 # instead, in seconds, without a build.11 # instead, in seconds, without a build.
12 #12 #
13+# The same class of loss applies to the prediction rungs: EC_PREDOUT8 (rung
14+# 16) and EC_PREDND (rung 17) lived only in the hand-patched oracle tree, so
15+# a rebuild from the script dropped the only probe that prints on a 10/12-bit
16+# stream (both, and the pre-existing EC_PREDOUT, sit after an `is_hbd` early
17+# return). Those are asserted here too, from a PRISTINE reconintra.c.
18+#
13 # What it does: copies the oracle source tree to a scratch dir, replaces19 # What it does: copies the oracle source tree to a scratch dir, replaces
14-# av1/decoder/decodeframe.c with the PRISTINE upstream file, runs the20+# av1/decoder/decodeframe.c and av1/common/reconintra.c with the PRISTINE
15-# instrument script over the copy, and asserts the derived file's shape. The21+# upstream files, runs the instrument script over the copy, and asserts the
16-# real oracle tree is never written to.22+# derived files' shape. The real oracle tree is never written to.
17 #23 #
18 # Usage:24 # Usage:
19 # scripts/check-aom-oracle-rungs.sh [SRC_DIR] [BASE_REF]25 # scripts/check-aom-oracle-rungs.sh [SRC_DIR] [BASE_REF]
@@ -25,8 +31,10 @@ SRC="${1:-${AOM_ORACLE_SRC:-$HOME/.cache/aom-oracle/src}}"
25 BASE="${2:-${AOM_ORACLE_BASE_REF:-v3.13.3}}"31 BASE="${2:-${AOM_ORACLE_BASE_REF:-v3.13.3}}"
26 HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"32 HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
27 DERIVED="$SRC/av1/decoder/decodeframe.c"33 DERIVED="$SRC/av1/decoder/decodeframe.c"
34+RECONINTRA="$SRC/av1/common/reconintra.c"
28 35
29 [ -f "$DERIVED" ] || { echo "no oracle source at $DERIVED" >&2; exit 1; }36 [ -f "$DERIVED" ] || { echo "no oracle source at $DERIVED" >&2; exit 1; }
37+[ -f "$RECONINTRA" ] || { echo "no oracle source at $RECONINTRA" >&2; exit 1; }
30 git -C "$SRC" rev-parse --verify "$BASE^{commit}" >/dev/null 2>&1 || {38 git -C "$SRC" rev-parse --verify "$BASE^{commit}" >/dev/null 2>&1 || {
31 echo "base ref '$BASE' is not a commit in $SRC" >&239 echo "base ref '$BASE' is not a commit in $SRC" >&2
32 exit 140 exit 1
@@ -36,6 +44,7 @@ WORK="$(mktemp -d "${TMPDIR:-$HOME/.cache/tmp}/aom-rung-check.XXXXXX")"
36 trap 'rm -rf "$WORK"' EXIT44 trap 'rm -rf "$WORK"' EXIT
37 cp -a "$SRC" "$WORK/src"45 cp -a "$SRC" "$WORK/src"
38 git -C "$SRC" show "$BASE:av1/decoder/decodeframe.c" > "$WORK/src/av1/decoder/decodeframe.c"46 git -C "$SRC" show "$BASE:av1/decoder/decodeframe.c" > "$WORK/src/av1/decoder/decodeframe.c"
47+git -C "$SRC" show "$BASE:av1/common/reconintra.c" > "$WORK/src/av1/common/reconintra.c"
39 48
40 AOM_ORACLE_SRC="$WORK/src" bash "$HERE/instrument-aom-oracle.sh" > "$WORK/derive.log" 2>&1 || {49 AOM_ORACLE_SRC="$WORK/src" bash "$HERE/instrument-aom-oracle.sh" > "$WORK/derive.log" 2>&1 || {
41 echo "FAIL: instrument-aom-oracle.sh errored on a pristine tree:" >&250 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
43 exit 152 exit 1
44 }53 }
45 cp "$WORK/src/av1/decoder/decodeframe.c" "$WORK/derived.c"54 cp "$WORK/src/av1/decoder/decodeframe.c" "$WORK/derived.c"
55+cp "$WORK/src/av1/common/reconintra.c" "$WORK/derived-intra.c"
46 56
47 # Re-running must be a no-op, or the repair pass is not idempotent and a57 # Re-running must be a no-op, or the repair pass is not idempotent and a
48 # second run would rewrite a tree under someone's feet.58 # 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" || {
51 echo "FAIL: a second instrument-aom-oracle.sh run changed the derived file" >&261 echo "FAIL: a second instrument-aom-oracle.sh run changed the derived file" >&2
52 exit 162 exit 1
53 }63 }
64+cmp -s "$WORK/derived-intra.c" "$WORK/src/av1/common/reconintra.c" || {
65+ echo "FAIL: a second instrument-aom-oracle.sh run changed reconintra.c" >&2
66+ exit 1
67+}
54 68
55 fail=069 fail=0
56 check() { # description, actual, expected70 check() { # description, actual, expected
@@ -85,8 +99,65 @@ check "rung 12 still converts plane pointers" "$conv" "1"
85 r12=$(grep -c 'ec_dump_finish(ec_f, "EC_AV1_FINAL_DUMP"' "$WORK/derived.c" || true)99 r12=$(grep -c 'ec_dump_finish(ec_f, "EC_AV1_FINAL_DUMP"' "$WORK/derived.c" || true)
86 check "rung 12 not routed through the narrowing checker" "$r12" "0"100 check "rung 12 not routed through the narrowing checker" "$r12" "0"
87 101
102+# --- rungs 16/17: the prediction rungs (lane-av1rungs17) --------------------
103+# EC_PREDOUT8 must be installed at BOTH 8-bit prediction sites in
104+# reconintra.c -- the non-directional early return (DC, SMOOTH*, PAETH) and
105+# the directional / filter-intra tail. A one-site install would look fine on
106+# the directional arm and print nothing at all for every non-directional
107+# block, which is most of an intra frame.
108+p8=$(grep -c 'EC_PREDOUT8 mi_row=%d' "$WORK/derived-intra.c" || true)
109+check "rung 16 EC_PREDOUT8 install sites (both 8-bit paths)" "$p8" "2"
110+
111+# `mode=` is what makes a non-directional diff attributable at all; a rebuild
112+# that lost it would still install two sites and still pass the count above.
113+p8m=$(grep -c 'EC_PREDOUT8 mi_row=%d.*txh=%d mode=%d sum=%ld' "$WORK/derived-intra.c" || true)
114+check "rung 16 EC_PREDOUT8 sites carry mode= (EC_PREDND field order)" "$p8m" "2"
115+
116+# EC_PREDND is the hbd twin and the ONLY prediction probe that fires on a
117+# 10/12-bit stream. One site, at the non-directional early return.
118+pnd=$(grep -c 'EC_PREDND mi_row=%d' "$WORK/derived-intra.c" || true)
119+check "rung 17 EC_PREDND install sites (hbd non-directional)" "$pnd" "1"
120+pndm=$(grep -c 'txw=%d txh=%d mode=%d n_top=%d n_left=%d' "$WORK/derived-intra.c" || true)
121+check "rung 17 EC_PREDND site carries mode=" "$pndm" "1"
122+
123+# Rung 16 claims to be idempotent in BOTH directions: an install on a
124+# pristine file, AND an upgrade of the no-`mode=` form the oracle tree's git
125+# HEAD carries. Rebuild the no-mode form, re-derive, and require the result to
126+# land back on the same bytes -- an upgrade path that silently no-ops (or
127+# double-writes) is exactly what a rebuild would hit.
128+python3 - "$WORK/derived-intra.c" "$WORK/nomode-intra.c" <<'PYUP'
129+import sys
130+s = open(sys.argv[1]).read()
131+# Strip `mode=` from the format string and `mode` from the argument list at
132+# both EC_PREDOUT8 sites only; EC_PREDND's own mode= must survive untouched.
133+for fmt_old, fmt_new in (
134+ ('txw=%d txh=%d mode=%d sum=%ld row0=", xd->mi_row',
135+ 'txw=%d txh=%d sum=%ld row0=", xd->mi_row'),
136+ ('txw=%d txh=%d mode=%d sum=%ld row0=", mi_row',
137+ 'txw=%d txh=%d sum=%ld row0=", mi_row'),
138+):
139+ assert fmt_old in s, "upgrade fixture: %r not found" % fmt_old
140+ s = s.replace(fmt_old, fmt_new, 1)
141+assert s.count('col_off, txwpx, txhpx, mode, ec_sum);') == 2, "upgrade fixture: args"
142+s = s.replace('col_off, txwpx, txhpx, mode, ec_sum);',
143+ 'col_off, txwpx, txhpx, ec_sum);')
144+assert 'EC_PREDOUT8 mi_row=%d' in s and s.count('txw=%d txh=%d sum=%ld row0=') == 2
145+open(sys.argv[2], 'w').write(s)
146+PYUP
147+cp "$WORK/nomode-intra.c" "$WORK/src/av1/common/reconintra.c"
148+AOM_ORACLE_SRC="$WORK/src" bash "$HERE/instrument-aom-oracle.sh" > "$WORK/upgrade.log" 2>&1 || {
149+ echo "FAIL: instrument-aom-oracle.sh errored on the no-mode reconintra.c:" >&2
150+ tail -20 "$WORK/upgrade.log" >&2
151+ exit 1
152+}
153+cmp -s "$WORK/derived-intra.c" "$WORK/src/av1/common/reconintra.c" || {
154+ echo "FAIL: re-deriving the no-mode EC_PREDOUT8 form did not land back on the derived bytes" >&2
155+ diff -u "$WORK/derived-intra.c" "$WORK/src/av1/common/reconintra.c" | head -30 >&2
156+ exit 1
157+}
158+
88 if [ "$fail" -ne 0 ]; then159 if [ "$fail" -ne 0 ]; then
89- echo "FAIL: derived decodeframe.c violates the rung contract (base $BASE)" >&2160+ echo "FAIL: a derived file violates the rung contract (base $BASE)" >&2
90 exit 1161 exit 1
91 fi162 fi
92 echo "ok instrument-aom-oracle.sh derives the depth-correct, byte-checked rungs (base $BASE)"163 echo "ok instrument-aom-oracle.sh derives the depth-correct, byte-checked rungs (base $BASE)"
scripts/instrument-aom-oracle.shmodified+153 -0
@@ -1074,3 +1074,156 @@ else:
1074 print("dump byte-count check: every narrowing rung already checks its bytes")1074 print("dump byte-count check: every narrowing rung already checks its bytes")
1075 open(path, "w").write(s)1075 open(path, "w").write(s)
1076 PYN1076 PYN
1077+
1078+# --- rung 16: EC_PREDOUT8, the 8-bit predicted block (lane-av1cmpaudit) ----
1079+# This rung lived ONLY in the hand-patched oracle tree -- `instrument-aom-
1080+# oracle.sh` never transcribed it -- so a rebuild from this script silently
1081+# dropped it (class: instrument that lives only in a build tree, the same
1082+# reason rung 13 exists). It is transcribed here at BOTH 8-bit prediction
1083+# sites in reconintra.c: the non-directional early-return path (DC, SMOOTH*,
1084+# PAETH) and the directional / filter-intra tail. lane-av1cmpaudit also grew
1085+# `mode=` on both: without it, an agreeing-top / disagreeing-bottom pattern
1086+# on a non-directional unit could not be attributed to a mode at all.
1087+# `mode=` sits after `txh=`, matching EC_PREDND's own field order; every
1088+# pre-existing field keeps its position.
1089+#
1090+# Idempotent, and an UPGRADE as well as an install: the oracle tree's git HEAD
1091+# already carries the rung WITHOUT `mode=`, so the script has to rewrite that
1092+# form too, not just insert the block into a pristine upstream file.
1093+I="$SRC/av1/common/reconintra.c"
1094+[ -f "$I" ] || { echo "no oracle source at $I" >&2; exit 1; }
1095+
1096+python3 - "$I" <<'PYRI'
1097+import sys
1098+path = sys.argv[1]
1099+s = open(path).read()
1100+
1101+if 'EC_PREDOUT8' not in s:
1102+ # Pristine upstream: insert the rung at both 8-bit prediction sites.
1103+ nd_old = """ build_non_directional_intra_predictors(ref, ref_stride, dst, dst_stride,
1104+ mode, tx_size, n_top_px, n_left_px);
1105+ return;
1106+ }"""
1107+ nd_new = """ build_non_directional_intra_predictors(ref, ref_stride, dst, dst_stride,
1108+ mode, tx_size, n_top_px, n_left_px);
1109+ /* EC_INSTRUMENTED_PREDOUT8 (non-directional, 8-bit) */
1110+ if (getenv("EC_PRED")) {
1111+ long ec_sum = 0;
1112+ for (int r = 0; r < txhpx; ++r)
1113+ for (int c = 0; c < txwpx; ++c) ec_sum += dst[r * dst_stride + c];
1114+ 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);
1115+ for (int c = 0; c < txwpx && c < 8; ++c) fprintf(stderr, "%d,", dst[c]);
1116+ fprintf(stderr, " col0=");
1117+ for (int r = 0; r < txhpx && r < 8; ++r) fprintf(stderr, "%d,", dst[r * dst_stride]);
1118+ fprintf(stderr, "\\n");
1119+ }
1120+ return;
1121+ }"""
1122+ assert nd_old in s, "non-directional intra predictor tail moved"
1123+ s = s.replace(nd_old, nd_new, 1)
1124+
1125+ dir_old = """ build_directional_and_filter_intra_predictors(
1126+ ref, ref_stride, dst, dst_stride, mode, p_angle, filter_intra_mode,
1127+ tx_size, disable_edge_filter, n_top_px, n_topright_px, n_left_px,
1128+ n_bottomleft_px, intra_edge_filter_type);
1129+}"""
1130+ dir_new = """ build_directional_and_filter_intra_predictors(
1131+ ref, ref_stride, dst, dst_stride, mode, p_angle, filter_intra_mode,
1132+ tx_size, disable_edge_filter, n_top_px, n_topright_px, n_left_px,
1133+ n_bottomleft_px, intra_edge_filter_type);
1134+ /* EC_INSTRUMENTED_PREDOUT8 (directional / filter-intra, 8-bit) */
1135+ if (getenv("EC_PRED")) {
1136+ long ec_sum = 0;
1137+ for (int r = 0; r < txhpx; ++r)
1138+ for (int c = 0; c < txwpx; ++c) ec_sum += dst[r * dst_stride + c];
1139+ 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);
1140+ for (int c = 0; c < txwpx && c < 8; ++c) fprintf(stderr, "%d,", dst[c]);
1141+ fprintf(stderr, " col0=");
1142+ for (int r = 0; r < txhpx && r < 8; ++r) fprintf(stderr, "%d,", dst[r * dst_stride]);
1143+ fprintf(stderr, "\\n");
1144+ }
1145+}"""
1146+ assert dir_old in s, "directional intra predictor tail moved"
1147+ s = s.replace(dir_old, dir_new, 1)
1148+ open(path, "w").write(s)
1149+ print("EC_PREDOUT8 installed (both 8-bit paths, with mode=)")
1150+ sys.exit(0)
1151+
1152+# Already present: upgrade the rung to carry `mode=` if it does not yet.
1153+nd_fmt_old = 'txw=%d txh=%d sum=%ld row0=", xd->mi_row'
1154+nd_fmt_new = 'txw=%d txh=%d mode=%d sum=%ld row0=", xd->mi_row'
1155+dir_fmt_old = 'txw=%d txh=%d sum=%ld row0=", mi_row'
1156+dir_fmt_new = 'txw=%d txh=%d mode=%d sum=%ld row0=", mi_row'
1157+upgraded = 0
1158+arg_old = "col_off, txwpx, txhpx, ec_sum);"
1159+arg_new = "col_off, txwpx, txhpx, mode, ec_sum);"
1160+if nd_fmt_old in s:
1161+ s = s.replace(nd_fmt_old, nd_fmt_new, 1)
1162+ assert arg_old in s, "EC_PREDOUT8 non-directional argument list moved"
1163+ s = s.replace(arg_old, arg_new, 1)
1164+ upgraded += 1
1165+if dir_fmt_old in s:
1166+ s = s.replace(dir_fmt_old, dir_fmt_new, 1)
1167+ assert arg_old in s, "EC_PREDOUT8 directional argument list moved"
1168+ s = s.replace(arg_old, arg_new, 1)
1169+ upgraded += 1
1170+if upgraded:
1171+ open(path, "w").write(s)
1172+ print("EC_PREDOUT8 upgraded to mode= (%d site(s))" % upgraded)
1173+else:
1174+ print("EC_PREDOUT8 already carries mode= (no-op)")
1175+PYRI
1176+
1177+# --- rung 17: EC_PREDND, the hbd twin of EC_PREDOUT8 (lane-av1cmpaudit) ----
1178+# The 10/12-bit non-directional twin of rung 16, and like it this rung lived
1179+# ONLY in the hand-patched oracle tree. Without it a rebuild drops the only
1180+# prediction probe that fires on a high-bitdepth stream -- rung 16 and the
1181+# pre-existing EC_PREDOUT both sit after the `is_hbd` early return and print
1182+# nothing there. EC_PREDND already carried `mode=`, so unlike rung 16 this one
1183+# is an INSTALL-ONLY rung: it is inserted into a pristine upstream file and is
1184+# a no-op on the already-instrumented tree.
1185+I="$SRC/av1/common/reconintra.c"
1186+[ -f "$I" ] || { echo "no oracle source at $I" >&2; exit 1; }
1187+
1188+python3 - "$I" <<'PYND'
1189+import sys
1190+path = sys.argv[1]
1191+s = open(path).read()
1192+if "EC_PREDND" in s:
1193+ print("EC_PREDND already instrumented (no-op)")
1194+ sys.exit(0)
1195+
1196+old = """ highbd_build_non_directional_intra_predictors(
1197+ ref, ref_stride, dst, dst_stride, mode, tx_size, n_top_px, n_left_px,
1198+ xd->bd);
1199+ return;
1200+ }"""
1201+new = """ highbd_build_non_directional_intra_predictors(
1202+ ref, ref_stride, dst, dst_stride, mode, tx_size, n_top_px, n_left_px,
1203+ xd->bd);
1204+ /* EC_INSTRUMENTED_PREDND (non-directional, high bitdepth) */
1205+ if (getenv("EC_PRED")) {
1206+ const int ec_mi_row = -xd->mb_to_top_edge >> (3 + MI_SIZE_LOG2);
1207+ const int ec_mi_col = -xd->mb_to_left_edge >> (3 + MI_SIZE_LOG2);
1208+ const uint16_t *d16 = CONVERT_TO_SHORTPTR(dst);
1209+ long sum = 0;
1210+ for (int r = 0; r < txhpx; ++r)
1211+ for (int c = 0; c < txwpx; ++c) sum += d16[r * dst_stride + c];
1212+ fprintf(stderr,
1213+ "EC_PREDND mi_row=%d mi_col=%d plane=%d row_off=%d col_off=%d "
1214+ "txw=%d txh=%d mode=%d n_top=%d n_left=%d sum=%ld row0=",
1215+ ec_mi_row, ec_mi_col, plane, row_off, col_off, txwpx, txhpx,
1216+ mode, n_top_px, n_left_px, sum);
1217+ for (int c = 0; c < txwpx && c < 8; ++c) fprintf(stderr, "%d,", d16[c]);
1218+ fprintf(stderr, " col0=");
1219+ for (int r = 0; r < txhpx && r < 8; ++r)
1220+ fprintf(stderr, "%d,", d16[r * dst_stride]);
1221+ fprintf(stderr, "\\n");
1222+ }
1223+ return;
1224+ }"""
1225+assert old in s, "highbd non-directional intra predictor tail moved"
1226+s = s.replace(old, new, 1)
1227+open(path, "w").write(s)
1228+print("EC_PREDND instrumented (non-directional, high bitdepth)")
1229+PYND