Files
R8Forge/src
starcells 7feebca5ee A 5 cell adder that ignores carry in and out
The idea: for an adder whose operand sum is known not to overflow, there is no
need for a separate carry in cell or a carry out cell -- the carry can live in
one cell and be overwritten each bit, and the final carry is simply dropped.
That takes the slice from 6 cells (A, B, Ci, S, Co, tmp) down to 5 (A, B,
carry, S, tmp).

The slice was not hand written: the table was derived from S = A^B^Ci and
carry = AB|AC|BC, and %synth searched it with metric flat:

    bit_add_nc_synth: tape cost 27 in 5 blocks   (1891406 states)
    bit_raw_add_synth (the 6 cell full adder):   tape cost 38 in 5 blocks

so 11 units of the metric cheaper, about 29%, plus one cell less per slice.

Verified: all eight input combinations of a single slice are correct through the
built in machine (A, B, Ci -> S), including the all zero one.

Known limitation, found rather than guessed: the synthesised program only
touches the low K bits of each cell, the bits the truth table knows about.  The
caller therefore has to hand it cells whose high bits are zero.  Chaining slices
with ror breaks that: the rotated cell keeps bit 7, and a block that loops until
its cell reaches zero can never get there.  So the 8 bit raw_add_nc hangs; the
slice itself is fine, the driver needs to move each bit into a clean cell first.

Also added: r8forge_derive <file> -1 addr=value ... runs a tape with chosen cells
and prints OUT, which is how the slice was checked.
2026-11-06 21:19:19 +08:00
..