test.r8asm now multiplies as well as adds
The file was the library smoke test: it set up a few cells, called raw_add and
printed five values. It now also calls clb_mul and prints the two product bytes,
so one tape exercises both of the expensive paths and the self check runs a
result rather than only an assembly.
127 + 130 = 257 -> S = 1, Co = 1
200 * 200 = 40000 -> PL = 0x40 = 64, PH = 0x9C = 156
whole tape 5417 characters (was 1666)
Both interpreters agree on `out 127 130 0 1 1 64 156`: r8forge_derive from the
source and r8forge_tape_run from the assembled tape, 427343 steps.
The multiply half lives at cells 16 and up so it cannot disturb the add half, and
the file's existing cell layout is untouched.
This commit is contained in:
1 parent
185b4bf24a
commit
6e8e33e455
3 files changed
+30
-1
No files matched your search
@@ -55,7 +55,7 @@ clang-cl /nologo /std:c++20 /EHsc /O2 /I include src/r8asm.cc src/synth.cc tests
|
||||
自检:
|
||||
|
||||
```sh
|
||||
r8forge asm/test.r8asm # 应 exit 0,1666 字符,7/7 命中缓存
|
||||
r8forge asm/test.r8asm # 应 exit 0,5417 字符(加法 + 乘法各一段)
|
||||
r8forge_synth_test examples/full_add.r8asm # all eight combinations ok
|
||||
r8forge verify_clb_bit_add_nc.r8asm # 4 cell 加法切片(进位进->出)
|
||||
r8forge verify_clb_bit_inc_nc.r8asm # 3 cell 自增切片,进位同样进->出
|
||||
@@ -293,6 +293,7 @@ B 被吃干净。对比:`raw_add` 1647(6 cell,保留操作数)、`clb_ad
|
||||
| 东西 | 结论 |
|
||||
|---|---|
|
||||
| 库里的 7 个位运算块(and/or/xor/inc/add) | 合成版比手写短:`asm/test.r8asm` 1714 → 1666 字符 |
|
||||
| `asm/test.r8asm` 也演乘法 | 现在 1666 → **5417 字符**(`raw_add` 一段 + `clb_mul` 一段),跑出 `127 130 0 1 1 64 156`(= 127+130 和 200×200),`derive` 与 `tape_run` 两个实现一致 |
|
||||
| `clb_bit_add_nc`(4 cell 忽略进位切片) | flat 代价 **27**,完整全加器切片是 38;8/8 组合正确 |
|
||||
| `clb_bit_inc_nc`(3 cell 自增切片) | 表 `0 4 4 2 0 4 4 2`(3 参数)缓存里就有,4 blocks;纸带 54 字符,4/4 组合正确 |
|
||||
| `clb_add_nc`(4 cell 字节加法) | 688 字符,65536 组合全对;比 6 cell 的 `raw_add` 少 2 个 cell、短 959 字符 |
|
||||
|
||||
@@ -296,6 +296,9 @@ while MUL != 0: (PH:PL) += MC ; MUL -= 1
|
||||
再用 `clb_add_ip` 把它加进高字节;`clb_add_nc` 会吃操作数,所以每轮先 `copy` 一份被乘数。
|
||||
|
||||
`255 × 255 = 65025 = 0xFE01` ✓,`r8forge_byte_op_test` 抽 64 组全对。
|
||||
`asm/test.r8asm` 里也演了一遍:先 `raw_add` 算 `127+130`,再 `clb_mul` 算 `200×200`,
|
||||
纸带 5417 字符,`r8forge_derive` 和 `r8forge_tape_run` 两个实现给出同样的
|
||||
`127 130 0 1 1 64 156`。
|
||||
|
||||
**这个设计本身是一条经验**:一开始以为乘法器缺"跨字节移位"和"条件累加",换成重复加法之后
|
||||
两样都不需要了。先看目标函数(纸带长度),再选算法,别照着硬件乘法的样子拼。
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
%include "asm/raw_or.r8asm"
|
||||
%include "asm/raw_xor.r8asm"
|
||||
%include "asm/raw_inc.r8asm"
|
||||
%include "asm/mul.r8asm"
|
||||
|
||||
|
||||
.var A 0
|
||||
@@ -26,3 +27,27 @@ output B
|
||||
output Ci
|
||||
output S
|
||||
output Co
|
||||
|
||||
|
||||
; 再乘一次:200 * 200 = 40000 = 0x9C40,低字节 0x40 = 64,高字节 0x9C = 156。
|
||||
; 这一块只碰 16 号往后的 cell,不打扰上面加法用的那一组。
|
||||
.var MC 16
|
||||
.var MUL 17
|
||||
.var PL 18
|
||||
.var PH 19
|
||||
.var MCA 20
|
||||
.var MS 21
|
||||
.var MCi 22
|
||||
.var MT 23
|
||||
.var MF 24
|
||||
.var MNR 25
|
||||
|
||||
.tp MC
|
||||
.xor 200
|
||||
.tp MUL
|
||||
.xor 200
|
||||
|
||||
clb_mul MC MUL PL PH MCA MS MCi MT MF MNR
|
||||
|
||||
output PL
|
||||
output PH
|
||||
Reference in new issue
Block a user