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.
129 lines
1.3 KiB
Plaintext
129 lines
1.3 KiB
Plaintext
%include "asm/lib.r8asm"
|
|
|
|
; Macro clb_bit_and
|
|
; %1: CellBit arg1
|
|
; %2: CellBit arg2
|
|
; %3: CellBit ans
|
|
%macro clb_bit_and 3
|
|
.anchor before_clb_bit_and
|
|
.tp %3
|
|
set_0
|
|
.tp %1
|
|
biz
|
|
.tp %2
|
|
biz
|
|
.tp %3
|
|
set_1
|
|
.tp %2
|
|
set_0
|
|
rnz
|
|
.tp %1
|
|
set_0
|
|
rnz
|
|
|
|
.tp before_clb_bit_and
|
|
%endmacro
|
|
|
|
|
|
|
|
; Macro clb_and
|
|
; %1: Cell arg1
|
|
; %2: Cell arg2
|
|
; %3: Cell ans
|
|
%macro clb_and 3
|
|
.anchor before_clb_and
|
|
|
|
%rep _CELL_SIZE
|
|
clb_bit_and %1 %2 %3
|
|
.tp %1
|
|
ror
|
|
.tp %2
|
|
ror
|
|
.tp %3
|
|
ror
|
|
%endrep
|
|
.tp before_clb_and
|
|
%endmacro
|
|
|
|
|
|
|
|
; Macro bit_and
|
|
; %1: CellBit arg1
|
|
; %2: CellBit arg2
|
|
; %3: CellBit ans
|
|
; %4: CellBit tmp
|
|
%macro bit_raw_and 4
|
|
.anchor before_bit_raw_and
|
|
.tp %3
|
|
biz
|
|
flb
|
|
rnz
|
|
|
|
.tp %4
|
|
biz
|
|
flb
|
|
rnz
|
|
|
|
.tp %1
|
|
biz
|
|
.tp %3
|
|
set_1
|
|
.tp %4
|
|
set_1
|
|
.tp %1
|
|
flb
|
|
rnz
|
|
|
|
.tp %2
|
|
biz
|
|
.tp %1
|
|
set_1
|
|
.tp %3
|
|
set_1
|
|
.tp %2
|
|
flb
|
|
rnz
|
|
|
|
.tp %1
|
|
biz
|
|
.tp %2
|
|
flb
|
|
.tp %3
|
|
flb
|
|
.tp %1
|
|
flb
|
|
rnz
|
|
|
|
.tp %4
|
|
biz
|
|
.tp %1
|
|
flb
|
|
.tp %3
|
|
flb
|
|
.tp %4
|
|
flb
|
|
rnz
|
|
.tp before_bit_raw_and
|
|
%endmacro
|
|
|
|
|
|
|
|
; Macro and
|
|
; %1: Cell arg1
|
|
; %2: Cell arg2
|
|
; %3: Cell ans
|
|
; %4: CellBit tmp
|
|
%macro raw_and 4
|
|
.anchor before_raw_and
|
|
|
|
%rep _CELL_SIZE
|
|
bit_raw_and %1 %2 %3 %4
|
|
.tp %1
|
|
ror
|
|
.tp %2
|
|
ror
|
|
.tp %3
|
|
ror
|
|
%endrep
|
|
.tp before_raw_and
|
|
%endmacro |