Byte level add, one bit per cell: 65536 combinations ok
The rotation based byte layer never ran. Measured with r8forge_derive -2:
raw_add A=0,B=0 / 1+1 / 3+5 / 1+0 out empty (step limit hit)
raw_add A=127,B=130 out 0 0 0 0 0, everything destroyed
raw_and 0xF0 and 0xCC, 1 and 1, 0 and 5 out empty
copy A=5 out empty (A=0 returns fine)
Not "only operand preservation is missing": set_0 (= [-]) cannot clear a cell
that holds more than one bit, and biz only answers "is this whole cell zero",
because ror does not change zero-ness. So the bits of a packed byte are
unreadable, and the whole ror + set_0 layer has no future. The docs now say
that instead of blaming operand preservation.
What replaces it is one bit per cell:
asm/byte_add.r8asm 8 bit adder. Bit i owns four adjacent cells at base+4i:
A, B, carry (in -> out), scratch. The synthesised four
cell slice bit_raw_add_nc does the bit, clb_bit_mov moves
the carry into the next quartet. A doubles as the
accumulator, so calling byte_add again continues the sum.
asm/pack_byte.r8asm eight flags -> one byte, the only direction that works.
bit_raw_flip_if consumes a flag into flipping bit 0 of an
accumulator that may already hold bits (no set_0 there).
examples/add8.r8asm a+b, 1308 characters. A shared carry cell layout needs
only 25 cells but was measured at 2517: paying .tp travel
eight times beats saving seven carry cells.
examples/add8_inc.r8asm add 1 three times, proving the block composes.
tests/byte_add_test.cc r8forge_byte_add_test: runs the tapes on the ROT-8
machine over every input pair, 0.3 s.
Also: AGENTS.md gains the measurement table, the third instruction set
constraint (packed bytes are unreadable), the new files, and the note that
build/ has to be rebuilt with the VS bundled cmake -- scoop's 4.4 reconfigures
it and dies with "No preprocessor test for PellesC".
This commit is contained in:
1 parent
9041034b6e
commit
43390efe8a
8 files changed
+502
-7
No files matched your search
@@ -0,0 +1,22 @@
|
||||
; 8 位加法器:两个 8 位数相加,一位一 cell,结果压成一个字节省出来。
|
||||
;
|
||||
; 第 i 位占 cell 4i..4i+3:A_i、B_i、进位_i、草稿_i(见 asm/byte_add.r8asm)。
|
||||
; add 之后 A 的八个 cell 就是和,B 的八个 cell 是 0,进位停在 cell 4*7+2 = 30。
|
||||
;
|
||||
; out 的第 1 个字节是 (A+B) & 0xFF,第 2 个是 b7 的进位。
|
||||
;
|
||||
; 压字节的累加器用 cell 15(第 3 位的草稿 cell):add 之后它一定是 0,而且离
|
||||
; 八个 flag 都不远,比放到数组外面省 300 多个字符。
|
||||
%include "asm/byte_add.r8asm"
|
||||
%include "asm/pack_byte.r8asm"
|
||||
|
||||
.var BITS 0
|
||||
.var P 15
|
||||
|
||||
byte_add BITS
|
||||
|
||||
; A 的八位在 0, 4, 8, ... 28 上,步长 4
|
||||
pack_byte BITS 4 P
|
||||
|
||||
output P
|
||||
output 30
|
||||
@@ -0,0 +1,26 @@
|
||||
; 自增三次:证明 byte_add 是可以拼的 —— A 是累加器,B 每次都被吃掉,所以只要把
|
||||
; 新的操作数(这里是常量 1)摆回 B 的最低一位,再叫一次 byte_add 就行。
|
||||
;
|
||||
; 第 i 位占 cell 4i..4i+3,A 在 4i 上,B 的最低一位在 cell 1 上。
|
||||
; out 的第 1 个字节是 (A+3) & 0xFF,第 2 个是 b7 的进位。
|
||||
%include "asm/byte_add.r8asm"
|
||||
%include "asm/pack_byte.r8asm"
|
||||
|
||||
.var BITS 0
|
||||
.var P 15
|
||||
|
||||
; B 的 cell 1 在 add 之后一定是 0,所以 flb 就是"摆一个 1 进去"
|
||||
%macro byte_inc 1
|
||||
.tp %1 + 1
|
||||
flb
|
||||
byte_add %1
|
||||
%endmacro
|
||||
|
||||
byte_inc BITS
|
||||
byte_inc BITS
|
||||
byte_inc BITS
|
||||
|
||||
pack_byte BITS 4 P
|
||||
|
||||
output P
|
||||
output 30
|
||||
Reference in new issue
Block a user