Files
R8Forge/asm/lib.r8asm
T
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

153 lines
1.9 KiB
Plaintext

; Macro step
; %1: step_count
%macro step 1
%rep %1
stp
stp
%endrep
%endmacro
; Macro back
; %1: back_count
%macro back 1
%rep %1
btp
btp
%endrep
%endmacro
; Macro set_0
; %this: CellBit operand
%macro set_0 0
biz
flb
rnz
%endmacro
; Macro set_1
; %this: CellBit operand
%macro set_1 0
set_0
flb
%endmacro
; Macro erase
; %1: Cell operand
%macro erase 1
.anchor before_erase
.tp %1
%rep _CELL_SIZE
set_0
ror
%endrep
.tp before_erase
%endmacro
; Macro rol
; %this: Cell operand
%macro rol 0
%rep _CELL_SIZE - 1
ror
%endrep
%endmacro
; Macro clb_bit_mov
; %this: CellBit data
; %1: CellBit destination
%macro clb_bit_mov 1
.anchor before_clb_bit_mov
.tp %1
set_0
.tp before_clb_bit_mov
biz
.tp %1
flb
.tp before_clb_bit_mov
flb
rnz
.tp before_clb_bit_mov
%endmacro
; Macro bit_copy
; %this: CellBit data
; %1: CellBit destination
; %2: CellBit buffer
%macro bit_copy 2
.anchor before_bit_copy
.tp %1
set_0
.tp %2
set_0
.tp before_bit_copy
biz
.tp %1
flb
.tp %2
flb
.tp before_bit_copy
flb
rnz
.tp %2
clb_bit_mov before_bit_copy
.tp before_bit_copy
%endmacro
; Macro copy
; %this: CellBit data
; %1: CellBit destination
; %2: CellBit buffer
%macro copy 2
.anchor before_copy
%rep _CELL_SIZE
bit_copy %1 %2
ror
.tp %1
ror
.tp %2
ror
.tp before_copy
%endrep
%endmacro
; Macro bit_copy_to_buffer
; %this: UnitBit operand
; %1: CellBit tmp
%macro bit_copy_to_buffer 1
stp
.anchor bit_copy_to_buffer_buf_1
btp
bit_copy bit_copy_to_buffer_buf_1 %1
%endmacro
; Macro copy_to_buffer
; %this: Unit operand
; %1: Cell tmp
%macro copy_to_buffer 1
stp
.anchor copy_to_buffer_buf_1
btp
copy copy_to_buffer_buf_1 %1
%endmacro
; Macro output
; %1: operand
%macro output 1
.anchor before_output
.tp %1
out
.tp before_output
%endmacro