forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust375.4 MiBca4790fTahinli3 months ago1157 commits

instrument-aom-oracle.sh490 lines, 20.9 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# Add the decode-localization instrumentation to the libaom oracle's aomdec.
3#
4# These patches used to live only in the hand-built /tmp tree; the 2026-08-30
5# tmpfs reclaim destroyed them along with the tree (see memory
6# oracle-in-reaped-dir). They are re-derived here so `build-aom-oracle.sh` +
7# this script reproduce the full ladder from scratch.
8#
9# Rungs provided (both env-gated, so an uninstrumented run is unchanged):
10# EC_AV1_PREFILT_DUMP=<prefix> -> <prefix>.f<N> per frame, Y then U then V,
11# crop-sized rows, written after tile decode and BEFORE any loop filter,
12# CDEF or LR. Diff against our own EC_AV1_PREFILT_DUMP to separate a
13# reconstruction mismatch from a filtering one.
14# EC_TRACE=1 -> "EC_PART mi_row=.. mi_col=.. bsize=.. ctx=.. tell=.. rng=.."
15# before every partition symbol, "EC_PART_VAL .. value=.." after. The
16# range ladder: compare rng element-by-element against our own
17# `TRACE part32_pre` (class compare-range-not-tell -- ranges, never tell).
18# EC_TRACE_COEFF=1 -> "EC_COEFF plane=.. row=.. col=.. tx_size=.. rng=.."
19# before every coefficient block, "EC_COEFF_VAL .. rng=.." after.
20# Partition granularity is too coarse to localize a coefficient desync;
21# two lanes stalled on 2026-08-30 because this rung did not exist.
22# EC_TRACE_MODE=1 -> "EC_MODE mi_row=.. mi_col=.. rng=.." before every inter
23# block's mode info, "EC_MODE_VAL .. mode=.. ref0/1=.. mv0=.. rng=.."
24# after -- the mv-stack/DRL/mv reads EC_PART cannot see. The same flag
25# also emits "EC_IMODE .. rng=.." / "EC_IMODE_VAL .. mode=.. uv_mode=..
26# skip=.. tx=.. rng=.." around every INTRA key-frame block: without it
27# the key-frame path has no traced symbol at all between the partition
28# read and the first coefficient block, which is precisely the gap a
29# rect-strip desync hides in.
30# EC_AV1_POSTDEBLOCK_DUMP=<prefix> -> <prefix>.f<N> per frame, Y then U then
31# V, full ALIGNED-buffer rows (y_width/y_height, not y_crop_width --
32# cm->cur_frame->buf at this point is still the pre-superres buffer,
33# but its aligned width already extends past FrameWidth out to the
34# mi-aligned true width, which is exactly the margin content we need).
35# Written right after av1_loop_filter_frame_mt returns and before
36# CDEF/superres run -- ground truth for the post-deblock, pre-superres
37# row content over frame_width..true_width that decode.rs stashes as
38# its superres margin (lane-superres r5: hand-tracing the arithmetic
39# could only prove our own self-consistency, not correctness against
40# libaom).
41# Rung 9 (unconditional, no env gate) -- SGR per-tap ground truth
42# (lane-lr r7): `calculate_intermediate_result` in
43# av1/common/restoration.c is `static`, so a standalone harness cannot
44# call it to get real A[]/B[] intermediate arrays, only the final
45# flt0/flt1 via the public av1_selfguided_restoration_c. This rung
46# drops `static` so an external harness can call it directly with a
47# `dgd32`-style buffer (see scripts/lr-sgr-pin-harness.c) and diff
48# every A[k]/B[k] tap against a from-scratch recompute -- the missing
49# half of r6's 9-tap cross-check. No behaviour change (only linkage).
50#
51# Idempotent: re-running is a no-op. Rebuild afterwards with
52# ninja -C ~/.cache/aom-oracle/build aomdec
53set -euo pipefail
54SRC="${AOM_ORACLE_SRC:-$HOME/.cache/aom-oracle/src}"
55F="$SRC/av1/decoder/decodeframe.c"
56[ -f "$F" ] || { echo "no oracle source at $F -- run scripts/build-aom-oracle.sh first" >&2; exit 1; }
57
58python3 - "$F" <<'PY'
59import sys, re
60path = sys.argv[1]
61s = open(path).read()
62if "EC_INSTRUMENTED" in s:
63 print("already instrumented (no-op)")
64 sys.exit(0)
65
66# --- rung 2: partition range ladder -------------------------------------
67old_sig = """static PARTITION_TYPE read_partition(MACROBLOCKD *xd, int mi_row, int mi_col,
68 aom_reader *r, int has_rows, int has_cols,
69 BLOCK_SIZE bsize) {"""
70new_sig = """/* EC_INSTRUMENTED */
71static PARTITION_TYPE ec_read_partition_impl(MACROBLOCKD *xd, int mi_row,
72 int mi_col, aom_reader *r,
73 int has_rows, int has_cols,
74 BLOCK_SIZE bsize);
75
76static PARTITION_TYPE read_partition(MACROBLOCKD *xd, int mi_row, int mi_col,
77 aom_reader *r, int has_rows, int has_cols,
78 BLOCK_SIZE bsize) {
79 const int ec_trace = getenv("EC_TRACE") != NULL;
80 if (ec_trace) {
81 fprintf(stderr,
82 "EC_PART mi_row=%d mi_col=%d bsize=%d ctx=%d tell=%d rng=%u\\n",
83 mi_row, mi_col, (int)bsize,
84 partition_plane_context(xd, mi_row, mi_col, bsize),
85 (int)aom_reader_tell(r), (unsigned)r->ec.rng);
86 }
87 PARTITION_TYPE ec_p =
88 ec_read_partition_impl(xd, mi_row, mi_col, r, has_rows, has_cols, bsize);
89 if (ec_trace) {
90 fprintf(stderr, "EC_PART_VAL mi_row=%d mi_col=%d bsize=%d value=%d\\n",
91 mi_row, mi_col, (int)bsize, (int)ec_p);
92 }
93 return ec_p;
94}
95
96static PARTITION_TYPE ec_read_partition_impl(MACROBLOCKD *xd, int mi_row,
97 int mi_col, aom_reader *r,
98 int has_rows, int has_cols,
99 BLOCK_SIZE bsize) {"""
100assert old_sig in s, "read_partition signature moved"
101s = s.replace(old_sig, new_sig, 1)
102
103# --- rung 1: pre-filter recon dump --------------------------------------
104anchor = """ av1_alloc_cdef_buffers(cm, &pbi->cdef_worker, &pbi->cdef_sync,
105 pbi->num_workers, 1);"""
106dump = """ {
107 const char *ec_dump = getenv("EC_AV1_PREFILT_DUMP");
108 if (ec_dump) {
109 static int ec_prefilt_idx = 0;
110 char ec_path[1024];
111 snprintf(ec_path, sizeof(ec_path), "%s.f%d", ec_dump, ec_prefilt_idx++);
112 FILE *ec_f = fopen(ec_path, "wb");
113 if (ec_f) {
114 const YV12_BUFFER_CONFIG *ec_b = &cm->cur_frame->buf;
115 for (int ec_r = 0; ec_r < ec_b->y_crop_height; ++ec_r)
116 fwrite(ec_b->y_buffer + ec_r * ec_b->y_stride, 1, ec_b->y_crop_width,
117 ec_f);
118 if (num_planes > 1) {
119 for (int ec_r = 0; ec_r < ec_b->uv_crop_height; ++ec_r)
120 fwrite(ec_b->u_buffer + ec_r * ec_b->uv_stride, 1,
121 ec_b->uv_crop_width, ec_f);
122 for (int ec_r = 0; ec_r < ec_b->uv_crop_height; ++ec_r)
123 fwrite(ec_b->v_buffer + ec_r * ec_b->uv_stride, 1,
124 ec_b->uv_crop_width, ec_f);
125 }
126 fclose(ec_f);
127 }
128 }
129 }
130
131"""
132assert anchor in s, "cdef alloc anchor moved"
133s = s.replace(anchor, dump + anchor, 1)
134open(path, "w").write(s)
135print("instrumented")
136PY
137echo "now: ninja -C ${AOM_ORACLE_BUILD:-$HOME/.cache/aom-oracle/build} aomdec"
138
139# --- rung 3: coefficient range ladder (decodetxb.c) ---------------------
140G="$SRC/av1/decoder/decodetxb.c"
141[ -f "$G" ] || { echo "no oracle source at $G" >&2; exit 1; }
142
143python3 - "$G" <<'PYC'
144import sys
145path = sys.argv[1]
146s = open(path).read()
147if "EC_INSTRUMENTED" in s:
148 print("decodetxb already instrumented (no-op)")
149 sys.exit(0)
150
151old = """void av1_read_coeffs_txb(const AV1_COMMON *const cm, DecoderCodingBlock *dcb,
152 aom_reader *const r, const int plane, const int row,
153 const int col, const TX_SIZE tx_size) {"""
154new = """/* EC_INSTRUMENTED */
155static void ec_read_coeffs_txb_impl(const AV1_COMMON *const cm,
156 DecoderCodingBlock *dcb,
157 aom_reader *const r, const int plane,
158 const int row, const int col,
159 const TX_SIZE tx_size);
160
161void av1_read_coeffs_txb(const AV1_COMMON *const cm, DecoderCodingBlock *dcb,
162 aom_reader *const r, const int plane, const int row,
163 const int col, const TX_SIZE tx_size) {
164 const int ec_trace = getenv("EC_TRACE_COEFF") != NULL;
165 if (ec_trace) {
166 fprintf(stderr, "EC_COEFF plane=%d row=%d col=%d tx_size=%d rng=%u\\n",
167 plane, row, col, (int)tx_size, (unsigned)r->ec.rng);
168 }
169 ec_read_coeffs_txb_impl(cm, dcb, r, plane, row, col, tx_size);
170 if (ec_trace) {
171 fprintf(stderr, "EC_COEFF_VAL plane=%d row=%d col=%d rng=%u\\n", plane, row,
172 col, (unsigned)r->ec.rng);
173 }
174}
175
176static void ec_read_coeffs_txb_impl(const AV1_COMMON *const cm,
177 DecoderCodingBlock *dcb,
178 aom_reader *const r, const int plane,
179 const int row, const int col,
180 const TX_SIZE tx_size) {"""
181assert old in s, "av1_read_coeffs_txb signature moved"
182s = s.replace(old, new, 1)
183open(path, "w").write(s)
184print("decodetxb instrumented")
185PYC
186
187# --- rung 4: mode-info range ladder (decodemv.c) ------------------------
188H="$SRC/av1/decoder/decodemv.c"
189[ -f "$H" ] || { echo "no oracle source at $H" >&2; exit 1; }
190
191python3 - "$H" <<'PYM'
192import sys
193path = sys.argv[1]
194s = open(path).read()
195if "EC_INSTRUMENTED" in s:
196 print("decodemv already instrumented (no-op)")
197 sys.exit(0)
198
199old = """static void read_inter_block_mode_info(AV1Decoder *const pbi,
200 DecoderCodingBlock *dcb,
201 MB_MODE_INFO *const mbmi,
202 aom_reader *r) {"""
203new = """/* EC_INSTRUMENTED */
204static void ec_read_inter_block_mode_info_impl(AV1Decoder *const pbi,
205 DecoderCodingBlock *dcb,
206 MB_MODE_INFO *const mbmi,
207 aom_reader *r);
208
209static void read_inter_block_mode_info(AV1Decoder *const pbi,
210 DecoderCodingBlock *dcb,
211 MB_MODE_INFO *const mbmi,
212 aom_reader *r) {
213 const int ec_trace = getenv("EC_TRACE_MODE") != NULL;
214 const MACROBLOCKD *const ec_xd = &dcb->xd;
215 if (ec_trace) {
216 fprintf(stderr, "EC_MODE mi_row=%d mi_col=%d rng=%u\\n", ec_xd->mi_row,
217 ec_xd->mi_col, (unsigned)r->ec.rng);
218 }
219 ec_read_inter_block_mode_info_impl(pbi, dcb, mbmi, r);
220 if (ec_trace) {
221 fprintf(stderr,
222 "EC_MODE_VAL mi_row=%d mi_col=%d mode=%d ref0=%d ref1=%d "
223 "mv0=(%d,%d) rng=%u\\n",
224 ec_xd->mi_row, ec_xd->mi_col, (int)mbmi->mode,
225 (int)mbmi->ref_frame[0], (int)mbmi->ref_frame[1],
226 mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col,
227 (unsigned)r->ec.rng);
228 }
229}
230
231static void ec_read_inter_block_mode_info_impl(AV1Decoder *const pbi,
232 DecoderCodingBlock *dcb,
233 MB_MODE_INFO *const mbmi,
234 aom_reader *r) {"""
235assert old in s, "read_inter_block_mode_info signature moved"
236s = s.replace(old, new, 1)
237open(path, "w").write(s)
238print("decodemv instrumented")
239PYM
240
241# --- rung 5: intra key-frame mode-info ladder (decodemv.c) --------------
242python3 - "$SRC/av1/decoder/decodemv.c" <<'PYI'
243import sys
244path = sys.argv[1]
245s = open(path).read()
246if "EC_INSTRUMENTED_INTRA" in s:
247 print("intra mode-info already instrumented (no-op)")
248 sys.exit(0)
249
250old = """static void read_intra_frame_mode_info(AV1_COMMON *const cm,
251 DecoderCodingBlock *dcb, aom_reader *r) {"""
252new = """/* EC_INSTRUMENTED_INTRA */
253static void ec_read_intra_frame_mode_info_impl(AV1_COMMON *const cm,
254 DecoderCodingBlock *dcb,
255 aom_reader *r);
256
257static void read_intra_frame_mode_info(AV1_COMMON *const cm,
258 DecoderCodingBlock *dcb, aom_reader *r) {
259 const int ec_trace = getenv("EC_TRACE_MODE") != NULL;
260 const MACROBLOCKD *const ec_xd = &dcb->xd;
261 if (ec_trace) {
262 fprintf(stderr, "EC_IMODE mi_row=%d mi_col=%d bsize=%d rng=%u\\n",
263 ec_xd->mi_row, ec_xd->mi_col, (int)ec_xd->mi[0]->bsize,
264 (unsigned)r->ec.rng);
265 }
266 ec_read_intra_frame_mode_info_impl(cm, dcb, r);
267 if (ec_trace) {
268 const MB_MODE_INFO *const ec_mbmi = ec_xd->mi[0];
269 fprintf(stderr,
270 "EC_IMODE_VAL mi_row=%d mi_col=%d mode=%d uv_mode=%d skip=%d "
271 "tx=%d rng=%u\\n",
272 ec_xd->mi_row, ec_xd->mi_col, (int)ec_mbmi->mode,
273 (int)ec_mbmi->uv_mode, (int)ec_mbmi->skip_txfm,
274 (int)ec_mbmi->tx_size, (unsigned)r->ec.rng);
275 }
276}
277
278static void ec_read_intra_frame_mode_info_impl(AV1_COMMON *const cm,
279 DecoderCodingBlock *dcb,
280 aom_reader *r) {"""
281assert old in s, "read_intra_frame_mode_info signature moved"
282s = s.replace(old, new, 1)
283open(path, "w").write(s)
284print("intra mode-info instrumented")
285PYI
286
287# --- rung 6: post-deblock, pre-superres row dump ------------------------
288python3 - "$F" <<'PYD'
289import sys
290path = sys.argv[1]
291s = open(path).read()
292if "EC_INSTRUMENTED_POSTDEBLOCK" in s:
293 print("postdeblock dump already instrumented (no-op)")
294 sys.exit(0)
295
296anchor = """ if (cm->lf.filter_level[0] || cm->lf.filter_level[1]) {
297 av1_loop_filter_frame_mt(&cm->cur_frame->buf, cm, &pbi->dcb.xd, 0,
298 num_planes, 0, pbi->tile_workers,
299 pbi->num_workers, &pbi->lf_row_sync, 0);
300 }
301"""
302dump = """
303 /* EC_INSTRUMENTED_POSTDEBLOCK */
304 {
305 const char *ec_dump = getenv("EC_AV1_POSTDEBLOCK_DUMP");
306 if (ec_dump) {
307 static int ec_postdeblock_idx = 0;
308 char ec_path[1024];
309 snprintf(ec_path, sizeof(ec_path), "%s.f%d", ec_dump,
310 ec_postdeblock_idx++);
311 FILE *ec_f = fopen(ec_path, "wb");
312 if (ec_f) {
313 const YV12_BUFFER_CONFIG *ec_b = &cm->cur_frame->buf;
314 /* Dump the FULL aligned buffer (y_width/y_height), not the
315 * crop_width/crop_height (== FrameWidth/FrameHeight): the
316 * superres margin (columns [FrameWidth, true mi-aligned width))
317 * only exists in the aligned buffer -- lane-superres r5. */
318 for (int ec_r = 0; ec_r < ec_b->y_height; ++ec_r)
319 fwrite(ec_b->y_buffer + ec_r * ec_b->y_stride, 1, ec_b->y_width,
320 ec_f);
321 if (num_planes > 1) {
322 for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r)
323 fwrite(ec_b->u_buffer + ec_r * ec_b->uv_stride, 1,
324 ec_b->uv_width, ec_f);
325 for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r)
326 fwrite(ec_b->v_buffer + ec_r * ec_b->uv_stride, 1,
327 ec_b->uv_width, ec_f);
328 }
329 fclose(ec_f);
330 }
331 }
332 }
333"""
334assert anchor in s, "loop filter call anchor moved"
335s = s.replace(anchor, anchor + dump, 1)
336open(path, "w").write(s)
337print("postdeblock dump instrumented")
338PYD
339
340# --- rung 7: pre-deblock, FULL aligned-buffer row dump (lane-superres r5) -
341# EC_AV1_PREFILT_DUMP (rung 1) is used by other lanes at its existing
342# y_crop_width/y_crop_height shape -- left untouched. This adds a second,
343# additive env var at the SAME anchor (pre-loop-filter) but dumping the full
344# y_width/y_height aligned buffer, so a margin-region reconstruction bug can
345# be told apart from a margin-region deblock bug.
346python3 - "$F" <<'PYW'
347import sys
348path = sys.argv[1]
349s = open(path).read()
350if "EC_INSTRUMENTED_PREFILT_WIDE" in s:
351 print("prefilt-wide dump already instrumented (no-op)")
352 sys.exit(0)
353
354anchor = """ av1_alloc_cdef_buffers(cm, &pbi->cdef_worker, &pbi->cdef_sync,
355 pbi->num_workers, 1);"""
356dump = """ /* EC_INSTRUMENTED_PREFILT_WIDE */
357 {
358 const char *ec_dump = getenv("EC_AV1_PREFILT_WIDE_DUMP");
359 if (ec_dump) {
360 static int ec_prefilt_wide_idx = 0;
361 char ec_path[1024];
362 snprintf(ec_path, sizeof(ec_path), "%s.f%d", ec_dump,
363 ec_prefilt_wide_idx++);
364 FILE *ec_f = fopen(ec_path, "wb");
365 if (ec_f) {
366 const YV12_BUFFER_CONFIG *ec_b = &cm->cur_frame->buf;
367 for (int ec_r = 0; ec_r < ec_b->y_height; ++ec_r)
368 fwrite(ec_b->y_buffer + ec_r * ec_b->y_stride, 1, ec_b->y_width,
369 ec_f);
370 if (num_planes > 1) {
371 for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r)
372 fwrite(ec_b->u_buffer + ec_r * ec_b->uv_stride, 1,
373 ec_b->uv_width, ec_f);
374 for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r)
375 fwrite(ec_b->v_buffer + ec_r * ec_b->uv_stride, 1,
376 ec_b->uv_width, ec_f);
377 }
378 fclose(ec_f);
379 }
380 }
381 }
382
383"""
384assert anchor in s, "cdef alloc anchor moved"
385s = s.replace(anchor, dump + anchor, 1)
386open(path, "w").write(s)
387print("prefilt-wide dump instrumented")
388PYW
389# --- rung 8: palette colour-index map range ladder (detokenize.c) -------
390# EC_TRACE_PALETTE=1 -> "EC_PAL row=.. col=.. ctx=.. n=.. rng=.." before every
391# colour-index symbol in decode_color_map_tokens's wavefront, "EC_PAL_VAL
392# row=.. col=.. color_idx=.. rng=.." after. lane-palette r4: r3 already
393# cleared every table/context function against this same source line-for-line
394# by hand; this rung is what lets a real per-symbol range compare (class
395# compare-range-not-tell / equal-range-means-unread) replace that by-hand
396# check instead of re-reading the tables again.
397I="$SRC/av1/decoder/detokenize.c"
398[ -f "$I" ] || { echo "no oracle source at $I" >&2; exit 1; }
399
400python3 - "$I" <<'PYP'
401import sys
402path = sys.argv[1]
403s = open(path).read()
404if "EC_INSTRUMENTED_PALETTE" in s:
405 print("palette map already instrumented (no-op)")
406 sys.exit(0)
407
408old = """ const int color_ctx = av1_get_palette_color_index_context(
409 color_map, plane_block_width, (i - j), j, n, color_order, NULL);
410 const int color_idx = aom_read_symbol(
411 r, color_map_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR);
412 assert(color_idx >= 0 && color_idx < n);
413 color_map[(i - j) * plane_block_width + j] = color_order[color_idx];"""
414new = """/* EC_INSTRUMENTED_PALETTE */
415 const int color_ctx = av1_get_palette_color_index_context(
416 color_map, plane_block_width, (i - j), j, n, color_order, NULL);
417 const int ec_pal_trace = getenv("EC_TRACE_PALETTE") != NULL;
418 if (ec_pal_trace) {
419 fprintf(stderr, "EC_PAL row=%d col=%d ctx=%d n=%d rng=%u\\n", (i - j),
420 j, color_ctx, n, (unsigned)r->ec.rng);
421 }
422 const int color_idx = aom_read_symbol(
423 r, color_map_cdf[n - PALETTE_MIN_SIZE][color_ctx], n, ACCT_STR);
424 assert(color_idx >= 0 && color_idx < n);
425 color_map[(i - j) * plane_block_width + j] = color_order[color_idx];
426 if (ec_pal_trace) {
427 fprintf(stderr, "EC_PAL_VAL row=%d col=%d color_idx=%d rng=%u\\n",
428 (i - j), j, color_idx, (unsigned)r->ec.rng);
429 }"""
430assert old in s, "decode_color_map_tokens loop body moved"
431s = s.replace(old, new, 1)
432s = s.replace(
433 "static void decode_color_map_tokens(Av1ColorMapParam *param, aom_reader *r) {",
434 "/* EC_INSTRUMENTED_PALETTE */\nstatic void decode_color_map_tokens(Av1ColorMapParam *param, aom_reader *r) {",
435 1,
436)
437open(path, "w").write(s)
438print("palette map instrumented")
439PYP
440
441# --- rung 8b: palette map[0] (av1_read_uniform) range ladder ------------
442python3 - "$I" <<'PYP0'
443import sys
444path = sys.argv[1]
445s = open(path).read()
446if "EC_INSTRUMENTED_PALETTE_UNIFORM" in s:
447 print("palette map[0] already instrumented (no-op)")
448 sys.exit(0)
449
450old = """ // The first color index.
451 color_map[0] = av1_read_uniform(r, n);
452 assert(color_map[0] < n);"""
453new = """ // The first color index.
454 /* EC_INSTRUMENTED_PALETTE_UNIFORM */
455 if (getenv("EC_TRACE_PALETTE") != NULL) {
456 fprintf(stderr, "EC_PAL row=0 col=0 ctx=-1 n=%d rng=%u\\n", n,
457 (unsigned)r->ec.rng);
458 }
459 color_map[0] = av1_read_uniform(r, n);
460 assert(color_map[0] < n);
461 if (getenv("EC_TRACE_PALETTE") != NULL) {
462 fprintf(stderr, "EC_PAL_VAL row=0 col=0 color_idx=%d rng=%u\\n",
463 color_map[0], (unsigned)r->ec.rng);
464 }"""
465assert old in s, "color_map[0] uniform read moved"
466s = s.replace(old, new, 1)
467open(path, "w").write(s)
468print("palette map[0] instrumented")
469PYP0
470
471# --- rung 9: export calculate_intermediate_result for a direct harness call
472I="$SRC/av1/common/restoration.c"
473[ -f "$I" ] || { echo "no oracle source at $I" >&2; exit 1; }
474
475python3 - "$I" <<'PYA'
476import sys
477path = sys.argv[1]
478s = open(path).read()
479if "/* EC_INSTRUMENTED_AB */" in s:
480 print("calculate_intermediate_result already exported (no-op)")
481 sys.exit(0)
482
483old = """static void calculate_intermediate_result(int32_t *dgd, int width, int height,"""
484new = """/* EC_INSTRUMENTED_AB */
485void calculate_intermediate_result(int32_t *dgd, int width, int height,"""
486assert old in s, "calculate_intermediate_result signature moved"
487s = s.replace(old, new, 1)
488open(path, "w").write(s)
489print("calculate_intermediate_result exported")
490PYA