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.
This commit is contained in:
dsh committed 2026-11-06 18:55:18 +08:00
1 parent da16c111cf
commit 14af0ca6ff
15 files changed
+38 -2

No files matched your search

-1
View File
@@ -8,5 +8,4 @@ build/
*.err
*.log
*.synth.r8asm
.r8forge_cache/
+5
View File
@@ -0,0 +1,5 @@
0 38 0
1 41 0
2 51 0
3 20 1
5 31 0
+4
View File
@@ -0,0 +1,4 @@
1 12 0
0 6 1
1 5 0
3 6 0
+4
View File
@@ -0,0 +1,4 @@
0 24 0
1 21 0
2 10 1
4 13 0
+3
View File
@@ -0,0 +1,3 @@
0 10 0
1 13 0
3 3 0
+2
View File
@@ -0,0 +1,2 @@
0 4 0
1 4 1
+4
View File
@@ -0,0 +1,4 @@
0 8 0
1 1 0
0 6 0
3 5 1
+2
View File
@@ -0,0 +1,2 @@
0 2 0
1 4 0
+4
View File
@@ -60,6 +60,10 @@ all eight combinations ok
## 三种代价口径
标准库现在统一用 metric flat(步长无关),结果全部预先生成并提交在 .r8forge_cache/ 里,
所以第一次构建不用等搜索。
%synth 里用 metric 选优化目标:
| metric | 优化什么 | 依赖 cell 布局? | 缓存能否跨调用点复用 |
+1
View File
@@ -14,6 +14,7 @@
%synth bit_raw_add_synth
params 6
stat 0 9 10 19 12 21 22 31 0 9 10 19 12 21 22 31 0 9 10 19 12 21 22 31 0 9 10 19 12 21 22 31 0 9 10 19 12 21 22 31 0 9 10 19 12 21 22 31 0 9 10 19 12 21 22 31 0 9 10 19 12 21 22 31
metric flat
mode tape
%endsynth
+1
View File
@@ -61,6 +61,7 @@ rnz
%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
+1
View File
@@ -11,6 +11,7 @@
%synth bit_raw_inc_synth
params 5
stat 0 5 6 11 0 5 6 11 0 5 6 11 0 5 6 11 0 5 6 11 0 5 6 11 0 5 6 11 0 5 6 11
metric flat
mode tape
%endsynth
+2
View File
@@ -9,6 +9,7 @@
%synth clb_bit_or_synth
params 3
stat 0 4 4 4 0 4 4 4
metric flat
mode tape
%endsynth
@@ -46,6 +47,7 @@
%synth bit_raw_or_synth
params 4
stat 0 5 6 7 0 5 6 7 0 5 6 7 0 5 6 7
metric flat
mode tape
%endsynth
+2
View File
@@ -9,6 +9,7 @@
%synth clb_bit_xor_synth
params 3
stat 0 4 4 0 0 4 4 0
metric flat
mode tape
%endsynth
@@ -46,6 +47,7 @@
%synth bit_raw_xor_synth
params 4
stat 0 5 6 3 0 5 6 3 0 5 6 3 0 5 6 3
metric flat
mode tape
%endsynth
+3 -1
View File
@@ -121,7 +121,9 @@ r8asm_synth_run(const std::vector<int> &in, const std::vector<int> &out,
// 2) shortest tape -- exact, so it stops as soon as the goal is popped
typename V::cost_options copt;
copt.max_states = 450'000'000;
copt.max_states = 700'000'000; // the layout free metric explores more than
// the exact one did (415M); past this the
// table stops fitting in a laptop
if (int(layout.size()) == P)
for (int i = 0; i < P; i++)
copt.addr[i] = layout[size_t(i)];