Files
R8Forge/drv
dsh 9a9ca48d9a raw_sub: a subtraction that keeps its operands
clb_sub_nc eats A and B, so the repeated subtraction divider has to copy both
every round (two 495 character copies, about five hundred steps each) -- that
is where clb_divmod's 1.48 million steps for 2047 comes from.  Binary long
division compares against the same divisor every round and cannot afford that,
so it needs a non destructive subtract first.

raw_sub A B S Bo Bc Ci buf is three useful lines: copy ~B, set Ci = 1, then
raw_add (which already preserves its operands).  S = A + ~B + 1 = A - B, and A
and B are untouched.  About 2900 characters, 7 cells, 9 sampled cases correct.

One trap measured: do not flip Bo at the end to turn a carry into a borrow --
clb_not_ip complements the whole cell, so 0 becomes 2047 and 1 becomes 2046.
Bo keeps the library's existing meaning instead: 1 means A >= B (no borrow),
same as clb_sub_nc's carry.

This is step one of replacing clb_divmod's O(N/D) loop with shift-and-restore
division at O(cell_size) rounds (11 instead of 205 for 2047, so roughly forty
times fewer steps for maybe a few hundred extra characters of tape).
2026-11-07 20:24:55 +08:00
..