Delete the duplicate slice file, and say what the carry cell really is

asm/raw_add_nc4.r8asm carried the same 4 cell table as asm/raw_add_nc.r8asm --
same stat line, same metric, only the wrapper was named bit_add_nc4 -- and
nothing included it.  Gone; raw_add_nc.r8asm stays, it is the one
verify_raw_add_nc.r8asm and the docs point at.

While looking at it: is the third parameter a scratch cell, and does the slice
have a carry input at all?  Measured with verify_raw_add_nc.r8asm:

    A=0 B=0 carry-in=0 -> S=0 carry-out=0
    A=0 B=0 carry-in=1 -> S=1 carry-out=0
    A=1 B=1 carry-in=1 -> S=1 carry-out=1

so the cell is read on the way in and written on the way out -- a carry input
and a carry output sharing one cell, not a scratch.  All four parameters carry
meaning, which is why the `raw` in bit_raw_add_nc is history rather than
something SPEC.md asks for (raw = the caller passes the scratch cell).  AGENTS.md
now spells that out instead of repeating "and the scratch cell is passed by the
caller", which was wrong for this one.

The macro count in the docs drops to "every macro" rather than a number, so
adding or removing one does not leave a stale count behind.

Everything still green: test.r8asm 1666, full_add 8/8, verify_raw_add_nc,
byte_op_test 65536x4 + 512, macro_docs_test 29 macros in 9 files, fibonacci.
This commit is contained in:
dsh committed 2026-11-07 00:26:03 +08:00
1 parent 56ea288cd6
commit 87ab064121
3 files changed
+5 -45

No files matched your search

+3 -2
View File
@@ -56,7 +56,7 @@ r8forge asm/test.r8asm # 应 exit 0,1666 字符,7
r8forge_synth_test examples/full_add.r8asm # all eight combinations ok
r8forge verify_raw_add_nc.r8asm # 4 cell 加法切片驱动
r8forge_byte_op_test # 字节级库:65536×4 + 512 全过,0.5 秒
r8forge_macro_docs_test # 30 个宏的注释格式,全是 ok
r8forge_macro_docs_test # asm/ 里每个宏的注释格式
```
`r8forge_byte_op_test` 是**唯一按返回值判断字节级对错的**;前三个只证明"汇编得出来"或
@@ -200,7 +200,8 @@ SPEC 第 136-150 行的标准宏前缀:
| 宏 | 为什么这么叫 |
|---|---|
| `raw_add` / `raw_and` / `raw_or` / `raw_xor` / `raw_inc` | 字节级,且草稿 cell 由调用者传 |
| `bit_raw_add`(6 cell)/ `bit_raw_add_nc`(4 cell) | 位级,且草稿 cell 由调用者传 |
| `bit_raw_add`(6 cell) | 位级,且 `%6: buf` 是真正的草稿:内容无关,结束是垃圾 |
| `bit_raw_add_nc`(4 cell) | **四个 cell 都有意义**,没有草稿 cell:第 3 个是"进→出"的进位(`A=0 B=0 进位入=1` 时 `S=1`,实测过)。名字里的 `raw` 是历史遗留,按 SPEC 严格读不该有 —— 但"调用者得多给一个工作 cell"这个宽松读法又说得通,所以先不改名 |
| `clb_bit_mov` | 位级搬运,并且把源吃掉 |
| `bit_copy` / `copy` | 位级/字节级拷贝,缓冲由调用者传(历史命名,少了 `raw`) |
| `set_0` / `set_1` / `erase` / `rol` / `step` / `back` / `output` | 基础操作,不带前缀 |
+2 -2
View File
@@ -381,7 +381,7 @@ cmake --build build --config Release
build\Release\r8forge.exe asm\test.r8asm > test.rot8
build\Release\r8forge_synth_test.exe # 合成 + 跑虚拟机自检
build\Release\r8forge_byte_op_test.exe # 字节级库穷举:65536×4 + 512 全对
build\Release\r8forge_macro_docs_test.exe # 30 个宏的注释格式
build\Release\r8forge_macro_docs_test.exe # 宏注释格式(asm/ 下每个 %macro)
```
`build/` 已经有生成器了,重编译时**别用 PATH 上的另一个 cmake**(版本不一致会重新配置,
@@ -404,7 +404,7 @@ src/synth.cc 真值表 -> 搜索
tests/asm_test.cc 汇编器自检(纸带不变)
tests/synth_test.cc 合成 + ROT-8 虚拟机自检
tests/byte_op_test.cc 字节级库穷举自检(65536×4 + 512)
tests/macro_docs_test.cc 宏注释格式自检(30 个宏)
tests/macro_docs_test.cc 宏注释格式自检(asm/ 下每个 %macro)
tests/tape_run.cc 第二个 ROT-8 解释器,直接跑 .rot8 交叉验证
asm/ 标准库与既有实现
examples/full_add.r8asm 汇编期合成全加器
-41
View File
@@ -1,41 +0,0 @@
%include "asm/lib.r8asm"
; 4 个 cell 的忽略进位加法切片:两个操作数、进位、和,没有独立的进位输出,
; 进位就在它自己的 cell 里就地更新(进->出),最高位的进位由调用者丢掉。
;
; p1..p4 = A, B, 进位(进->出), S
;
; 目标:S = A^B^Ci,进位 = AB|AC|BC,A、B 结束为 0。
; 每个输入组合后的值只落在「进位」和 S 这两位,所以表里只出现 0/4/8/12。
;
; 与 6 cell 的完整全加器切片(bit_raw_add,flat 代价 38)相比,这个切片 flat 代价
; 只有 27,少一个 cell。代价是它只适用于"和不会溢出"的场合,而且调用者必须保证
; 喂进来的 cell 里只有一位(见下)。
;
; 两条要知道的:
; 1. 合成出来的程序只碰每个 cell 的低 K 位(K = 参与运算的输入位数),高位不追踪 ——
; 这是个位级切片,喂进来的 A、B、进位都必须是 0/1;
; 2. set_0 清的是最低位(`biz`/`rnz` 判的是 `cell & 1`,见 AGENTS),所以 S 里的
; 其余位不会被它动。
; A、B 被吃掉,所以它配不了轮转式的字节级驱动 —— 那种驱动每轮还要读回操作数。
; 字节级的 `raw_add` 用的是保留 A、B 的 `bit_raw_add`(6 cell)。
; Macro bit_add_nc4
; %1: CellBit A
; %2: CellBit B
; %3: CellBit Ci
; %4: CellBit S
;
; 和 asm/raw_add_nc.r8asm 里的 bit_raw_add_nc 是同一张表(4 cell、flat 代价 27),
; 区别只有包装宏的名字。目前仓库里没有引用这个文件。
%synth bit_add_nc4_synth
params 4
stat 0 8 8 4 8 4 4 12 0 8 8 4 8 4 4 12
metric flat
%endsynth
%macro bit_add_nc4 4
.tp %4
set_0
bit_add_nc4_synth %1 %2 %3 %4
%endmacro