defs.bend checks
raw source on the hub · import lawful-words@0.1.0.1/defs.bend as Defs
1 import
import Base
Definitions
def two32 source · line 8 · raw
Nat
2^32, for prose and tests. The laws write Nat.pow(2n, 32n) inline instead: the checker evaluates a named constant when comparing terms, and 2^32 in unary is too deep to evaluate. (A Nat literal of 2^32 or more is not allowed.)
def wrap source · line 13 · raw
@n:Nat -> Nat
n modulo 2^32: the number U32.from_nat(n) stands for (the laws write Nat.mod(n, Nat.pow(2n, 32n)) inline, for the same reason).
def bit source · line 17 · raw
@a:U32 -> @k:Nat -> Bool
Bit k of a word (bit 0 is the lowest; every bit from 32 up is 0).
def byte source · line 21 · raw
@w:U32 -> @j:Nat -> U32
Byte j of a word (byte 0 is the lowest): (w >> 8j) & 255.
def put_byte source · line 27 · raw
@w:U32 -> @+j:Nat -> @b:U32 -> U32
w with byte j replaced by b: (w & ~(255 << 8j)) | (b << 8j). Meant for b < 256 and j < 4: a larger b spills into the next byte, and from j = 4 up the word is unchanged.
def pack4 source · line 32 · raw
@b0:U32 -> @b1:U32 -> @b2:U32 -> @b3:U32 -> U32
The word whose bytes 0 to 3 are b0 to b3: b0 | b1 << 8 | b2 << 16 | b3 << 24. Meant for bytes below 256: larger values spill into the next byte.
def nth4 source · line 36 · raw
@j:Nat -> @b0:U32 -> @b1:U32 -> @b2:U32 -> @b3:U32 -> U32
The j-th of four values (j = 0 to 3; b3 from 3 up).
def merge source · line 53 · raw
@lo:U32 -> @hi:U32 -> @+r:Nat -> U32
The word that starts r bytes into the pair (lo, hi), r from 0 to 4: (lo >> 8r) | (hi << 8(4 - r)). Copying at any alignment reads such words.
def zb source · line 58 · raw
@+v:U32 -> U32
The zero-byte flags: (v - 0x01010101) & ~v & 0x80808080. It is zero exactly when no byte of v is zero (law zb_zero); individual flags are not exact.
def bcast source · line 63 · raw
@+b:U32 -> U32
A byte repeated in all four bytes: searching for b is searching xor(w, bcast(b)) for a zero byte.