From f30b61365f2a5455f2b4004cafe3e22f7f76f6e2 Mon Sep 17 00:00:00 2001 From: StarCells Date: Fri, 6 Nov 2026 22:04:46 +0800 Subject: [PATCH] Document what set_0 really is Checked instead of assuming, and it explains the chained hang: '-' flb flips bit 0 cells[dp] ^= 1 '[' biz if the cell is zero, jump past the matching ']' ']' rnz if the cell is not zero, jump back to the matching '[' so set_0 = [ - ] is 'while the cell is not zero, flip its lowest bit', which only terminates for 0 and 1. Measured with the cell dump: X=5 goes 5 -> 4 -> 5 -> 4 until the step limit, X=0x80 never changes, and in both cases the tape never reaches the next instruction. erase = %rep 8 { set_0; ror } hangs on the same set_0, so it cannot clear an arbitrary cell either. That is the whole story of the 8 bit chain: after a slice and a ror the S cell holds 0x80, the next wrapper calls set_0 on it, and there is no way out. The slice itself is fine, as the dump showed (A and B fully cleared, carry a clean 0/1). Consequence: a cell always holds one bit in this world, so clearing has to happen while it still is a bit, not after it has been rotated out. --- asm/raw_add_nc.r8asm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/asm/raw_add_nc.r8asm b/asm/raw_add_nc.r8asm index 8c00f17..c31a69b 100644 --- a/asm/raw_add_nc.r8asm +++ b/asm/raw_add_nc.r8asm @@ -16,11 +16,17 @@ ; 合成块假定不参与运算的参数从 0 开始(compress_stat_space 的语义),而 S 和 tmp ; 在循环里带着上一轮的值,所以外面包一层先清掉它们。 ; +; 已查证:set_0 展开成 [ - ],也就是"只要不为零就翻最低位"(flb 是 cell ^= 1, +; biz 是"为零跳到匹配的 ] 之后",rnz 是"非零跳回匹配的 [ ")。它只对 0 和 1 成立: +; 5 会 5->4->5->4 死循环,0x80 永远不会变 0。erase = %rep 8 { set_0; ror } 卡在 +; 同一个 set_0 上。所以库里的 cell 必须始终只放"一位"(0 或 1),轮转出来的 0x80 +; 不能再喂给 set_0 —— 要清就得趁它还是 0/1 的时候清。 +; ; 已知限制:合成出来的程序只碰每个 cell 的低 K 位(K = 参与运算的输入位数), -; 高位是"不追踪"的。所以调用者必须保证喂进来的 cell 高位是 0 —— 本轮实测: -; 单片对所有输入组合都对(包括全零),但用 ror 把上一片的进位/和挪到下一位之后, -; cell 里会留下第 7 位,下一片里那些"循环直到 cell 归零"的块就再也退不出来了。 -; 也就是说要把多片串起来,还得先把每个 bit 挪到一个干净的 cell 里。 +; 高位不追踪。本轮实测:单片对所有输入组合都对(包括全零),但 ror 之后 S 里留下 +; 第 7 位(0x80),下一片的 set_0 就再也退不出来,8 位版本因此卡住。 +; 正确做法:让每个 bit 先落到一个干净 cell 里再进切片,而不是把结果轮转进 +; "下一片会被清"的那一格。 %macro bit_add_nc 5 .tp %4 set_0