Fixed-limb product runtime #
Carry-preserving addition and full products operate over one, two, and four native limbs. The
UInt256 carrier holds the full product of two UInt128 values, so the product needs no
arbitrary-precision conversion.
Product.Proof shows that each returned value and carry reconstruct the natural-number sum or
product.
A fixed-width addition result together with its unsigned carry.
- value : α
Low fixed-width part of the sum.
- carry : UInt64
Carry above the payload's highest bit, represented as a native word.
Instances For
Instances For
Instances For
Add two native words and retain the unsigned carry.
Instances For
Add two words and an incoming carry.
Instances For
Add two two-word values.
Instances For
Instances For
Embed a two-limb unsigned value in the low half of a four-limb carrier.
Instances For
Embed a two-limb value after shifting it left by shift bits, for 64 < shift < 128.
The two-word kernels for formats of at most 128 bits align a fracWidth + 1-bit significand by
fracWidth or fracWidth + 1 places, so division, fused multiply-add, and square root share this
one word shuffle. toNat_ofUInt128ShiftedLeft gives its value under the stated shift bounds.
Outside them the native shift counts wrap and the result is unspecified.
Instances For
Return the low two limbs of a four-limb unsigned value.
Instances For
Mathematical value of a four-limb unsigned integer.
Instances For
Position of the most significant set bit, with zero mapped to zero.
Instances For
Add two four-word values.
Instances For
Full 256-bit product of two two-limb values in native arithmetic.
Four mul64 products form the schoolbook product. Each output column is reduced with add64, and
the resulting carry count is passed to the next column.
Instances For
Scalar-carry implementations #
AddResult UInt64 boxes its value field, and the generated code materializes the record behind
the carry branch, so every add64 inside a larger kernel allocates. The definitions below repeat
the same column arithmetic with every intermediate sum and carry as a native word. Each is
definitionally equal to the definition it replaces, and @[csimp] installs it in compiled code.
Compiled code runs addCarry64 as Internal.addCarry64.
Compiled code runs add128 as Internal.add128.
Compiled code runs add256 as Internal.add256.
Compiled code runs mul128 as Internal.mul128.