u32.bend checks
raw source on the hub · import bend-osdev-u32@0.1.0.0/u32.bend as MU32
bend-osdev-u32: the arithmetic of Base's words as Nat arithmetic.
This package has no word type of its own: its laws (LAWS.bend) are about Base's Word(n) and U32 operations, stated through their values (Word.to_nat, U32.to_nat): comparison is the order of the values, and addition, subtraction, increment and the shifts are the Nat operations on the values when nothing wraps, and the wrapping ones otherwise. Other packages' proofs use these laws instead of each proving them again.
The defs below are the Nat functions the laws are stated with. None of them names a power of two as a closed number: 2^n is U32Nat.dbl(n, 1n), and 2^32 itself is never written out (see README.md, "Stating the bounds").
1 import
import Base
Definitions
def U32Nat.dbl source · line 17 · raw
@n:Nat -> @x:Nat -> Nat
x times 2^n: x doubled n times
def U32Nat.bit source · line 25 · raw
@b:Bool -> Nat
1 for True, 0 for False
def U32Nat.half source · line 33 · raw
@n:Nat -> Nat
n / 2, rounded down
def U32Nat.odd source · line 45 · raw
@n:Nat -> Nat
x mod 2: 1 for an odd x, 0 for an even one
def U32Nat.low source · line 58 · raw
@k:Nat -> @+x:Nat -> Nat
the low k bits of x (x mod 2^k), and the rest (x / 2^k, rounded down): x = low(k, x) + 2^k high(k, x)
def U32Nat.high source · line 65 · raw
@k:Nat -> @x:Nat -> Nat
def U32Word.mask source · line 74 · raw
@n:Nat -> @k:Nat -> Word(n)
the word of width n whose low k bits are set (2^k - 1, for k <= n): the mask that U32.and(x, m) takes x's low k bits with