Files
R8Forge/examples/full_add_cost.r8asm
T
dsh 548c239a85 Tape-length search beats the layer search on the full adder
Five layers cost 95 characters; six layers cost 90.  Both are in examples/ and
both pass the eight-combination check on the ROT-8 machine in
tests/synth_test.cc (which now takes a file argument).

    sacrifice B,  FLIP {S,T}
    sacrifice A,  FLIP {B}
    sacrifice B,  FLIP {A,Ci,S}
    sacrifice Ci, FLIP {B,Co,T}
    sacrifice S,  SET1 {Ci,Co}
    sacrifice T,  FLIP {B,Ci,S,Co}

Cost 75 in the model, 90 on the tape once the inter-block hops and the two
output lines are counted.  The goal was popped at 75 only after everything
below 75 had been expanded, so 75 is the minimum of this cost model.

Trading a layer for a shorter tape is not a contradiction: the layer search
cannot see that a small, cheap block can be worth more than one wide, expensive
one.
2026-11-06 09:12:15 +08:00

86 lines
808 B
Plaintext

%include "asm/lib.r8asm"
; 按纸带长度搜索得到的最优解:6 个块,模型代价 75(5 层那版是 82)。
; 这个文件不走 %synth,直接手写,用来实测真实长度并跑虚拟机。
.var A 0
.var B 1
.var Ci 2
.var S 3
.var Co 4
.var T 5
; sacrifice B, FLIP {S,T}
.tp B
biz
.tp S
flb
.tp T
flb
.tp B
flb
rnz
; sacrifice A, FLIP {B}
.tp A
biz
.tp B
flb
.tp A
flb
rnz
; sacrifice B, FLIP {A,Ci,S}
.tp B
biz
.tp A
flb
.tp Ci
flb
.tp S
flb
.tp B
flb
rnz
; sacrifice Ci, FLIP {B,Co,T}
.tp Ci
biz
.tp B
flb
.tp Co
flb
.tp T
flb
.tp Ci
flb
rnz
; sacrifice S, SET1 {Ci,Co}
.tp S
biz
.tp Ci
set_1
.tp Co
set_1
.tp S
flb
rnz
; sacrifice T, FLIP {B,Ci,S,Co}
.tp T
biz
.tp B
flb
.tp Ci
flb
.tp S
flb
.tp Co
flb
.tp T
flb
rnz
output S
output Co