The profile said 77% of clb_digits' steps are pointer moves, so the layout of its 13 cell scratch block (S..S+12) is the cost. The block is one rigid 7 cell unit (clb_divmod owns its internal order: Rhi,Sd,Bo,Cm=Bc,Ci,buf,NR) plus six free units, so the legal space is 5040 permutations. All 5040 were assembled and run (minimal driver, value 2047): old: TEN Q R [block] counter T F new: T1 R [block] TEN Q F counter tape 13,717 -> 11,717 chars (-14.6%) steps 145,114 -> 113,264 (-21.9%) pointer moves 111,958 -> 80,108 (-28.4%) non-move steps identical (33,156) Full 2048 value sweep: worst 164,843 -> 123,731 (-24.9%), mean 144,904 -> 112,552 (-22.3%), better on all 2048 values. The old layout ranked 3459/5040. Two things worth remembering. First, ordering the units by the wrapper's first visit order is *worse* than the old layout (150,748 steps): first visit ignores revisit frequency -- the counter is touched once per round, TEN is copied into Bc every round, T1 is hammered by clb_add_ip's carry chain. Second, the n-1 lower bound is not reachable here: 74% of the steps still execute inside clb_divmod's block, whose order is not clb_digits' to choose, so this lever is now exhausted (that is what the exhaustive search proves). Min tape is not min steps either: block-first BQTRT1F1C gives the shortest tape (10,713) but 123,890 steps. Tape counts a .tp once, steps count its execution. Ripple: asm/test.r8asm 64,513 -> 62,513 chars, 236,439 -> 206,491 steps, INS_SIZE headroom ~1k -> ~3k; --opt 58,060 -> 56,350; calc --opt 52,857; calc_op 77,356 -> 69,324 chars / 599,090 -> 476,170 steps. Verified: ctest 8/8, byte_op_test 21 items (digits 2048/2048), examples_test 18, --opt assembles, SPEC 7.7/10.2 + AGENTS + README + docs/calc.md + docs/divmod.md numbers updated. New driver drv/digits_layout.r8asm keeps the measurement honest (one clb_digits call, no output, value fed as 0=2047).
18 lines
707 B
Plaintext
18 lines
707 B
Plaintext
; clb_digits 的**最小驱动**:只调一次、不带 output(SPEC §1.3 的口径)。
|
|
; 专门用来量布局:纸带长度 11717 = SPEC §7.7 给的最小驱动长度(重排草稿格之前 13717)。
|
|
;
|
|
; N=0 放被转换的值(运行期喂,不进纸带),REG=1..4 是四位 ASCII 窗口,
|
|
; S=5 起 13 格是草稿区。看结果用 drv/digits.r8asm(那份带 output)。
|
|
;
|
|
; build/Release/r8forge drv/digits_layout.r8asm | Set-Content -NoNewline t.rot8
|
|
; build/Release/r8forge_tape_run t.rot8 0=2047 --profile
|
|
;
|
|
; 换布局时**只许动 asm/digits.r8asm 里的内部偏移**,这个驱动一个字都不用改。
|
|
%include "asm/digits.r8asm"
|
|
|
|
.var N 0
|
|
.var REG 1
|
|
.var S 5
|
|
|
|
clb_digits N REG S
|