word64.bend checks
raw source on the hub · import bend-osdev-word64@0.1.1.0/word64.bend as Word64
bend-osdev-word64: unsigned 64-bit words for bend-osdev, wrapping on overflow.
Every bend-osdev package that needs 64 bits uses W64, and only through these defs. A W64 is its two 32-bit halves, each a native U32, so a W64 costs two machine words (a Word(64n) of bits, used before, cost sixty-four, and records of several of them were more than Bend's C backend can compile: bendlang/bend#1069). When Base gains a native U64 (bendlang/bend#1027), only this file changes. The type is not named U64, so that it cannot clash with Base's when it arrives.
1 import
import Base
Types
type W64 source · line 12 · raw
Data
W64@hi:U32 -> @lo:U32 -> W64
type W64Small source · line 312 · raw
Data
a quotient and a small remainder
W64Small@q:W64 -> @r:U32 -> W64Small
Definitions
def W64.zero source · line 15 · raw
W64
def W64.one source · line 18 · raw
W64
def W64.max source · line 21 · raw
W64
def W64.from_u32 source · line 26 · raw
@a:U32 -> W64
def W64.bits.lo source · line 32 · raw
@m:Nat -> @n:Nat -> @w:Word(Nat.add(m, n)) -> Word(m)
Splitting a Word(m + n) into its low m and high n bits (bits are stored least significant first), and joining them back. Named under W64, not Word, so that they cannot clash with Base if it gains Word.lo, Word.hi or Word.cat.
def W64.bits.hi source · line 41 · raw
@m:Nat -> @n:Nat -> @w:Word(Nat.add(m, n)) -> Word(n)
def W64.bits.cat source · line 50 · raw
@m:Nat -> @n:Nat -> @a:Word(m) -> @b:Word(n) -> Word(Nat.add(m, n))
def W64.lo source · line 60 · raw
@a:W64 -> U32
the low 32 bits
def W64.hi source · line 66 · raw
@a:W64 -> U32
the high 32 bits
def W64.from_parts source · line 72 · raw
@hi:U32 -> @lo:U32 -> W64
the word whose high and low 32 bits are hi and lo
def W64.two32 source · line 76 · raw
Nat
2^32, built from literals Bend reads (a literal is at most 2^32 - 1)
def W64.dbl source · line 80 · raw
@n:Nat -> @x:Nat -> Nat
x * 2^n: x doubled n times
def W64.to_nat source · line 91 · raw
@a:W64 -> Nat
lo + hi * 2^32. The high half's weight is 32 doublings of its value, not a product with the closed number 2^32: the checkers count a Nat in unary, so a proof that unfolds to_nat on unknown halves stays symbolic this way (see README.md, Laws).
def W64.from_nat.pair source · line 96 · raw
@qr:Pair(Nat, Nat) -> W64
def W64.from_nat source · line 101 · raw
@k:Nat -> W64
k mod 2^64
def W64.bit source · line 106 · raw
@b:Bool -> U32
def W64.sel source · line 113 · raw
@b:Bool -> @x:W64 -> @y:W64 -> W64
def W64.add.go source · line 122 · raw
@+al:U32 -> @ah:U32 -> @bh:U32 -> @+l:U32 -> W64
def W64.add source · line 125 · raw
@a:W64 -> @b:W64 -> W64
def W64.sub source · line 130 · raw
@a:W64 -> @b:W64 -> W64
def W64.mulhi.go source · line 137 · raw
@+p00:U32 -> @+p01:U32 -> @+p10:U32 -> @p11:U32 -> U32
the high 32 bits of the 64-bit product of two 32-bit words, from their 16-bit halves (every partial product fits in 32 bits)
def W64.mulhi source · line 141 · raw
@+a:U32 -> @+b:U32 -> U32
def W64.mul source · line 148 · raw
@a:W64 -> @b:W64 -> W64
def W64.and source · line 155 · raw
@a:W64 -> @b:W64 -> W64
def W64.or source · line 160 · raw
@a:W64 -> @b:W64 -> W64
def W64.xor source · line 165 · raw
@a:W64 -> @b:W64 -> W64
def W64.not source · line 170 · raw
@a:W64 -> W64
def W64.shl.pick source · line 176 · raw
@z:Bool -> @lt32:Bool -> @lt64:Bool -> @+k:Nat -> @a:W64 -> W64
shifts by k bits: 0 leaves the word, 64 or more gives 0
def W64.shl source · line 191 · raw
@a:W64 -> @+k:Nat -> W64
def W64.shr.pick source · line 194 · raw
@z:Bool -> @lt32:Bool -> @lt64:Bool -> @+k:Nat -> @a:W64 -> W64
def W64.shr source · line 209 · raw
@a:W64 -> @+k:Nat -> W64
def W64.cmp.pick source · line 214 · raw
@c:Cmp -> @al:U32 -> @bl:U32 -> Cmp
def W64.cmp source · line 223 · raw
@a:W64 -> @b:W64 -> Cmp
def W64.is_eq source · line 228 · raw
@a:W64 -> @b:W64 -> Bool
def W64.is_lt source · line 231 · raw
@a:W64 -> @b:W64 -> Bool
def W64.is_le source · line 234 · raw
@a:W64 -> @b:W64 -> Bool
def W64.is_gt source · line 237 · raw
@a:W64 -> @b:W64 -> Bool
def W64.is_ge source · line 240 · raw
@a:W64 -> @b:W64 -> Bool
def W64.is_zero source · line 243 · raw
@a:W64 -> Bool
def W64.div.step source · line 256 · raw
@x:Bool -> @+b:W64 -> @qr:Pair(W64, W64) -> Pair(W64, W64)
one step: the bit x comes in below r
def W64.div.bits source · line 264 · raw
@m:Nat -> @w:Word(m) -> @+b:W64 -> @qr:Pair(W64, W64) -> Pair(W64, W64)
the m bits of w (least significant first) read onto qr, most significant first
def W64.div.go source · line 271 · raw
@a:W64 -> @+b:W64 -> Pair(W64, W64)
def W64.divmod.pick source · line 276 · raw
@z:Bool -> @+a:W64 -> @+b:W64 -> Pair(W64, W64)
def W64.divmod source · line 285 · raw
@+a:W64 -> @+b:W64 -> Pair(W64, W64)
the quotient and the remainder; by zero, the quotient is 0 and the remainder is a (as bend-kit-int's U64, used before, answered)
def W64.fst source · line 288 · raw
@p:Pair(W64, W64) -> W64
def W64.snd source · line 292 · raw
@p:Pair(W64, W64) -> W64
def W64.div source · line 296 · raw
@+a:W64 -> @+b:W64 -> W64
def W64.mod source · line 299 · raw
@+a:W64 -> @+b:W64 -> W64
def W64.small.step source · line 306 · raw
@+d:U32 -> @qr:Pair(U32, U32) -> @+c:U32 -> Pair(U32, U32)
a divided by a small d (1 to 65536) and the remainder, through the four 16-bit pieces of a, most significant first: every step fits in 32 bits
def W64.small.join source · line 315 · raw
@qhi:U32 -> @ql:Pair(U32, U32) -> W64Small
def W64.small.fin source · line 319 · raw
@qh:Pair(U32, U32) -> @+d:U32 -> @+l:U32 -> W64Small
def W64.small.divmod source · line 323 · raw
@a:W64 -> @+d:U32 -> W64Small
def W64.digit source · line 328 · raw
@+d:U32 -> Char
def W64.show.push source · line 331 · raw
@z:Bool -> @acc:String -> @+d:U32 -> String
def W64.small.q source · line 338 · raw
@p:W64Small -> W64
def W64.small.r source · line 343 · raw
@p:W64Small -> U32
def W64.show.go source · line 350 · raw
@n:Nat -> @+a:W64 -> @acc:String -> String
the decimal digits of a, consuming one of 20 steps per digit (after a reaches 0 the steps add nothing)
def W64.show.pick source · line 358 · raw
@z:Bool -> @+a:W64 -> String
def W64.show source · line 365 · raw
@+a:W64 -> String
def W64.hex.pick source · line 369 · raw
@lt:Bool -> @d:U32 -> Char
the 16 hex digits, lower case, most significant first
def W64.hex.digit source · line 376 · raw
@+d:U32 -> Char
def W64.hex.go source · line 379 · raw
@n:Nat -> @+a:W64 -> @acc:String -> String
def W64.show_hex source · line 386 · raw
@a:W64 -> String