Asked whether two's complement can be done in place. The negate cannot, but the
inversion half can and is absurdly cheap, so it is a macro now:
clb_not_ip A A = ~A, one cell, 17 characters, 256/256
`%rep 8 { flb; ror }` -- flip the low bit, rotate the next one down, eight times
puts the byte back where it started. The same result through clb_neg_nc with its
carry at 0 costs 467 characters, because that path runs a synthesised slice once
per bit.
The in place two's complement itself: tried four tables and none of them exist.
A <- ~A ^ Ci A <- A ^ Ci A <- A ^ B ^ Ci A <- A ^ ~B ^ Ci
no program up to 8 layers (all four)
Two separate reasons, both worth keeping:
* Synthesis cannot: a block has exactly one condition cell. In place increment
has to tell (A=1, Ci=0) -> (1,0) from (A=1, Ci=1) -> (0,1); A is the same in
both and only Ci differs, and one condition cannot look at two cells.
* Hand writing cannot either (2 cells): `[ ... ]` is a while loop and the only
one shot conditional this ISA has, and it eats the bit it tests. In place
negate wants "flip the low bit every round, then decide the carry from it",
so both cells hold live bits and the test destroys one.
So a negate still has to land in a separate S (clb_neg_nc, 3 cells); one cell
buys the ones' complement only. byte_op_test is ten operations now, AGENTS.md
and README.md carry the distinction and the two reasons.
13 lines
196 B
Plaintext
13 lines
196 B
Plaintext
%include "asm/not_ip.r8asm"
|
|
|
|
; clb_not_ip 的驱动:A 原地变成 ~A。
|
|
;
|
|
; r8forge_derive drv/not_ip_byte.r8asm -2 0=5 # 得 250
|
|
;
|
|
; out 只有 A。
|
|
.var A 0
|
|
|
|
clb_not_ip A
|
|
|
|
output A
|