Asked why an in place complement does not exist, given that in place inversion
does. The inversion half is now hoisted out of the per bit loop, which is both
simpler and shorter:
clb_neg_nc A S Ci = clb_not_ip A ; clb_inc_nc A S Ci 468 -> 448
clb_sub_nc A B S Ci = clb_not_ip B ; clb_add_nc A B S Ci 725 -> 707
and the unsigned complement through the same macro (carry in at 0) drops 467 ->
447. B is eaten by the add anyway, so inverting it in place costs nothing. The
per bit `flb` wrappers (clb_bit_neg_nc, clb_bit_sub_nc) are gone with them, so
macro_docs_test now counts 35 macros.
What does not work is the other half: there is no in place increment, so the sum
still has to land in S. Two independent reasons, both written down:
* A synthesised block has exactly one condition cell, so it cannot tell
(A=1, Ci=0) from (A=1, Ci=1) -- and that distinction is the whole carry rule.
All four in place tables answer "no program up to 8 layers".
* Hand writing cannot do it with two cells either: `[ ... ]` is the only one shot
conditional this ISA has, and it eats the bit it tests, while in place
increment needs both cells' bits alive at the same time.
So one cell buys the ones' complement only; a two's complement negate costs three
(A, S, carry). tests unchanged and green: ten byte level operations, 1666
character test tape, 8/8 full adder, fibonacci.
Also: the docs quoted clb_neg_nc at 468 and clb_sub_nc at 725, now 448 and 707.
29 lines
814 B
Plaintext
29 lines
814 B
Plaintext
%include "asm/not_ip.r8asm"
|
|
%include "asm/raw_inc_nc.r8asm"
|
|
|
|
; 取负 / 取反:S = ~A + Ci。
|
|
;
|
|
; 拆成两步,比"每 bit 取反一次"更短:
|
|
; 1. clb_not_ip 把整个字节原地取反(17 字符左右,不占额外 cell);
|
|
; 2. 再走 clb_inc_nc 那套:每一轮把 A 的当前最低位喂给 clb_bit_inc_nc,和写进 S。
|
|
; "加 1"这一步做不到原地(见 AGENTS:2 cell 的原地自增不成立),所以结果落在 S 上。
|
|
;
|
|
; Ci 是真正的进位输入:
|
|
; Ci = 1 -> S = -A(补码取负)
|
|
; Ci = 0 -> S = ~A(反码)—— 此时第 2 步只是把 A 抄进 S
|
|
|
|
; Macro clb_neg_nc
|
|
; %1: Cell A
|
|
; %2: Cell S
|
|
; %3: CellBit Ci
|
|
;
|
|
; S = ~A + Ci,A 被吃干净。
|
|
%macro clb_neg_nc 3
|
|
.anchor before_clb_neg_nc
|
|
|
|
clb_not_ip %1
|
|
clb_inc_nc %1 %2 %3
|
|
|
|
.tp before_clb_neg_nc
|
|
%endmacro
|