"""Rough SH-2 decode-cost model over a codec_study run (assumptions, not measurements). Per frame: IDCT 1,000 cycles per coded 8x8 block; bitstream 64 cycles per byte; motion-compensated copy 1,200 cycles per MC MB (byte copies, odd vectors); colour conversion (YCbCr -> RGB555 -> palette LUT -> frame buffer) 15 cycles per pixel for every MB changed in this frame or the last (double buffering), 256 pixels per MB. Budget: two SH-2s at 22.8 MHz (PAL) over 25 fps = 1.82 M cycles per frame. """ import json, sys from pathlib import Path BUDGET = 2 * 22_800_000 / 25 for d in sys.argv[1:]: rows = json.loads((Path(d) / "frames.json").read_text()) cyc, prev_changed = [], 280 for r in rows: changed = 280 - r["skip_mbs"] conv = min(280, changed + prev_changed) * 256 * 15 prev_changed = changed cyc.append(r["coded_blocks"] * 1000 + r["bytes"] * 64 + r["mc_mbs"] * 1200 + conv) over = sum(c > BUDGET for c in cyc) cyc.sort() print(f"{d}: median {cyc[len(cyc)//2]/BUDGET:.0%} p95 {cyc[int(len(cyc)*.95)]/BUDGET:.0%} max {cyc[-1]/BUDGET:.0%} frames over budget {over}/{len(cyc)}")