`metric chars|flat|blocks` inside %synth meant the same truth table could be
searched twice for two call sites, and every library block had to spell out
`metric flat` to avoid the default. The cost model belongs to the whole
assembly, so it is one now:
r8forge <file.r8asm> flat (layout free), the default
r8forge --synth-chars <file.r8asm> charge the real .tp walk
flat stays the default because a library block is expanded at dozens of call
sites with different layouts: only a layout free result can share one cache
entry, and it is usually within a few percent (full_add: 95 vs 90 characters).
The chars search is far more expensive (full_add: 415M states, ~21 minutes,
~10 GB), which is exactly why it should be asked for on the command line.
`metric blocks` goes with it: block count is a poor proxy for tape length (and
it was only another way to ask for mode layers).
Implementation: the metric lives in the assembler (ast::synth_metric, default
1) and is set through r8asm::set_synth_metric() before import_file; the CLI in
tests/asm_test.cc parses --synth-chars / --synth-flat. The cache key already
carried metric, so the committed entries still hit: assembling the library and
asm/test.r8asm gives byte identical tapes (28729 characters, byte_op_test all
green, all 13 examples green, synth_test still 8/8).
A `metric` line now fails with a message that names the flag instead of being
silently ignored. examples/full_add_flat.r8asm and full_add_flat_spaced.r8asm
are removed: they only existed to demonstrate the per block metric (the flat
default makes them copies of full_add.r8asm).
Also repairs the mojibake in README's metric section: an earlier tool wrote
\x0c / \x08 / \x0d where \f, \b and \r belonged, which ate characters out of
"flat", "blocks", "biz/flb/rnz" and "rnz". The section is rewritten for the
flag, and the %synth numbers in README/SPEC/AGENTS now match what the tree
prints.
New cache entry c16bf083bb0ccbc8.txt is full_add's stat table with mode layers
+ flat, which full_add_stat.r8asm now produces.
95 lines
1.7 KiB
Plaintext
95 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_raw_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
|
|
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 raw_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
|