Limb arrays: representation and field access #
A LimbArray stores a natural number as a little-endian array of 32-bit limbs: limb i carries
weight 2^(32 i), and reading beyond the stored limbs yields zero, so an array denotes the same
number after zero limbs are appended. The value of an array is toNat; Core.Proof relates the
accessors to this value, and the arithmetic and shift modules provide their own value theorems.
Using UInt32 limbs lets each limb product, plus an accumulator limb and a carry, fit in a
UInt64: (2^32 - 1)^2 + 2 * (2^32 - 1) = 2^64 - 1. Array updates can also reuse storage when
the array is uniquely referenced.
This module defines the representation and the non-arithmetic accessors: reading bits and 32-bit
windows, masking to a bit count, resizing, comparing, and locating the leading set bit. Each loop
is structural recursion over a limb count so its invariant can be stated by induction. The
arithmetic kernels live in Arithmetic.Runtime and the shifts in Shift.Runtime.
A natural number stored as little-endian 32-bit limbs.
Little-endian limbs; limb
ihas weight2^(32 i).
Instances For
Instances For
The limb radix 2^32.
Instances For
Number of stored limbs.
Instances For
Limb i, or zero beyond the stored limbs.
Instances For
Value of the count limbs starting at index start, in units of 2^(32 start).
The recursion places the first limb below the remaining segment, which gives the arithmetic loops a common induction invariant.
Instances For
The natural number denoted by a limb array.
Instances For
The count-limb array holding n modulo 2^(32 count).
Instances For
The count-limb array holding zero.
Instances For
One more than the index of the highest nonzero limb below count, or zero if there is none.
Instances For
Whether the array denotes zero.
Instances For
Position of the leading set bit; zero for the zero array.
Instances For
Bit k of the denoted number.
Instances For
The 32-bit window of the denoted number starting at bit lo.
Instances For
The mask of the low r bits of a limb, for r < 32.
Instances For
The denoted number modulo 2^k, keeping the stored limb count.
Instances For
The denoted number modulo 2^(32 count), stored in exactly count limbs.
Instances For
Whether any of the limbs below index count is nonzero.
Instances For
Whether any bit below position k is set.
Instances For
Set the low bit when sticky holds; an empty array remains empty.
Instances For
Compare the limbs below index count, most significant first.
Instances For
Compare the denoted numbers.