From 677878779aa305212e0c43c77044552a19d5f969 Mon Sep 17 00:00:00 2001 From: dsh Date: Sat, 7 Nov 2026 20:31:15 +0800 Subject: [PATCH] AGENTS: hand off the divider rewrite at the top of the file A new session should not have to reconstruct the task from git history. The first thing in AGENTS.md is now the job: replace clb_divmod's repeated subtraction with shift-and-restore division, target 2047/10 going from 1.48M steps to about 35k with the tape staying near 4k. It names the first step (build and single step verify the R cross cell shift plus bit injection before anything else), the order that bit clb_mul got wrong twice, the second step (raw_sub + clb_bit_or/clb_bit_and for the commit logic), the acceptance list, the baseline commands that must stay green, and what not to touch. DEC SPEC 14 holds the derivation, and raw_sub (already in the library) is the piece that makes it possible. --- AGENTS.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index 2a762b9..c0a209d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,5 +1,44 @@ # 给接手的 agent 的话 +## 下一轮从这里开始(2026-11-07 交接) + +**任务**:把 `clb_divmod` 从"重复减法"换成**移位-恢复除法**(二进制长除法)。 +目标:`2047 / 10` 从 **148 万步** 降到 **~35k 步**(W 轮 vs N/D 轮),纸带保持 ~4k。 +**完整设计在 `SPEC.md §14`,动手前先把那节读完**(状态布局、每轮骨架、四个坑、验收清单)。 + +**第一步(不要跳)**:只做"R 的跨格左移 + 从 N 注入一位",单点验证确认顺序对: + + # R = (Rhi:Rlo) 左移一格,并把 N 的 LSB 注进 Rlo 的 bit0 + # 期望:Rlo 的 bit W-1 进 Rhi 的 bit0;Rlo 的 bit0 = N 的 LSB + r8forge_derive drv/<新驱动>.r8asm -1 0= 2= 4= + +顺序(`clb_mul` 当年在这里返工两轮):`rol` 把要注入的那位搬到 bit0、用 `bit_copy` +(38 字符,保留源)搬过去、再 `ror` 回来;**先搬 Rlo→Rhi,再清 Rlo 的绕回位**。 + +**第二步**:按 §14.3 拼整轮 —— `raw_sub`(现成的,保留操作数)+ `clb_bit_or`(commit = +`Rhi | Bo`)+ `clb_bit_and`(新高位 = `Rhi & Bo`)+ `biz` 门控提交 + `clb_bit_mov` 写商位。 + +**验收**(§14.5):和现有 `clb_divmod` 跑同一张 76 组抽样表逐对比 Q/R;步数前后对比 +(`2047/10`、`2047/2`、`999/7`、`2047/1` —— 最后一个现在会 HANG);`clb_digits` 换上新 +除法器后 11 位下 11 个值全对且步数从 1.48M 降到几万。**半成品不要提交**。 + +**别动**:`asm/` 里其它宏;`%synth` 的指令模型(改了就 bump `kModelVersion`); +`geometry.hh` 的位宽(真要改照 SPEC §13 的清单,四份虚拟机一起)。 + +**当前基线(都通过,别弄坏)**: + +```sh +r8forge asm/test.r8asm # 28729 字符 +r8forge_byte_op_test # 20 项(含 clb_digits 的 11 个值) +r8forge_macro_docs_test # 47 macros in 21 files +r8forge_synth_test examples/full_add.r8asm # all eight combinations ok +r8forge_derive verify_loop.r8asm -1 0=5 # out 5 0 +``` + +**另一个仓库**:`../ROT-8-viz`(fork `dsh/ROT-8-viz`,`main` = `754f885`)有串行 7E1 +(`-s` / `--parity` / `--stop` / `--7e1`),`clb_digits` 产出的 ASCII 正好能直接喂它的 +`OUT`。那边的工作树也是干净的。 + > **动手之前,先把这份文件从头读完**,再看 `SPEC.md`(本仓库自己的:`%synth` 指令 + > `asm/` 里每个宏的契约、纸带长度、验证口径)、上游语言规格 > (`C:\Users\peng0\git\r8asm_rev-fork\SPEC.md`)和 `asm/lib.r8asm` 里的宏注释。