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).
This commit is contained in:
1 parent
c6bfaca349
commit
505ff509eb
3 files changed
+45
-15
No files matched your search
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in new issue
Block a user