From 14af0ca6ff4cb1aa35a7e1b393b852115023d544 Mon Sep 17 00:00:00 2001 From: dsh Date: Fri, 6 Nov 2026 18:55:18 +0800 Subject: [PATCH] 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. --- .gitignore | 1 - .r8forge_cache/1906ce570b1bb727.txt | 5 +++++ .r8forge_cache/2c0e4b4ec0113a05.txt | 4 ++++ .r8forge_cache/3d99a544df4fd342.txt | 4 ++++ .r8forge_cache/4a3cdd9890e2c185.txt | 3 +++ .r8forge_cache/635f3aabeb0db198.txt | 2 ++ .r8forge_cache/75883d0d632b1705.txt | 4 ++++ .r8forge_cache/8e8fe7cc111be258.txt | 2 ++ README.md | 4 ++++ asm/raw_add.r8asm | 1 + asm/raw_and.r8asm | 1 + asm/raw_inc.r8asm | 1 + asm/raw_or.r8asm | 2 ++ asm/raw_xor.r8asm | 2 ++ src/synth.cc | 4 +++- 15 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .r8forge_cache/1906ce570b1bb727.txt create mode 100644 .r8forge_cache/2c0e4b4ec0113a05.txt create mode 100644 .r8forge_cache/3d99a544df4fd342.txt create mode 100644 .r8forge_cache/4a3cdd9890e2c185.txt create mode 100644 .r8forge_cache/635f3aabeb0db198.txt create mode 100644 .r8forge_cache/75883d0d632b1705.txt create mode 100644 .r8forge_cache/8e8fe7cc111be258.txt diff --git a/.gitignore b/.gitignore index 46ff993..566a79c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,4 @@ build/ *.err *.log *.synth.r8asm -.r8forge_cache/ diff --git a/.r8forge_cache/1906ce570b1bb727.txt b/.r8forge_cache/1906ce570b1bb727.txt new file mode 100644 index 0000000..456f8a2 --- /dev/null +++ b/.r8forge_cache/1906ce570b1bb727.txt @@ -0,0 +1,5 @@ +0 38 0 +1 41 0 +2 51 0 +3 20 1 +5 31 0 diff --git a/.r8forge_cache/2c0e4b4ec0113a05.txt b/.r8forge_cache/2c0e4b4ec0113a05.txt new file mode 100644 index 0000000..d56dc1e --- /dev/null +++ b/.r8forge_cache/2c0e4b4ec0113a05.txt @@ -0,0 +1,4 @@ +1 12 0 +0 6 1 +1 5 0 +3 6 0 diff --git a/.r8forge_cache/3d99a544df4fd342.txt b/.r8forge_cache/3d99a544df4fd342.txt new file mode 100644 index 0000000..c8a18ff --- /dev/null +++ b/.r8forge_cache/3d99a544df4fd342.txt @@ -0,0 +1,4 @@ +0 24 0 +1 21 0 +2 10 1 +4 13 0 diff --git a/.r8forge_cache/4a3cdd9890e2c185.txt b/.r8forge_cache/4a3cdd9890e2c185.txt new file mode 100644 index 0000000..1c8dbea --- /dev/null +++ b/.r8forge_cache/4a3cdd9890e2c185.txt @@ -0,0 +1,3 @@ +0 10 0 +1 13 0 +3 3 0 diff --git a/.r8forge_cache/635f3aabeb0db198.txt b/.r8forge_cache/635f3aabeb0db198.txt new file mode 100644 index 0000000..aa9f006 --- /dev/null +++ b/.r8forge_cache/635f3aabeb0db198.txt @@ -0,0 +1,2 @@ +0 4 0 +1 4 1 diff --git a/.r8forge_cache/75883d0d632b1705.txt b/.r8forge_cache/75883d0d632b1705.txt new file mode 100644 index 0000000..75eb0ab --- /dev/null +++ b/.r8forge_cache/75883d0d632b1705.txt @@ -0,0 +1,4 @@ +0 8 0 +1 1 0 +0 6 0 +3 5 1 diff --git a/.r8forge_cache/8e8fe7cc111be258.txt b/.r8forge_cache/8e8fe7cc111be258.txt new file mode 100644 index 0000000..eef48f4 --- /dev/null +++ b/.r8forge_cache/8e8fe7cc111be258.txt @@ -0,0 +1,2 @@ +0 2 0 +1 4 0 diff --git a/README.md b/README.md index cab31c1..1fe81d6 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,10 @@ all eight combinations ok ## 三种代价口径 +标准库现在统一用 metric flat(步长无关),结果全部预先生成并提交在 .r8forge_cache/ 里, +所以第一次构建不用等搜索。 + + %synth 里用 metric 选优化目标: | metric | 优化什么 | 依赖 cell 布局? | 缓存能否跨调用点复用 | diff --git a/asm/raw_add.r8asm b/asm/raw_add.r8asm index 9f7cbd5..3759e49 100644 --- a/asm/raw_add.r8asm +++ b/asm/raw_add.r8asm @@ -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 diff --git a/asm/raw_and.r8asm b/asm/raw_and.r8asm index 81d8f12..1d183cc 100644 --- a/asm/raw_and.r8asm +++ b/asm/raw_and.r8asm @@ -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 diff --git a/asm/raw_inc.r8asm b/asm/raw_inc.r8asm index 5ede204..92f49ec 100644 --- a/asm/raw_inc.r8asm +++ b/asm/raw_inc.r8asm @@ -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 diff --git a/asm/raw_or.r8asm b/asm/raw_or.r8asm index 9d9a36c..da8a329 100644 --- a/asm/raw_or.r8asm +++ b/asm/raw_or.r8asm @@ -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 diff --git a/asm/raw_xor.r8asm b/asm/raw_xor.r8asm index 27aed98..ccfccf3 100644 --- a/asm/raw_xor.r8asm +++ b/asm/raw_xor.r8asm @@ -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 diff --git a/src/synth.cc b/src/synth.cc index 6f21fa8..90830ea 100644 --- a/src/synth.cc +++ b/src/synth.cc @@ -121,7 +121,9 @@ r8asm_synth_run(const std::vector &in, const std::vector &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)];