From 505ff509eb1a77dd0657152b0a8e9c1016cf9198 Mon Sep 17 00:00:00 2001 From: dsh Date: Fri, 6 Nov 2026 23:24:27 +0800 Subject: [PATCH] Rotation and synthesised slices do not mix; naming fixed Tried the rotating byte level driver with the 4 cell slice. It cannot work, and the search says why: rotation needs A and B preserved, because every round reads their current bit, while a synthesised program consumes its operands. Rewriting the table to keep A and B and letting %synth search it gives no program up to 8 layers so 'read without destroying' does not exist in this block model at four cells. The hand written bit_raw_add can do it (loops), which is exactly why the original library rotates inside the macro and the synthesised one cannot. What is committed instead: asm/raw_add_nc.r8asm bit_raw_add_nc, the destroying 4 cell slice, flat cost 27 against bit_raw_add's 38, with the naming and the comment format of lib.r8asm: ; Macro bit_raw_add_nc ; %1: CellBit A ; %2: CellBit B ; %3: CellBit Ci ; %4: CellBit S The synth body is named bit_raw_add_nc_synth, so the 'raw' in the name marks the macro that takes cells. verify_raw_add_nc.r8asm feeds A, B, Ci to one slice and prints sum and carry: 8/8 combinations correct, 78 characters. The rotation limitation is written into the file header so it is not retried blind, and the library still assembles from cache (1666 characters, 7/7). --- asm/raw_add_nc.r8asm | 34 ++++++++++++++++++++++++++++++++++ verify_bit_add_nc4.r8asm | 15 --------------- verify_raw_add_nc.r8asm | 11 +++++++++++ 3 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 asm/raw_add_nc.r8asm delete mode 100644 verify_bit_add_nc4.r8asm create mode 100644 verify_raw_add_nc.r8asm diff --git a/asm/raw_add_nc.r8asm b/asm/raw_add_nc.r8asm new file mode 100644 index 0000000..144e1a9 --- /dev/null +++ b/asm/raw_add_nc.r8asm @@ -0,0 +1,34 @@ +%include "asm/lib.r8asm" + +; 忽略进位的加法切片:两个操作数,没有独立的进位输入/输出, +; 进位在自己的 cell 里就地更新(进->出),最高位的进位由调用者丢掉。 +; +; 切片占 4 个 cell:A、B、进位、S。A、B 被吃掉(结束为 0),这和 bit_raw_add +; 不一样 —— 那个是保留 A、B 的,代价是多一个 Co 和一个 buf。 +; +; 两条实测结论(别忽略): +; 1. %synth 出来的程序只碰每个 cell 的低 K 位,高位不追踪; +; 2. set_0 展开成 [ - ],只对 0 和 1 收敛(5 会 5->4->5->4,0x80 永远不变)。 +; 所以喂进来的 cell 必须只放一位。正因如此,轮转式的字节级驱动配不了这个切片: +; 轮转要求 A、B 保留(每轮读它们的当前位),而合成的程序只会吃掉操作数 —— +; 把表改成"保留 A、B"之后 %synth 报 "no program up to 8 layers"。 + +; Macro bit_raw_add_nc +; %1: CellBit A +; %2: CellBit B +; %3: CellBit Ci +; %4: CellBit S +; +; 表:S = A^B^Ci,进位 = AB|ACi|BCi;A、B 结束为 0,S 和进位只落在 0/1 上。 +%synth bit_raw_add_nc_synth + params 4 + stat 0 8 8 4 8 4 4 12 0 8 8 4 8 4 4 12 + metric flat + mode tape +%endsynth + +%macro bit_raw_add_nc 4 + .tp %4 + set_0 + bit_raw_add_nc_synth %1 %2 %3 %4 +%endmacro diff --git a/verify_bit_add_nc4.r8asm b/verify_bit_add_nc4.r8asm deleted file mode 100644 index 7842786..0000000 --- a/verify_bit_add_nc4.r8asm +++ /dev/null @@ -1,15 +0,0 @@ -%include "asm/raw_add_nc4.r8asm" - -; 4 cell 切片的单点验证驱动:喂 A、B、进位,打出和。 -; 用法(需要一份 tape): -; r8forge verify_bit_add_nc4.r8asm > t.rot8 -; r8forge_derive t.rot8 -1 0=1 1=1 # A=1 B=1 Ci=0 -> out 0,进位留在 cell 2 -; r8forge_derive t.rot8 -2 0=1 1=0 # 顺便看所有非零 cell -.var A 0 -.var B 1 -.var Ci 2 -.var S 3 - -bit_add_nc4 A B Ci S -output S -output Ci diff --git a/verify_raw_add_nc.r8asm b/verify_raw_add_nc.r8asm new file mode 100644 index 0000000..c4011e7 --- /dev/null +++ b/verify_raw_add_nc.r8asm @@ -0,0 +1,11 @@ +%include "asm/raw_add_nc.r8asm" + +; bit_raw_add_nc 的单点验证:A、B、进位各喂一位,打出和与进位。 +.var A 0 +.var B 1 +.var Ci 2 +.var S 3 + +bit_raw_add_nc A B Ci S +output S +output Ci