6 Commits
Author SHA1 Message Date
dsh 90feedb37b 32 bit cells: widen the VMs to uint32_t, fix the mask at 32, make width a build option
All five R8Forge machines stored a cell in uint16_t, so anything above 16 bits
was silently truncated even though geometry.hh (and the viz) allow 1..32; and
`(1 << cell_size) - 1` for _CELL_MAX was undefined at 32.

  * cells and out/input buffers are uint32_t in derive, tape_run, byte_op_test,
    examples_test and synth_test (r8veritas*.hh keep their uint16_t search
    state -- that is node ids, unrelated)
  * kDefaultCellMask and the injected _CELL_MAX special-case 32 instead of
    shifting by 32
  * width is now a build option: -DR8FORGE_CELL_SIZE=<1..32> (CMake cache var,
    added as a compile definition), so a whole toolchain of another width is one
    configure away; build*/ is ignored so those trees do not leak into git

Verified: 11 bits unchanged (tape 64513, byte_op ok); a 16 bit build passes
synth_test 8/8 and byte_op_test (65536 exhaustive pairs); a 32 bit build passes
synth_test, verify_clb_bit_add_nc and assembles full_add to the same 95 chars.
Exhaustive 32 bit is 2^64 pairs -- that stays sampled, not verified.

SPEC 13 checklist now says five VMs / uint32_t / the 32 bit mask case.
2026-11-10 18:23:26 +08:00
dsh ebc7b7c72e docs: split the machine-local half of AGENTS.md into an ignored AGENTS.local.md
AGENTS.md was carrying two kinds of things: project facts (semantics traps, the
do-not-retry list, baselines, pointers) and this-machine facts (the Visual Studio
cmake path, PowerShell's GBK read-modify-write trap, the git identity and the
sandbox elevation needed to push, the flaky %synth temp file, "put slow commands
in the background").  Only the first kind belongs in a repo: a contributor on
another machine gets noise from the second, and half of it goes stale the moment
the box changes.

So AGENTS.md keeps the project (124 lines) and points at AGENTS.local.md for the
rest; AGENTS.local.md is gitignored, so a fresh clone simply re-creates it for its
own machine.  The commit identity rule stays in AGENTS.md (it is repo policy) and
now defers the mechanics to the local file.

No content is lost: the moved bullets are byte-identical apart from the framing.
2026-11-09 16:37:54 +08:00
dsh 14af0ca6ff Standard library: flat metric, cache pre-warmed and committed
Every synth block in asm/ now says 'metric flat', so the seven block bodies are
optimised without the .tp walk and therefore do not depend on where the caller
puts its cells.  The resulting bodies are cached in .r8forge_cache/ and the
cache is committed, so a fresh clone assembles the library without waiting for
a single search.

asm/test.r8asm: 1674 -> 1666 characters.

The seven tables were re-derived after the switch and all match the hand written
implementations bit for bit (bit_raw_add still 0 9 10 19 12 21 22 31 repeated,
bit_raw_inc 0 5 6 11, and so on), so this is a pure length win.

One caveat: bit_raw_add's flat search still runs out of state budget (700M, the
table stops fitting in a laptop) and falls back to the layer answer, which is
what got cached for it.  The other six converge in milliseconds; the whole warm
up took 396 seconds, almost all of it that one block.
2026-11-06 18:55:18 +08:00
dsh 30089af06d Rewrite the bit macros as %synth blocks
The eight bit-level macros in asm/ are now synthesised instead of hand written.
Their tables were not typed in by hand: r8forge_derive (new, src/derive.cc)
runs the OLD implementation over every input combination and reads the cells
back, so the replacement is bit-for-bit identical, quirks included.  big two
findings:

  * a synth block assumes the parameters that do not take part in the
    computation start at 0 (that is what compress_stat_space means).  These
    macros are called repeatedly inside a loop, so S/Co/tmp arrive dirty; each
    one now has a thin %macro wrapper that clears them and then calls the
    synthesised body.  With that, bit_raw_add derives to exactly the old table
    (0 9 10 19 12 21 22 31 repeated) and bit_raw_and to 0 1 2 7 repeated.
  * clb_bit_and stays hand written.  Three parameters leave no scratch bit and
    "and" needs both inputs alive at once, so it needs nested biz; the searcher
    exhausts nine layers over three planes without finding anything.  That is
    the model's expressive limit, not a shallow search.

asm/test.r8asm assembles to 1674 characters, down from 1714, with identical
block semantics.

%synth results are cached in .r8forge_cache/ keyed by the table, so the
twenty minute tape search happens once per table rather than once per build.

Note on verification: r8forge_derive validates one block at a time, which is
what the tables above are.  The little VM inside it is not solid enough to
vouch for whole programs (fibonacci prints two numbers instead of ten), so
"the whole library still computes the right answer end to end" is NOT verified
here -- that needs the real ROT-8 virtual machine.
2026-11-06 11:04:29 +08:00
dsh 79bc0a4068 Splice %synth into the tape, and check it on a ROT-8 machine
The synthesised body is written out as a macro file and imported, so the
generated code goes through the ordinary expansion path instead of being
spliced by hand.  set_1 is spelled out as set_0 plus flb, so the generated file
needs nothing from lib.r8asm.

examples/full_add.r8asm now assembles: 7.7 seconds of search at assembly time,
then a 95 character tape.  tests/synth_test.cc runs that tape on a small ROT-8
machine for all eight input combinations and checks S and Co -- all eight pass.

Two things that cost me time and are worth writing down:

  * the opcode map is "><+-[].,", i.e. '-' is flb and '+' is ror.  Guess it the
    other way round and a perfectly good tape looks like an infinite loop.
  * synth names must not collide with mnemonics: 'out' is lexed as rot8_out
    before it can be a block keyword.
2026-11-06 00:08:29 +08:00
dsh 19cbfb36f6 R8Forge: assembler and searcher in one repo, %synth directive
The searcher stops being a separate program: %synth is an assembly-time
directive.  It describes a truth table, the assembler runs the search while
parsing, and the block list comes back as ready-to-paste r8asm.

Merging is what makes the cost model honest.  The price of a layer is
  cost = 2 (biz + rnz) + sum(move distance + op cost)
and the move distance depends on the call site's cell layout, not on anything
the assembler knows in advance: the same five-layer adder is 87 characters
with the cells adjacent and 136 with them two apart.  Only the side that sees
the layout can price it, which is now the assembler itself.

Working: the assembler (asm/test.r8asm still assembles to the same 1714
characters), the searcher (bit planes + backward one-step lookup, full_add in
5 layers, proven shortest in 7.2s), and %synth parsing plus the search itself.
Not working yet: splicing the synthesised body into the tape -- a synth call
fails loudly with 'unknown macro' instead of emitting anything, so nothing can
silently assemble wrong.  The two ways to finish it are in the README.

Also carries over the CMake fix: no set(CMAKE_CXX_FLAGS ...), which used to
drop /EHsc, push -O3 into Debug and fight /RTC1.
2026-11-05 23:59:15 +08:00