Files
R8Forge/asm/raw_and.r8asm
T
dsh 14af0ca6ff Standard library: flat metric, cache pre-warmed and committed
Every synth block in asm/ now says 'metric flat', so the seven block bodies are
optimised without the .tp walk and therefore do not depend on where the caller
puts its cells.  The resulting bodies are cached in .r8forge_cache/ and the
cache is committed, so a fresh clone assembles the library without waiting for
a single search.

asm/test.r8asm: 1674 -> 1666 characters.

The seven tables were re-derived after the switch and all match the hand written
implementations bit for bit (bit_raw_add still 0 9 10 19 12 21 22 31 repeated,
bit_raw_inc 0 5 6 11, and so on), so this is a pure length win.

One caveat: bit_raw_add's flat search still runs out of state budget (700M, the
table stops fitting in a laptop) and falls back to the layer answer, which is
what got cached for it.  The other six converge in milliseconds; the whole warm
up took 396 seconds, almost all of it that one block.
2026-11-06 18:55:18 +08:00

96 lines
1.7 KiB
Plaintext

%include "asm/lib.r8asm"
; bit 宏由 %synth 在汇编期合成。
; stat 那张表是用 r8forge_derive 从旧实现上跑出来的(跑遍所有输入组合,读回各 cell
; 的终值),所以合成结果与旧实现语义完全一致 —— 包括旧实现里"某个输入没被清掉"
; 这类行为。要改语义,改这张表。
; Macro clb_bit_and
; %1: CellBit arg1
; %2: CellBit arg2
; %3: CellBit ans
;
; 这个没换成 %synth:三个参数里没有草稿位,而"与"需要同时保住两个输入,
; 所以只能靠嵌套 biz(一层只能有一个条件)。搜索器在 3 个平面、9 层内穷尽无解,
; 这是模型的表达力边界,不是搜索没跑够。
%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
%synth bit_raw_and_synth
params 4
stat 0 1 2 7 0 1 2 7 0 1 2 7 0 1 2 7
metric flat
mode tape
%endsynth
%macro bit_raw_and 4
.tp %3
set_0
.tp %4
set_0
bit_raw_and_synth %1 %2 %3 %4
%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