| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | set -euo pipefail |
| 54 | SRC="${AOM_ORACLE_SRC:-$HOME/.cache/aom-oracle/src}" |
| 55 | F="$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 | |
| 58 | python3 - "$F" <<'PY' |
| 59 | import sys, re |
| 60 | path = sys.argv[1] |
| 61 | s = open(path).read() |
| 62 | if "EC_INSTRUMENTED" in s: |
| 63 | print("already instrumented (no-op)") |
| 64 | sys.exit(0) |
| 65 | |
| 66 | # --- rung 2: partition range ladder ------------------------------------- |
| 67 | old_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) {""" |
| 70 | new_sig = """/* EC_INSTRUMENTED */ |
| 71 | static 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 | |
| 76 | static 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 | |
| 96 | static 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) {""" |
| 100 | assert old_sig in s, "read_partition signature moved" |
| 101 | s = s.replace(old_sig, new_sig, 1) |
| 102 | |
| 103 | # --- rung 1: pre-filter recon dump -------------------------------------- |
| 104 | anchor = """ av1_alloc_cdef_buffers(cm, &pbi->cdef_worker, &pbi->cdef_sync, |
| 105 | pbi->num_workers, 1);""" |
| 106 | dump = """ { |
| 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 | """ |
| 132 | assert anchor in s, "cdef alloc anchor moved" |
| 133 | s = s.replace(anchor, dump + anchor, 1) |
| 134 | open(path, "w").write(s) |
| 135 | print("instrumented") |
| 136 | PY |
| 137 | echo "now: ninja -C ${AOM_ORACLE_BUILD:-$HOME/.cache/aom-oracle/build} aomdec" |
| 138 | |
| 139 | |
| 140 | G="$SRC/av1/decoder/decodetxb.c" |
| 141 | [ -f "$G" ] || { echo "no oracle source at $G" >&2; exit 1; } |
| 142 | |
| 143 | python3 - "$G" <<'PYC' |
| 144 | import sys |
| 145 | path = sys.argv[1] |
| 146 | s = open(path).read() |
| 147 | if "EC_INSTRUMENTED" in s: |
| 148 | print("decodetxb already instrumented (no-op)") |
| 149 | sys.exit(0) |
| 150 | |
| 151 | old = """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) {""" |
| 154 | new = """/* EC_INSTRUMENTED */ |
| 155 | static 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 | |
| 161 | void 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 | |
| 176 | static 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) {""" |
| 181 | assert old in s, "av1_read_coeffs_txb signature moved" |
| 182 | s = s.replace(old, new, 1) |
| 183 | open(path, "w").write(s) |
| 184 | print("decodetxb instrumented") |
| 185 | PYC |
| 186 | |
| 187 | |
| 188 | H="$SRC/av1/decoder/decodemv.c" |
| 189 | [ -f "$H" ] || { echo "no oracle source at $H" >&2; exit 1; } |
| 190 | |
| 191 | python3 - "$H" <<'PYM' |
| 192 | import sys |
| 193 | path = sys.argv[1] |
| 194 | s = open(path).read() |
| 195 | if "EC_INSTRUMENTED" in s: |
| 196 | print("decodemv already instrumented (no-op)") |
| 197 | sys.exit(0) |
| 198 | |
| 199 | old = """static void read_inter_block_mode_info(AV1Decoder *const pbi, |
| 200 | DecoderCodingBlock *dcb, |
| 201 | MB_MODE_INFO *const mbmi, |
| 202 | aom_reader *r) {""" |
| 203 | new = """/* EC_INSTRUMENTED */ |
| 204 | static 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 | |
| 209 | static 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 | |
| 231 | static void ec_read_inter_block_mode_info_impl(AV1Decoder *const pbi, |
| 232 | DecoderCodingBlock *dcb, |
| 233 | MB_MODE_INFO *const mbmi, |
| 234 | aom_reader *r) {""" |
| 235 | assert old in s, "read_inter_block_mode_info signature moved" |
| 236 | s = s.replace(old, new, 1) |
| 237 | open(path, "w").write(s) |
| 238 | print("decodemv instrumented") |
| 239 | PYM |
| 240 | |
| 241 | |
| 242 | python3 - "$SRC/av1/decoder/decodemv.c" <<'PYI' |
| 243 | import sys |
| 244 | path = sys.argv[1] |
| 245 | s = open(path).read() |
| 246 | if "EC_INSTRUMENTED_INTRA" in s: |
| 247 | print("intra mode-info already instrumented (no-op)") |
| 248 | sys.exit(0) |
| 249 | |
| 250 | old = """static void read_intra_frame_mode_info(AV1_COMMON *const cm, |
| 251 | DecoderCodingBlock *dcb, aom_reader *r) {""" |
| 252 | new = """/* EC_INSTRUMENTED_INTRA */ |
| 253 | static void ec_read_intra_frame_mode_info_impl(AV1_COMMON *const cm, |
| 254 | DecoderCodingBlock *dcb, |
| 255 | aom_reader *r); |
| 256 | |
| 257 | static 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 | |
| 278 | static void ec_read_intra_frame_mode_info_impl(AV1_COMMON *const cm, |
| 279 | DecoderCodingBlock *dcb, |
| 280 | aom_reader *r) {""" |
| 281 | assert old in s, "read_intra_frame_mode_info signature moved" |
| 282 | s = s.replace(old, new, 1) |
| 283 | open(path, "w").write(s) |
| 284 | print("intra mode-info instrumented") |
| 285 | PYI |
| 286 | |
| 287 | |
| 288 | python3 - "$F" <<'PYD' |
| 289 | import sys |
| 290 | path = sys.argv[1] |
| 291 | s = open(path).read() |
| 292 | if "EC_INSTRUMENTED_POSTDEBLOCK" in s: |
| 293 | print("postdeblock dump already instrumented (no-op)") |
| 294 | sys.exit(0) |
| 295 | |
| 296 | anchor = """ 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 | """ |
| 302 | dump = """ |
| 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 | """ |
| 334 | assert anchor in s, "loop filter call anchor moved" |
| 335 | s = s.replace(anchor, anchor + dump, 1) |
| 336 | open(path, "w").write(s) |
| 337 | print("postdeblock dump instrumented") |
| 338 | PYD |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | python3 - "$F" <<'PYW' |
| 347 | import sys |
| 348 | path = sys.argv[1] |
| 349 | s = open(path).read() |
| 350 | if "EC_INSTRUMENTED_PREFILT_WIDE" in s: |
| 351 | print("prefilt-wide dump already instrumented (no-op)") |
| 352 | sys.exit(0) |
| 353 | |
| 354 | anchor = """ av1_alloc_cdef_buffers(cm, &pbi->cdef_worker, &pbi->cdef_sync, |
| 355 | pbi->num_workers, 1);""" |
| 356 | dump = """ /* 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 | """ |
| 384 | assert anchor in s, "cdef alloc anchor moved" |
| 385 | s = s.replace(anchor, dump + anchor, 1) |
| 386 | open(path, "w").write(s) |
| 387 | print("prefilt-wide dump instrumented") |
| 388 | PYW |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | I="$SRC/av1/decoder/detokenize.c" |
| 398 | [ -f "$I" ] || { echo "no oracle source at $I" >&2; exit 1; } |
| 399 | |
| 400 | python3 - "$I" <<'PYP' |
| 401 | import sys |
| 402 | path = sys.argv[1] |
| 403 | s = open(path).read() |
| 404 | if "EC_INSTRUMENTED_PALETTE" in s: |
| 405 | print("palette map already instrumented (no-op)") |
| 406 | sys.exit(0) |
| 407 | |
| 408 | old = """ 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];""" |
| 414 | new = """/* 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 | }""" |
| 430 | assert old in s, "decode_color_map_tokens loop body moved" |
| 431 | s = s.replace(old, new, 1) |
| 432 | s = 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 | ) |
| 437 | open(path, "w").write(s) |
| 438 | print("palette map instrumented") |
| 439 | PYP |
| 440 | |
| 441 | |
| 442 | python3 - "$I" <<'PYP0' |
| 443 | import sys |
| 444 | path = sys.argv[1] |
| 445 | s = open(path).read() |
| 446 | if "EC_INSTRUMENTED_PALETTE_UNIFORM" in s: |
| 447 | print("palette map[0] already instrumented (no-op)") |
| 448 | sys.exit(0) |
| 449 | |
| 450 | old = """ // The first color index. |
| 451 | color_map[0] = av1_read_uniform(r, n); |
| 452 | assert(color_map[0] < n);""" |
| 453 | new = """ // 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 | }""" |
| 465 | assert old in s, "color_map[0] uniform read moved" |
| 466 | s = s.replace(old, new, 1) |
| 467 | open(path, "w").write(s) |
| 468 | print("palette map[0] instrumented") |
| 469 | PYP0 |
| 470 | |
| 471 | |
| 472 | I="$SRC/av1/common/restoration.c" |
| 473 | [ -f "$I" ] || { echo "no oracle source at $I" >&2; exit 1; } |
| 474 | |
| 475 | python3 - "$I" <<'PYA' |
| 476 | import sys |
| 477 | path = sys.argv[1] |
| 478 | s = open(path).read() |
| 479 | if "/* EC_INSTRUMENTED_AB */" in s: |
| 480 | print("calculate_intermediate_result already exported (no-op)") |
| 481 | sys.exit(0) |
| 482 | |
| 483 | old = """static void calculate_intermediate_result(int32_t *dgd, int width, int height,""" |
| 484 | new = """/* EC_INSTRUMENTED_AB */ |
| 485 | void calculate_intermediate_result(int32_t *dgd, int width, int height,""" |
| 486 | assert old in s, "calculate_intermediate_result signature moved" |
| 487 | s = s.replace(old, new, 1) |
| 488 | open(path, "w").write(s) |
| 489 | print("calculate_intermediate_result exported") |
| 490 | PYA |