Write the handoff notes down
AGENTS.md, pointed at from the README, so a new session does not have to
rediscover any of this:
* working habits: put anything over ~30s in the background, keep large stderr
out of the transcript (the transport failures), write Chinese only through
the editor, put conclusions in commits rather than in the chat
* build and self check commands for both MSVC and clang-cl
* r8forge_derive's three modes, including the detail that -1/-2 take assembly
source, not a .rot8 tape
* the instruction semantics and the two consequences: set_0 only converges on
0/1, and synthesised programs only touch the low K bits of each cell
* %synth syntax, metric flat, the cache key and kModelVersion, the 990M state
reference point and the layer bound of 8
* what is verified working, and the list of dead ends not to retry: three cell
slices, rotation with synthesised slices, bit per cell adders, byte level
tables through the search
* the naming and comment conventions of lib.r8asm
This commit is contained in:
1 parent
861aa1c4d5
commit
a3502eb410
2 files changed
+110
No files matched your search
@@ -0,0 +1,104 @@
|
||||
# 给接手的 agent 的话
|
||||
|
||||
这个文件是给下一个会话(或者下一个 agent)看的交接说明。内容都是这个仓库里**实测过**的结论,
|
||||
不是推测;每条后面基本都跟着一次失败的尝试,别再踩。
|
||||
|
||||
## 工作方式(上一轮踩到的)
|
||||
|
||||
* **超过 ~30 秒的命令一律丢后台**(`run_in_background`),前台只做短轮询。
|
||||
一次搜索可以跑 680 秒、缓存预热 885 秒,前台干等会撞上客户端和 API 的传输超时。
|
||||
* **别让大段 stderr 进上下文**。PowerShell 遇到原生命令出错会吐一整套 `NativeCommandError`
|
||||
堆栈;用 `2>$null` 收干净,判断结果靠 `$LASTEXITCODE` 和 stdout。
|
||||
* 写含中文的文件用编辑工具(UTF-8),**不要用 `Set-Content -Encoding ascii`** ——
|
||||
汉字会变成 `?`(`examples/full_add_flat*.r8asm` 就这么坏过一次)。
|
||||
* 会话很长时传输容易失败,重要结论要落到 **commit message 和文件注释**里,别只留在对话里。
|
||||
|
||||
## 构建与自检
|
||||
|
||||
```sh
|
||||
# MSVC Release
|
||||
cmake -S . -B build -G "Visual Studio 18 2026" -A x64
|
||||
cmake --build build --config Release
|
||||
|
||||
# clang-cl(scoop 的 llvm,比 MSVC 严格,能抓出模板推导问题)
|
||||
clang-cl /nologo /std:c++20 /EHsc /O2 /I include src/r8asm.cc src/synth.cc tests/asm_test.cc /Fe:r8forge.exe
|
||||
```
|
||||
|
||||
自检三件套:
|
||||
|
||||
```sh
|
||||
r8forge asm/test.r8asm # 应 exit 0,1666 字符,7/7 命中缓存
|
||||
r8forge_synth_test examples/full_add.r8asm # all eight combinations ok
|
||||
r8forge verify_raw_add_nc.r8asm # 4 cell 加法切片驱动
|
||||
```
|
||||
|
||||
`r8forge_derive` 是验证工具:
|
||||
|
||||
```sh
|
||||
r8forge_derive <file.r8asm> 4 0 2 # 按输入组合跑,打印 stat
|
||||
r8forge_derive <file.r8asm> -1 0=100 1=50 # 指定 cell 初值跑一遍,打印 out
|
||||
r8forge_derive <file.r8asm> -2 0=100 # 同上,另外倒出所有非零 cell
|
||||
```
|
||||
|
||||
注意 `-1/-2` 是拿**汇编源码**跑的(内部会先 `import_file`),不能直接喂 `.rot8` 纸带。
|
||||
|
||||
## 指令集语义(这些搞错会浪费一整轮)
|
||||
|
||||
```
|
||||
'-' flb 翻转最低位 cells[dp] ^= 1
|
||||
'+' ror 右旋整个 cell
|
||||
'[' biz 当前 cell 为零 -> 跳到匹配的 ']' 之后
|
||||
']' rnz 当前 cell 非零 -> 跳回匹配的 '['
|
||||
```
|
||||
|
||||
由此推出两条**关键约束**:
|
||||
|
||||
1. **`set_0`(= `[-]`)只对 0 和 1 收敛。**
|
||||
`5` 会 `5->4->5->4` 死循环,`0x80` 永远不变,而且 tape 走不到下一条指令、不报错。
|
||||
`erase`(`%rep _CELL_SIZE { set_0; ror }`)卡在同一个 `set_0` 上,也清不掉任意 cell。
|
||||
→ **清必须发生在 cell 还只放一位的时候。**
|
||||
2. **合成的程序只碰每个 cell 的低 K 位**(K = 参与运算的输入位数),高位不追踪。
|
||||
所以 `%synth` 出来的块只适用于"每格一位"的世界。
|
||||
|
||||
## %synth 相关
|
||||
|
||||
* 语法:`params N` + `mode tape|layers` + `metric chars|flat|blocks` + `layout ...`(可选)
|
||||
+ 目标表 `stat ...` 或 `map ...`。`stat` 的项数必须是 `2^params`(3 参数要 8 项)。
|
||||
参数是输入位 `%1..%K`、输出位、剩余草稿位(草稿位必须结束为 0,语义见 `compress_stat_space`)。
|
||||
* `metric flat`:不计 `.tp` 行走代价 → 结果与 cell 布局无关、缓存可跨调用点复用。
|
||||
`metric chars` 才是按实际布局最优。库里的块统一用 `flat`。
|
||||
* 缓存:`.r8forge_cache/`(**已入库**,克隆下来直接命中)。键 = 模型版本 + params + mode +
|
||||
metric + **解析后的整张目标表**(+ layout,仅 chars)。改指令模型时要 bump
|
||||
`kModelVersion`(`src/synth.cc`)。
|
||||
* 缓存代价参考:`bit_raw_add` 的 flat 搜索 990,636,137 状态 / 680 秒 / ~22 GB 内存。
|
||||
层数上限现在是 8(原来是 5,5 会把一些可行的表误判成不可能)。
|
||||
|
||||
## 已经验证可行的东西
|
||||
|
||||
| 东西 | 结论 |
|
||||
|---|---|
|
||||
| 库里的 7 个位运算块(and/or/xor/inc/add) | 合成版比手写短:`asm/test.r8asm` 1714 → 1666 字符 |
|
||||
| `bit_raw_add_nc`(4 cell 忽略进位切片) | flat 代价 **27**,完整全加器切片是 38;8/8 组合正确 |
|
||||
| `bit_raw_add`(6 cell 全加器切片) | 保留 A、B,配合轮转使用(原版库的做法) |
|
||||
|
||||
## 已经确认走不通的(别重试)
|
||||
|
||||
* **3 个 cell 做加法切片**:层数上限 5 和 8 都报 `no program up to N layers`。
|
||||
* **轮转 + 合成切片**:轮转要求 A、B 保留,合成的程序只会吃掉操作数;
|
||||
把表改成"保留 A、B"后同样报 `no program up to 8 layers`。
|
||||
只有手写的 `bit_raw_add` 能保留操作数(它有循环)。
|
||||
* **把每个 bit 拆进不同 cell 再拼字节级运算**:能跑通但 cell 数爆炸(8 位加法 25 个 cell),
|
||||
没有实用价值,相关文件已删除。
|
||||
* 字节级(2^16 项真值表)交给 `%synth`:搜索空间不可行,字节级只用轮转手写。
|
||||
|
||||
## 命名与注释格式(`asm/lib.r8asm` 的约定)
|
||||
|
||||
```asm
|
||||
; Macro bit_raw_add_nc
|
||||
; %1: CellBit A
|
||||
; %2: CellBit B
|
||||
```
|
||||
|
||||
* 暴露 cell 作为参数的宏,名字里要有 `raw`;块级别的宏(`Cell` 参数)不带。
|
||||
* `%synth` 块名 = `<宏名>_synth`,包装的 `%macro` 用不带 `_synth` 的名字。
|
||||
* 宏里的注释沿用上面那种 `; Macro` / `; %N: <类型> <名字>`。
|
||||
@@ -305,6 +305,12 @@ cost(layer) = 2 # biz + rnz
|
||||
2. 缓存:现在每次汇编都要重跑搜索(full_add 是 7.7 秒)。按真值表 + 布局落盘缓存。
|
||||
3. `%synth` 只支持 8 位以内的参数(状态要塞进 64 位字里)。
|
||||
|
||||
## 给接手的 agent / 新会话
|
||||
|
||||
先读 [`AGENTS.md`](AGENTS.md)。那里有这个仓库实测过的指令集语义、`%synth` 用法、缓存机制,
|
||||
以及一列**已经确认走不通**的方案(3 cell 加法切片、轮转配合成切片、字节级真值表交给搜索……)。
|
||||
那些都是失败换来的结论,别重试。
|
||||
|
||||
## 构建
|
||||
|
||||
```powershell
|
||||
|
||||
Reference in new issue
Block a user