From 66ed7bc263f354aad0f9893fc0ebffddf193236f Mon Sep 17 00:00:00 2001 From: dsh Date: Sat, 7 Nov 2026 23:31:23 +0800 Subject: [PATCH] SPEC/AGENTS: why the bit level wrappers must keep their set_0 A question that came up: the %synth stat tables already carry every parameter's initial value, so shouldn't bit_raw_* stop clearing its output cells first? No -- and the reason is in the searcher, not in the table. compress_stat_space() drops the bits whose initial value never changes the target and canonicalises them to 0 in the start state. The bit slice tables are periodic in exactly those bits (the old hand written implementation cleared them before working, and the derived table records that), so the search never had to handle "the output cell already holds a 1": the block is only proven for a cleared cell. The wrapper's set_0 is what puts the call site inside the block's domain. Measured by removing all nine of them (seven wrappers plus clb_bit_or and clb_bit_xor): raw_add / raw_and / raw_or / raw_xor ... still 65536/65536 ok clb_mul 62064/65536 wrong clb_divmod 14742/16384 wrong clb_digits 2048/2048 wrong (one of them HANGs) The rotation driven macros survive because they write the result at bit 0 and rotate it away immediately, so the output LSB is 0 anyway; mul and divmod copy accumulators around and really do feed a 1 back into the slice. Dropping the set_0 would save three characters per cleared bit, which is exactly why someone will try it again. Reverted the experiment and wrote it down: SPEC gains 3.6 (compression semantics and this trap, with the numbers), 6.1 gets the pointer line, and AGENTS gets an entry in the "already confirmed dead ends" list. --- AGENTS.md | 7 +++++++ SPEC.md | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index b42ad7e..d666b11 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -500,6 +500,13 @@ W 轮之后 `(PH:PL)` 就是积;`PL`(原来的 Q)被移空,所以 **MUL "读走最低位 → 丢掉 → `ror`",吃掉操作数完全没问题:`clb_add_nc`(4 cell)就是这么跑的, 65536 组合全过。 * 字节级(2^16 项真值表)交给 `%synth`:搜索空间不可行。 +* **删掉位级包装宏里的 `set_0`**(想法是"`%synth` 的 `stat` 已经把初值算进去了, + 输出位不用先清"):**错的**。`stat` 表对输出位的初值是周期的(旧实现先清再算), + 而 `compress_stat_space()` 把"初值不影响终值"的位从搜索初态里清成 0 —— 搜出来的块 + 只保证**初值为 0** 的调用点。2026-11 实测删掉 9 处 `set_0`:`raw_add`/`raw_and`/ + `raw_or`/`raw_xor` 照样全过(轮转驱动每轮把结果写在 bit0 上就转走,输出位的 LSB + 一直是 0),但 `clb_mul` 62064/65536 错、`clb_divmod` 14742/16384 错、 + `clb_digits` 2048/2048 错(其中一个 HANG)。见 SPEC §3.6。 ## 命名与注释格式(照 `SPEC.md`,别自己发明) diff --git a/SPEC.md b/SPEC.md index 5eccfac..aa37b45 100644 --- a/SPEC.md +++ b/SPEC.md @@ -161,6 +161,28 @@ R8Forge 唯一的语言扩展:在汇编期现场搜出一段最短的块序列 `REG+0→REG+1`),位宽一改就静默算错;现在是 `%for k L-1` 生成,**位数、链长、 常数构建的尾部转数全部跟着 `_CELL_SIZE` 走**。 +### 3.6 "表里那位不影响答案" = "搜索器不保证那位的初值" + +`compress_stat_space()` 会把**初值不影响终值**的位从搜索的初态里清成 0:只要 +`target[j] == target[j ^ (1<