Files
R8Forge/asm/raw_add_nc.r8asm
T
dsh 505ff509eb 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).
2026-11-06 23:24:27 +08:00

35 lines
1.2 KiB
Plaintext

%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