Multiword arithmetic on the checked word RAM #
An elementary schoolbook multiplication update uses half-word digits. For radix
β = 2 ^ (w / 2), four digits a, b, d, c < β satisfy
a * b + d + c < β ^ 2 ≤ 2 ^ w. Thus the product and both partial sums fit the
physical word, and division and remainder recover an exact digit and carry.
Main definitions #
Cslib.WordRAM.Multiword.radix: the half-word radix.Cslib.WordRAM.Multiword.LimbUpdate.program: five standard RAM instructions implementing one schoolbook multiply-add update.Cslib.WordRAM.Multiword.LimbUpdate.initializedProgram: compute the half-word radix and perform the update in ten instructions, with no preloaded radix.
Main results #
Cslib.WordRAM.Multiword.LimbUpdate.exec: checked execution, exact reconstruction, and bounded output digit and carry in five instructions, independently of the word size.
This module supplies the elementary update. WordRAM.Multiword.Mul assembles the full
schoolbook routine for arbitrary fixed operand lengths.
References #
Radix for digits whose multiply-add updates fit a single physical word.
Instances For
First multiplicand digit (preserved).
Instances For
Second multiplicand digit (preserved).
Instances For
Previous destination digit (preserved).
Instances For
Input carry, replaced by the output carry.
Instances For
Radix (preserved).
Instances For
Product and partial-sum workspace.
Instances For
Output digit.
Instances For
One schoolbook update, using only checked single-word arithmetic.
Instances For
Compute the radix from the physical word size, using only the two output registers as workspace. The four input digits are preserved.
Instances For
The result of radix setup.
Instances For
Radix setup costs five instructions for every physical word size at least two.
Fixed code computing the radix and then executing a schoolbook update.
Instances For
The mathematical result of the five instructions, including the workspace.
Instances For
Checked execution of the elementary update. All three intermediate results are justified from the digit bounds; no high-product primitive or enlarged physical word is assumed.
In five instructions the elementary update returns an exact low digit and carry, both
strictly below the radix. Memory and the two operands, addend, and radix are preserved.
For globally bounded input data, ExecWithin.bounded also gives globally bounded output data.
The update with charged radix setup, in ten instructions at any word size at least two. The initial radix and workspace registers may contain arbitrary words.