W<n> machine-word type + surface add_into prim (ADR-0047) - #8
Merged
Conversation
Replace the 1-bit iter fib in the benchmark-energy figure with a byte-wide (U8) Fibonacci: 10 unrolled reversible steps of (a,b) |-> (b, a+b mod 256), each compiling to the two-word datapath EXCH ; ADD. The addInto8 prim (a Flat(8) forward table) is recognized by the TISC compiler as a single reversible Add, so fib8 lowers to a clean 20-instruction ROM (the same shape tests/fib_cpu.rs runs) rather than a bit-blasted gate tree. Priced end to end: reversible 2.58e-9 J vs CMOS-equivalent 9.10e-8 J (~35x). Refactor price_benchmark to delegate to a source-independent price_iso so the Rust-constructed fib8 shares the exact pipeline. Regenerate benchmark-energy.svg; update README prose + alt-text.
Make reversible word arithmetic writable in surface theseus and compilable to the TISC ROM. Two pieces: - W<n> (W1/W2/W4/W8): a machine-word type lowering to a single-register Flat(n) leaf, distinct from the tree-encoded numeric U<n>. One ISA register => byte-capped. (theseus-check env + theseus-cli value marshaling.) - A builtin prim registry: builtin_prim(key, in, out) resolves a declared prim key to a PrimDef, and a surface `prim ... = "key"` reference now elaborates to Iso::Prim (was unsupported). The one key today, theseus.arith.add_into, is (a, b) |-> (a, a + b mod 2^w), addend- preserving. It ships as a SYMBOLIC ripple-carry PrimSpec, not a table: Flat values are deep-thermometer trees, so a 2^w x 2^w table is heap- pathological (a debug build peaked ~45 GB; the spec is ~2 GB / 19 s). At w=8 the compiler recognizes add_into as a single reversible Add, so a byte-wide Fibonacci `fibStep = swap2 ; add_into` unrolls to a clean EXCH;ADD ROM -- the same shape tests/fib_cpu.rs runs. The README energy figure now compiles fib (u8) from this real surface source (dogfood). Tests: conformance 0027-fib8 (fwd+back, carry wrap) and tests/ add_into_prim.rs (single-Add recognition, EXCH;ADD shape, fib evals, mutual-inverse BVEQ at all widths, non-word-type rejected). Adversarial review (fresh-context, cross-model) verified the ripple spec exhaustively both directions at every width and the register mapping by execution; pre-existing checker gaps it exposes are documented in ADR-0047 §3. nix flake check green (fmt + clippy --all-targets --deny warnings + nextest).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes reversible word arithmetic writable in surface theseus and compilable to the TISC ROM, and uses a real byte-wide (U8) Fibonacci as the README energy benchmark.
What
Step 1 — U8 Fibonacci in the energy figure. Replace the 1-bit
fibinbenchmark-energy.svgwith a byte-wide Fibonacci: 10 reversible steps of(a, b) |-> (b, a + b mod 256), each compiling to the two-word datapathEXCH ; ADD. Priced end to end: reversible 2.58e-9 J vs CMOS-equivalent 9.10e-8 J (~35x).Step 2 — the language feature (ADR-0047).
W<n>machine-word type (W1/W2/W4/W8): lowers to a single-registerFlat(n)leaf, distinct from the tree-encoded numericU<n>. One ISA register => byte-capped.builtin_prim(key, in, out)resolves a declared prim key to aPrimDef, and a surfaceprim ... = "key"reference now elaborates toIso::Prim(wasunsupported()). The one key today,theseus.arith.add_into, is(a, b) |-> (a, a + b mod 2^w), addend-preserving. It ships as a symbolic ripple-carryPrimSpec, not a table (a2^w x 2^wtable of deep-thermometerFlatvalues is heap-pathological — a debug build peaked ~45 GB; the spec is ~2 GB / 19 s).At
w = 8the compiler recognizesadd_intoas a single reversibleAdd, sofibStep = swap2 ; add_intounrolls to a cleanEXCH;ADDROM — the same shapetests/fib_cpu.rsruns. The figure now compilesfib (u8)from this real surface source (dogfood).Verification
nix flake checkgreen (fmt + clippy--all-targets --deny warnings+ nextest).0027-fib8(forward + backward, carry wrap) andcrates/theseus-tisc/tests/add_into_prim.rs(single-Addrecognition,EXCH;ADDshape, fib evals fwd/back, mutual-inverse BVEQ at all widths, non-word-type rejected).= expriso bodies aren't checked against their declared signature) are documented in ADR-0047 §3 as follow-ups.