Checked multiword subtraction #
Digits use the half-word radix β = 2 ^ (w / 2). A subtraction cell computes
t = β + a - b - c, then returns t % β and borrow 1 - t / β.
For digits a, b < β and incoming borrow c ≤ 1, all intermediate values fit
the physical word, even at width two. In particular, no modular overflow is used.
Main definitions #
Difference.borrow,Difference.one: reserved borrow and constant-one workspace registers (sharingWorkspace.total,Workspace.base,Workspace.IsDigit, andWorkspace.Frame).Difference.cell,Difference.cellResult: six standard instructions for a digit and outgoing borrow, and their mathematical state update.Difference.digits,Difference.program: unrolled digit cells and the fixed-length, in-place multiword difference routine.
Main results #
Difference.exec_cell: checked execution and the exact borrow equation.Difference.exec: execution and reconstruction of a nonnegative difference.
References #
Incoming and outgoing borrow, reusing workspace register 1 (Workspace.carry).
Instances For
Preserved one, reusing workspace register 3 (Workspace.zero, which holds 0 in addition
and 1 in subtraction).
Instances For
Subtract one digit and the incoming borrow, replacing the minuend digit.
Instances For
Every cell uses six instructions, with a zero-or-one outgoing borrow and exact reconstruction. The equality accounts for the borrow at both ends.
Execute an entire subtraction, retaining a possible final borrow. Source digits and all registers outside the destinations and arithmetic workspaces are preserved.
Width-only constants, followed by a zero incoming borrow and the unrolled cells.
Instances For
Only destinations and the four named workspace registers are written.
Nonnegative multiword subtraction, with charged constant installation and no preloaded radix or borrow. The running time depends only on the number of digits.