#!/usr/bin/env python3 """Create the clean chain of commits from the rebuilt trees and the quiet batch's A/B files. Prints the new tip; does not move any branch.""" import pathlib, re, subprocess, sys ROOT = pathlib.Path("/data/emu/pcengine-rust-fast") CHAIN = ROOT / "external" / "chain" TREES = ROOT / "external" / "trees" BASE = "678d5af" # the tooling commit TRAILER = "Co-Authored-By: Claude Fable 5.2 " GATE = "Gate: cargo test, 275 of 275 lockstep cases, 18 of 18 save-state round trips and run-ahead passes." def ab(name, where="chain"): text = (ROOT / "external" / where / f"{name}.txt").read_text() titles = re.findall(r"^(.*?): A [\d.]+ fps, B [\d.]+ fps, (x[\d.]+)$", text, re.M) overall = re.search(r"overall (x[\d.]+)", text).group(1) return overall, ", ".join(f"{t} {f}" for t, f in titles) def lto_name(name): return "L00" if name == "forkpoint" else "L" + name[1:] def measured(prev, name, frames, port=False): if name == "k12": overall, titles = ab("k11-k12") return overall, (f"A/B of this tree built without it against the same tree built with it (best of 12 a side, " f"{frames} frames, CPU time, one pinned core): {titles}; overall {overall}.") overall, titles = ab(f"{lto_name(prev)}-{lto_name(name)}" + ("-port" if port else ""), "chain3") what = " with a device on the expansion port (--device lockstep-port)" if port else "" return overall, (f"A/B against the change before it{what}, both built with fat LTO and one codegen unit (best of " f"12 a side, {frames} frames, CPU time, one pinned core): {titles}; overall {overall}.") STEPS = [ ("k01", "forkpoint", 600, False, "The event horizon: a CPU cycle that ends before the next event only moves the clock", """The base board runs run_to and deliver_lines after every CPU cycle, asking the VDCs and the timer for their next event each time (two thirds of the profile). The board now keeps the earliest master clock at which run_to has anything to do (the next line, the end of the row, a VDC event, the timer's next tick) and skips both before it. The horizon is forgotten whenever the board is reached from outside a bus access (Board::touch: board_mut, step, run_frame, run_until, reset, hold, advance, vdc) and recomputed after every access that is not a plain work RAM one. It is 'every cycle' while a VRAM DMA runs or waits and with a device on the expansion port, so the state after every cycle is the base board's (tests/fork.rs: catching a copy of the VDC and the timer up to the clock changes nothing). A work RAM access with nothing waiting skips finish_access. Seeded faults: horizon-waits-for-the-underflow, horizon-sleeps-through-a-dma, access-keeps-the-old-horizon, quiet-access-with-a-hold-waiting. Also: wasm-bench/ and scripts/wasm-bench.sh (the board under Node, the PSG's level table against the native build's), scripts/seeded_faults.py --check."""), ("k02", "k01", 600, False, "The VDC's next event by hand, not folded through an iterator", """Vdc::next_event and catch_up took the minimum of three optional times by building an array and folding it through flatten().min(), which the compiler does not flatten: a third of the profile after the event horizon, since the horizon is recomputed after every card access. The same minimum, written out. Seeded fault (with the next commit): next-event-forgets-the-commit."""), ("k03", "k02", 600, False, "Accesses to this crate's own cards finish like work RAM's", """RomCard, Sf2Card, PopulousCard and TennokoeCard use nothing of the BoardPins they are handed (no hold, no interrupt line, no VDC), so an access to one, below the hardware page and with nothing waiting, has nothing for finish_access to do: no stretch, no hold, no line, no new horizon. Any other card (an add-on's, a test's) still finishes in full. Seeded faults: any-card-is-plain, quiet-access-with-a-hold-waiting (the first commit's, now on both pages)."""), ("k04", "k03", 1000, False, "The capture's row without a palette write needs no dot times", """Capture::finish_line replays the palette log dot by dot. With no palette write inside the row, which is nearly every row, the colour table is the same at every dot: one pass over the row with no time arithmetic. Seeded fault: palette-write-waits-for-the-row-end."""), ("k05", "k04", 1000, False, "A tile line's eight pixels from a bitplane table, drawn into the row itself", """The background shifted each pixel's four bits out of the two pattern words one at a time and pushed the pixels into a vector of the whole width, which render_line then copied into the row. A 256-entry table spreads a bitplane byte into eight nibbles, so a tile line's pixels are four lookups ORed together, written straight into the part of the row that shows. background::row is kept (it calls the new row_into). Seeded faults: tile-line-mirrored, background-fine-scroll-dropped."""), ("k06", "k05", 1500, False, "The line path without copies: the VDC's row read where it lies, buffers reused", """With the default pixel path (DirectPath, whose mix returns the first VDC's row) end_row hands the capture the VDC's row itself instead of cloning every VDC's row into a vector for the path. render_line reuses the last line's row buffer, the sprite scan the last line's entry list (sprites::scan_into), the sequencer its event list. Seeded faults: any-path-is-direct, row-buffer-not-cleared, sprite-list-not-emptied, line-events-not-emptied. (Not kept, docs/not-kept.md: a sprite-drawing change measured between the last commit and this one, a colour table by pixel value for the capture measured after the bus callbacks' change, and a second sprite-drawing change measured at the end.)"""), ("k07", "k06", 600, True, "With a port device, only its catch_up before the event horizon", """A device on the expansion port is promised a catch_up at every advance (socket 5), so with one the board woke every cycle and ran the whole of run_to. Before the horizon proper (events_at) nothing is due but that catch_up: the board now runs it alone, then delivers the lines and recomputes the horizon (the device is handed IRQ2, the hold and the VDCs). Without a port device nothing changes (measured x%s on the five titles, the A/A noise). Seeded fault: port-catch-up-keeps-the-old-horizon (tests/fork.rs: a port device that starts a VRAM DMA from catch_up, checked cycle by cycle)."""), ("k08", "k07", 1500, False, "The bus callbacks' quiet case keeps no register across a call", """Bus::read was one function with the taps, the slow path and the card call in it, so every cycle saved and restored six registers. Each callback is now a short quiet case (the cycle ends before the horizon and the access is work RAM's or a plain card's) that tail-calls the rest (read_in_full, write_in_full, idle_in_full, quiet_card_read, tap), which is the base board's callback. The taps (bus_log, bus_detail) are honoured on every path: the gate runs with them on, through the quiet cases. Seeded faults: quiet-idle-cycle-not-tapped, full-read-skips-the-events."""), ("k10", "k08", 1500, False, "A RomCard's image on loan to the board while it runs", """A read from a plain ROM card is data[offset of the bank + offset in it], reached through the card's trait with a BoardPins built for it: half of all CPU cycles. While the board runs it now holds the image itself (the Vec moved out of the card, not copied) and reads it inline. Board::touch gives it back before anything can look: board_mut() and every other way in call it; &Board cannot reach a card's fields; a port device or a replacement pixel path could through its pins, and with either there is no loan. tests/fork.rs: the host finds the image whole after a frame and after a step, a byte it changes is the byte the CPU reads, a port device finds it at every catch_up. Seeded faults: rom-lent-beside-a-port-device, rom-not-given-back, lent-rom-bank-offsets."""), ("k11", "k10", 600, True, "Work RAM and plain-card accesses stay quiet beside a port device", """With a port device every access finished in full, because its catch_up may leave a hold for the next access to apply. The board now looks for that hold (its own, or a VDC's from an access the device made) after each catch_up, and only then sends the next access through finish_access. Seeded fault: hold-from-catch-up-waits."""), ("k12", "k11", 1500, False, "Fat LTO and one codegen unit for the crate's own binaries", """The CPU core and the 65xx frame under it are other crates, and every CPU cycle crosses both borders (Part::step, Frame::access). profile.release: lto = "fat", codegen-units = 1. Thin LTO and one codegen unit alone are each about 10% behind (docs/not-kept.md). A crate that depends on this one sets its own profile; the browser pages already build this way. The seeded faults are built without it (the same source, a third of the build time)."""), ] if "--sprites" in sys.argv: STEPS.append(("x13", "k12", 1500, False, "Sprites: only the columns under an entry cleared and merged, pixels from the bitplane table", """sprites::draw kept a line buffer of the whole width, shifted each pixel's four bits out of the planes, and merged every column of the width into the line whether a sprite was there or not. The buffer is now on the stack, only the columns under an entry are merged (twice where two overlap, which changes nothing more), a pattern row's sixteen pixels come from the background's bitplane table and an all-transparent row is skipped. Seeded faults: sprite-flip-ignored, sprite-merge-skips-the-first-entry. (The first attempt, a few commits back, merged the whole range between the leftmost and the rightmost sprite and was not kept: docs/not-kept.md.)""")) parent = BASE for name, prev, frames, port, subject, body in STEPS: overall, line = measured(prev, name, frames, port) if name == "k07": body = body % ab("k06-k07")[0][1:] # the no-port pair of the first batch tree = (TREES / name).read_text().strip() import textwrap line = textwrap.fill(line, 95) message = f"{subject} ({overall}{' with a port device' if port else ''})\n\n{body}\n\n{line}\n\n{GATE}\n\n{TRAILER}\n" parent = subprocess.run(["git", "commit-tree", tree, "-p", parent, "-F", "-"], cwd=ROOT, input=message, capture_output=True, text=True, check=True).stdout.strip() print(name, parent[:10], subject, overall) print(parent)