master
18
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
9b31a51fec |
hardware: M0 -- the packer, the RTL, and a simulator that agrees byte for byte
The two things software cannot check by reading its own source are the 3 bit
packing and the bracket strategy, so both got a tool and a test.
New in the library (r8forge/tape.hh, src/tape.cc): the opcode numbering (taken
from ROT-8-viz enum, so the packed image and the hardware decoder cannot drift),
text <-> opcodes, opcodes <-> 3 bit bytes, the .r8t image with its trailer and
crc32, and a machine model that runs a packed tape the way a board would. The
model takes the bracket strategy as an option: backward scan with loop stack or
not, and jump-back-onto-the-[ (the contract) or past it (what the interpreters
do). All four combinations print the same thing, and the step count differs by
exactly the number of taken ] instructions -- which is what the test asserts.
Found and fixed while writing it: the loop stack discipline depends on the jump
convention. Jumping onto the [ means the [ re-pushes, so ] must pop on the jump;
jumping past it means the entry must stay until the loop exits. Mixing them up
emptied the stack on the second iteration of the calculator main loop -- caught
by the equivalence test on examples/calc.r8asm, not by reading the code.
Tools: r8forge_tape_pack (text tape -> image + --hex for $readmemh + --verify,
727 instructions become 273 bytes for hello, 62%, and the trailer sits past the
halt so address 0 of a ROM is instruction 0), and r8forge_tape_run now reads an
image directly and takes --loop-stack / --retest.
hardware/rot8.v: the 8 bit / 64 cell machine -- 3 bit opcodes from a byte
addressed memory read as a 16 bit window, a 6 bit dp with free wrap, the loop
stack bracket jump, blocking input, halt on ip == length, and a step counter that
counts instructions rather than cycles. hardware/tb_rot8.v loads a --hex image
and prints the OUT stream in tape_run format.
Verified with Icarus Verilog 14 (the RTL against tape_run --loop-stack --retest):
hello 577 instructions 417 steps 10 outs
term 16414 17643 11 (fed "lhi")
calc 51378 166741 19 (fed "12 34 + .": prints the prompt,
046 and the next prompt)
flagship 43676 100142 93
Every OUT stream identical. ctest -R rtl_sim runs that comparison from an 8 bit
build (11 tests in the default build now, where the RTL test self-skips because
the RTL is the 8 bit machine).
Two traps worth remembering: Icarus passes plusargs through as raw bytes, so an
absolute +HEX path containing non-ASCII (this checkout is under a Chinese
directory name) arrives mangled, $readmemh silently leaves the memory empty and
the machine obediently runs LEN steps of opcode 0 printing nothing -- run vvp
from the directory holding the hex with a relative name. And in_ready must not
be qualified with !in_valid or the input handshake deadlocks.
|
||
|
|
0c75772cbb |
geometry: the ring size becomes a build option, and the machine takes 64 cells
259 was never part of the machine, just the historical default, so kDefaultMemoryCells is now R8FORGE_MEMORY_CELLS (1..65536, default 259) with a range guard in CMake, the same way the cell width already worked. All five VMs read it from geometry.hh, so nothing else had to change. Measured the highest cell each tape in the tree actually touches by walking its > and < and recording the peak (no tape does a < at cell 0, so none of them depend on wrapping): calc 51, hello 49, signed_demo 34, term 27, and the asm/test.r8asm self test 155, because it lays every macro cell block out side by side. So a 64 cell ring runs every program we ship; only the self test needs the default. Verified: the full ctest suite is 8/8 at both 128 and 64 cells (11 bit); at the hardware geometry of 8 bit plus 64 cells the widthfree label is 5/5, and the calculator tape is byte for byte identical to the 259 cell build and its sessions take the same 166348 steps. The self test also produces identical output at 64 cells but 216 more steps, because its high cells fold back onto low ones -- which is why SPEC section 1.2 states the rule: ring size must be at least the highest cell a program touches plus one. Hardware payoff: at 64 cells dp is a 6 bit counter whose wrap is free, so the TTL build loses its modulo-259 comparator logic (four to five chips), the RAM needs 64 bytes, and the drum shrinks to 8 tracks by 64 cells (at 3000 rpm that is 52 s for a calculator session, so it wants to spin faster). hardware.md is updated to the 8 bit / 64 cell machine throughout. |
||
|
|
d0fd127048 |
build: the 32 bit toolchain builds, and 8/16 bit byte tests really pass
Two separate things hid behind "32 bit works": * tests/byte_op_test.cc could not compile at 32 bits at all (`1 << 32` in a constexpr plus an int typed mask), so the whole 32 bit build stopped there -- only `r8forge` and the core library came out. kCellMod is now clamped at 31+ bits and main() prints "skipped" above 16 bits (every sweep there is 2^W rows) and exits green. All ten targets build at 32 bits with MSVC, and the same tree builds clean on a Gentoo box with GCC 16 -- the missing <cstring> in asm_test.cc that stopped GCC first is in the previous commit. * the digit drivers hardcoded a 4 cell window, so byte_op_test's digits / digits_signed / undigits failed at every other width (16 bits wants 5 digits, 8 bits 3). drv/digits.r8asm, drv/digits_signed.r8asm and drv/undigits_byte.r8asm now derive D = _CELL_SIZE * 30103 / 100000 + 1 and space their cells by it, and the C++ side uses the same kDigits instead of a literal 4 (including the T/F cells clb_digits_signed leaves behind). With that, byte_op_test passes at 8, 11 and 16 bits (the 16 bit run takes about 450 s) and above 16 it skips. Two more width bugs fell out on the way: the divmod divisor sweep used 1000 and 2047 unconditionally (they wrap at 8 bits), and the undigits garbage guard OR'ed in bits above the cell, which at 8 bits turned '0'+digit into a value over 255. test_divmod_signed also divided by the recovered divisor without re-checking it, and at 8 bits the boundary value 1024 wraps to 0 -- that was a hard crash (divide by zero), not a failure. CMakeLists.txt now refuses -DR8FORGE_CELL_SIZE outside 1..32 at configure time; the range used to be a comment, so an out of range width was discovered as a compiler error in whichever file shifted by it first. geometry.hh and SPEC section 13 record that 32 is the ceiling because every VM stores a cell in uint32_t -- going further means widening all five VMs, the assembler's immediate type and ROT-8-viz's rot8_data. Also recorded there: the %synth cache is keyed by the truth table, not the width, so a 32 bit build hits the committed entries (0.4 s for the flagship tape of 227075 characters). A full cold rebuild takes ~500 s on a 44 thread machine, 479 s of which is the single 6 parameter full adder table. |
||
|
|
a56a12f132 |
r8forge --opt: the peephole pass is part of the assembler now
The pass moved out of tests/tape_opt.cc into src/tape_opt.cc with a header (rot8_optimize(tape, cell_size)), so both entry points share one implementation: r8forge --opt file.r8asm > t.rot8 assemble, then optimise in memory r8forge_tape_opt t.rot8 t2.rot8 optimise a tape assembled earlier --opt is peeled off argv before the rest of the parsing, so it can appear anywhere and the existing flags are untouched; without it the output is byte for byte what it was (flagship 64513). Measured: flagship 64513 -> 58060 (-10.0%), calculator 62585 -> 54863 (-12.3%), and "12 34 + ." still prints the same out stream from the optimised calculator. ctest 8/8 still green. |
||
|
|
ca72e19b0b |
tape_opt: the peephole pass -- 10% off the flagship tape with identical output
r8forge_tape_opt rewrites a tape with three run-local rules: > < a maximal run of pointer moves becomes its net displacement + a run becomes (length % _CELL_SIZE), a whole turn is a no-op - a run becomes (length % 2), two flips cancel The nice part is what it does NOT do: it never looks at brackets. '[' and ']' are not in any of the three character classes, so they always end a run, and within a run only the net matters (the pointer moves are pure additions and nothing in between is observable). Keeping every run's net keeps the pointer identical at every surviving character, brackets included, so the pairing that the machine finds by scanning cannot change; and since bracket characters are never added or removed, a run can never be merged across one. No stack, no offset table, one linear pass. Measured, with tape_run's out stream compared before and after (and the reference machine on the flagship's -n stream, same 93 values): asm/test.r8asm 64513 -> 58060 (-6453, 10.0%) examples/calc.r8asm 62585 -> 54863 (-7722, 12.3%) "12 34 + ." identical examples/term.r8asm 3467 -> 3402 ( -65, 1.9%) "hi" identical Step counts unchanged (the removed instructions did nothing). Not yet wired into `r8forge` itself: the pipeline is `r8forge f.r8asm > t.rot8 && r8forge_tape_opt t.rot8 t2.rot8`, and a --opt flag can wrap that later. |
||
|
|
c0144a2fcf |
ci: wire CTest and give the runner a pipeline
ci / nightly sweep (1) (push) Skipped
ci / nightly sweep (11) (push) Skipped
ci / nightly sweep (12) (push) Skipped
ci / nightly sweep (16) (push) Skipped
ci / nightly sweep (2) (push) Skipped
ci / nightly sweep (24) (push) Skipped
ci / nightly sweep (32) (push) Skipped
ci / nightly sweep (4) (push) Skipped
ci / nightly sweep (7) (push) Skipped
ci / cold cache (push) Skipped
ci / nightly sweep (8) (push) Skipped
ci / baseline (11 bit) (push) Canceled after 33m54s
ci / cell 8 (push) Canceled after 0s
ci / cell 16 (push) Canceled after 0s
ci / cell 32 (push) Canceled after 0s
`ctest --test-dir build -j` now runs the whole baseline (8 entries, 9 s) instead of six commands typed from memory, and .gitea/workflows/ci.yml drives it: baseline 11 bits, full ctest on every push widths -DR8FORGE_CELL_SIZE=8/16/32, the `widthfree` label only nightly the width sweep for cell 1..32 plus a cold cache run The tests carry labels for that reason: `widthfree` means "true at any width" (bit level slices, the synthesizer, the looping demo, the macro comment format), while flagship / byte_ops / examples pin the 11 bit word (2047 style values, 8 bit era pair counts) and are only meaningful at the default geometry. Cold cache job: throw .r8forge_cache away and let the searcher find the blocks again -- it fails if the fresh results no longer match what the repo ships, which is the cheap version of "the cache is only recomputed when the search changes". Labels in the workflow are `ubuntu-latest`; change them if the self hosted act_runner advertises something else. |
||
|
|
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.
|
||
|
|
3f4149c9d0 |
examples: one runnable routine per macro group
SPEC is the contract and drv/ is what the tests sweep, but there was no place
that showed a reader how a group is actually used. examples/ now has one stand
alone program per group, each ending in output calls:
base_macros.r8asm S5 set_0 vs erase, rol/ror, copy vs bit_copy vs
clb_bit_mov, step
bit_adder.r8asm S6 4 bit ripple carry adder built from
clb_bit_add_nc, then bit_raw_add for the
preserving variant
byte_raw_ops.r8asm S7.1 raw_add/raw_inc/raw_and/raw_or/raw_xor/raw_sub,
printing the operands afterwards to show the
whole point of the family: they survive
byte_clobber.r8asm S7.2 clb_add/sub/neg/inc_nc (operands eaten) and the
S7.3 clb_and residue (240 & 204 -> B = 12)
byte_in_place.r8asm S8 not/inc/neg/dec/add_ip and clb_nonzero
sum_loop.r8asm S5.1 clb_ones + loop/endloop: 1+2+...+N, count from
data rather than from the assembler
mul_demo.r8asm S9 82*141 and 2047*2047
divmod_demo.r8asm S7.6 2047/10 and 2047/1 (the case that used to hang),
reusing the scratch block on purpose
digits_demo.r8asm S7.7 1234 and 7 -> four ASCII digits
Every header carries a `; out 1 2 3` line: the expected OUT stream, so the
file itself says what it prints. The new r8forge_examples_test target runs all
of examples/*.r8asm and compares that line with the real output (a file without
the marker counts as a failure), printing the tape length and step count on the
way. That makes examples the second place after byte_op_test that checks
behaviour instead of just "it assembles", and keeps the examples from rotting as
the macros change. The six %synth examples get the marker too: their inputs are
all zero, so they print 0 0.
All 15 examples pass. The values in the headers were checked with
r8forge_tape_run (the second interpreter) as well as the test's own machine.
Docs: SPEC S10.3 has the table and the convention, S11 gets the test row, and
README gets a short section plus the layout list. AGENTS records the examples
in the handoff baseline and the "verified" table.
|
||
|
|
56ea288cd6 |
Tidy the standard library's macro docs, and check them by machine
Audited all 30 %macro in asm/. The format was already followed almost
everywhere -- the doc block sits above the %macro, or above the %synth block
that generates its body -- but four things were wrong:
raw_and.r8asm the two doc blocks still carried the old names (bit_and, and)
raw_xor.r8asm raw_xor's first two parameters were typed Unit, not Cell
lib.r8asm step / back / output had no type at all ("%1: step_count")
and two files still repeated the retracted claim that set_0 only converges on 0
and 1 (raw_add_nc.r8asm, raw_add_nc4.r8asm). Those now say what set_0 really
does -- it clears the low bit -- and stay on the point that matters for a bit
level slice: A, B and the carry must be single bits because the searched
program only tracks the low K bits.
Parameter types are now a closed set: Cell, CellBit, Unit, UnitBit, Count
(Count is for step/back's repeat count). It is written down in AGENTS.md
together with the format, so the next macro has something to copy.
New r8forge_macro_docs_test checks the format instead of trusting review: a doc
block must exist, its "; Macro <name>" line must match the macro, the number
of documented parameters must equal argc, and every type must be one of the
five. Negative tested by deleting a parameter line and by renaming a block --
it reports both and exits 1.
Also fixes a real annoyance found while running the checks: %synth writes its
generated macro to the system temp directory and imports it. That write fails
intermittently on this machine (same directory, cmd can write, r8forge cannot;
cause unknown), which turned every assembly into "cannot open ...synth.r8asm".
The body is now built in memory and written to the temp directory or, if that
open fails, to the working directory, with one stderr line saying so.
Full suite green: test.r8asm 1666 characters, full_add 8/8, verify_raw_add_nc,
byte_op_test 65536x4 + 512, macro_docs_test 30/30, fibonacci prints its ten
numbers.
|
||
|
|
e30725247e |
Delete the one bit per cell layer
It was written from a wrong diagnosis. Because the interpreters in this repo
read biz/rnz as a whole cell zero test, every packed byte program looked hung,
and the conclusion was "byte level arithmetic has to be one bit per cell".
With the interpreters fixed (
|
||
|
|
afd56e7a8c |
Fix the ROT-8 interpreters: biz / rnz test the low bit
Four interpreters here (tests/synth_test.cc, src/derive.cc and the two I added
earlier: tests/tape_run.cc, tests/byte_add_test.cc) implemented '[' and ']' as
a Brainfuck style "is this whole cell zero" test. The reference implementation
does not:
ROT-8-viz src/rot8.c
rot8_biz: if ((*mem & 1) == 0) skip to just past the matching ']'
rot8_rnz: if ((*mem & 1) == 1) jump back to the matching '['
That one difference is why every byte level program in the library looked like
an endless loop. It is invisible in the bit level world -- for a cell holding 0
or 1 the low bit test and the zero test agree -- which is why the synth tables,
asm/test.r8asm and full_add never noticed anything.
Cross checked against the reference before touching anything: the tape our
assembler produces for "A = 128, set_0, B = 3, raw_add" prints 128 3 0 131 0 on
ROT-8-viz/build/rot8_test.exe and hung in our derive.
With the fix, measured:
raw_add 65536/65536 pairs ok 1647 chars
raw_and 65536/65536 639
raw_or 65536/65536 575
raw_xor 65536/65536 463
raw_inc 512/512 1214
asm/fibonacci.r8asm prints 1 1 2 3 5 8 13 21 34 55, exactly what its
comment claims
So the byte level layer was never broken. Two commits ago it was declared dead
-- set_0 "only converges on 0 and 1", the bits of a packed byte "unreadable",
raw_add "only survives 0+0" -- entirely on the strength of the broken
interpreters. AGENTS.md and README.md now say the opposite and keep the wrong
diagnosis as a worked example: when byte level code looks hung, check the
interpreter first.
New:
tests/byte_op_test.cc + drv/raw_{add,and,or,xor,inc}_byte.r8asm
exhaustive runtime proof for the byte level library, 0.5 s
tests/tape_run.cc + r8forge_tape_run
a second interpreter that runs a .rot8 file directly -- cross checking
derive is now one command
verify_set_0.r8asm now demonstrates what set_0 really does instead of claiming
it hangs: 255 -> 254, 5 -> 4, 128 -> 128 (it clears the low bit, not the cell).
The one bit per cell layer (byte_add / pack_byte) stays as a documented
alternative: it is correct under the real semantics too, just redundant.
|
||
|
|
43390efe8a |
Byte level add, one bit per cell: 65536 combinations ok
The rotation based byte layer never ran. Measured with r8forge_derive -2:
raw_add A=0,B=0 / 1+1 / 3+5 / 1+0 out empty (step limit hit)
raw_add A=127,B=130 out 0 0 0 0 0, everything destroyed
raw_and 0xF0 and 0xCC, 1 and 1, 0 and 5 out empty
copy A=5 out empty (A=0 returns fine)
Not "only operand preservation is missing": set_0 (= [-]) cannot clear a cell
that holds more than one bit, and biz only answers "is this whole cell zero",
because ror does not change zero-ness. So the bits of a packed byte are
unreadable, and the whole ror + set_0 layer has no future. The docs now say
that instead of blaming operand preservation.
What replaces it is one bit per cell:
asm/byte_add.r8asm 8 bit adder. Bit i owns four adjacent cells at base+4i:
A, B, carry (in -> out), scratch. The synthesised four
cell slice bit_raw_add_nc does the bit, clb_bit_mov moves
the carry into the next quartet. A doubles as the
accumulator, so calling byte_add again continues the sum.
asm/pack_byte.r8asm eight flags -> one byte, the only direction that works.
bit_raw_flip_if consumes a flag into flipping bit 0 of an
accumulator that may already hold bits (no set_0 there).
examples/add8.r8asm a+b, 1308 characters. A shared carry cell layout needs
only 25 cells but was measured at 2517: paying .tp travel
eight times beats saving seven carry cells.
examples/add8_inc.r8asm add 1 three times, proving the block composes.
tests/byte_add_test.cc r8forge_byte_add_test: runs the tapes on the ROT-8
machine over every input pair, 0.3 s.
Also: AGENTS.md gains the measurement table, the third instruction set
constraint (packed bytes are unreadable), the new files, and the note that
build/ has to be rebuilt with the VS bundled cmake -- scoop's 4.4 reconfigures
it and dies with "No preprocessor test for PellesC".
|
||
|
|
505fe8af86 |
Make it build under clang
Found with scoop's llvm 23.1.5 (clang-cl), which is stricter than MSVC about
non-type template arguments:
candidate template ignored: substitution failure: deduced non-type
template argument does not have the same type as the corresponding
template parameter ('unsigned long long' vs 'int')
block_cost deduced its N from std::array<int, N>, and that deduces size_t;
clang refuses to convert size_t to the int parameter, MSVC allows it. N is now
size_t. Every target (r8forge, synth_test, derive, cost_par, cost_search)
builds clean with clang-cl and the clang-built binaries assemble test.r8asm to
the same 1674 characters, pass the eight combination check and derive the same
bit_raw_add table.
Two other portability fixes in the same pass:
* cost_search used _strtoui64, which is MSVC only -- now std::strtoull
* the CMake project now finds Threads and links Threads::Threads, which
clang and MinGW need to pull in the thread runtime
* if spawning a worker throws (no thread runtime available) the search now
carries on with the threads it did get instead of failing
|
||
|
|
0bc5f1e6b8 |
Phase-parallel tape search: 22 minutes down to 2.7
The sequential search is memory bound on its hash table, so the split that
works is inside a Dial bucket, not across the graph:
* the table is read only for the whole bucket, so threads probe it with no
locking -- 99.7% of the work, since only about one edge in four hundred
lands on an unseen state
* misses and dist improvements are buffered per thread and applied by one
serial pass after the bucket
Cost order is untouched, so the answer is identical. Measured at limit 60:
threads wall states
1 12.40s 7,671,626
8 2.68s 7,671,626
16 2.20s 7,671,626
32 2.14s 7,671,626
and at the full limit 82 (the run that used to take 1350s): 162s, 414,631,673
states, cost 75 in 6 blocks -- the same program.
%synth now uses this by default. examples/full_add.r8asm assembles in 166s
instead of ~23 minutes and still produces the 90 character tape, checked on the
machine for all eight combinations.
The earlier attempt -- one worker per possible first block -- stays in
r8veritas.hh behind opt.threads but off by default; it duplicated the middle of
the graph and cost three to four times the work.
|
||
|
|
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.
|
||
|
|
98593b568c |
Add a tape-length search: Dijkstra with the real block cost
Layers are not characters. solve_cost runs Dijkstra over the same state graph
with an edge weight of what the block actually assembles to:
w = 3 (biz + flb + rnz) + 2 * span(cell addresses) + sum(op)
op = 1 for flb, 4 for set_1
Dial buckets, pop in cost order, the first pop of the goal is the shortest
tape. Give it max_cost and it becomes branch and bound: anything past the
bound never enters the queue.
Exhausted regions on the full adder with adjacent cells:
max_cost 20 1,086 states 0.0s
max_cost 40 128,528 states 0.1s
max_cost 50 999,448 states 0.7s
max_cost 60 7,671,626 states 12.8s
max_cost 65 20,153,459 states 47.6s
About 2.6x states per 5 cost, about 32 bytes per state, so max_cost 80 is
~350M states / 11GB and 82 would be ~600M / 19GB. The block weight leaves out
the hop from the previous sacrifice (that would make the cost depend on
history and Dijkstra would stop working); the emitter adds it when it reports
the real length -- the five layer program is 82 in the model, 87 on the tape.
The first version of the bucket ring only looked one max-edge-weight ahead for
work, so it declared 'nothing under the limit' while the queue still had
states further out. That made the small limits look sound when they were not;
advancing to the next nonempty bucket fixed it.
|
||
|
|
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.
|
||
|
|
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. |