word64.bend checks
raw source on the hub · import bend-osdev-word64@0.1.0.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 283 · 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.to_nat source · line 79 · raw
@a:W64 -> Nat
def W64.from_nat.pair source · line 84 · raw
@qr:Pair(Nat, Nat) -> W64
def W64.from_nat source · line 89 · raw
@k:Nat -> W64
k mod 2^64
def W64.bit source · line 94 · raw
@b:Bool -> U32
def W64.sel source · line 101 · raw
@b:Bool -> @x:W64 -> @y:W64 -> W64
def W64.add.go source · line 110 · raw
@+al:U32 -> @ah:U32 -> @bh:U32 -> @+l:U32 -> W64
def W64.add source · line 113 · raw
@a:W64 -> @b:W64 -> W64
def W64.sub source · line 118 · raw
@a:W64 -> @b:W64 -> W64
def W64.mulhi.go source · line 125 · 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 129 · raw
@+a:U32 -> @+b:U32 -> U32
def W64.mul source · line 136 · raw
@a:W64 -> @b:W64 -> W64
def W64.and source · line 143 · raw
@a:W64 -> @b:W64 -> W64
def W64.or source · line 148 · raw
@a:W64 -> @b:W64 -> W64
def W64.xor source · line 153 · raw
@a:W64 -> @b:W64 -> W64
def W64.not source · line 158 · raw
@a:W64 -> W64
def W64.shl.pick source · line 164 · 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 179 · raw
@a:W64 -> @+k:Nat -> W64
def W64.shr.pick source · line 182 · raw
@z:Bool -> @lt32:Bool -> @lt64:Bool -> @+k:Nat -> @a:W64 -> W64
def W64.shr source · line 197 · raw
@a:W64 -> @+k:Nat -> W64
def W64.cmp.pick source · line 202 · raw
@c:Cmp -> @al:U32 -> @bl:U32 -> Cmp
def W64.cmp source · line 211 · raw
@a:W64 -> @b:W64 -> Cmp
def W64.is_eq source · line 216 · raw
@a:W64 -> @b:W64 -> Bool
def W64.is_lt source · line 219 · raw
@a:W64 -> @b:W64 -> Bool
def W64.is_le source · line 222 · raw
@a:W64 -> @b:W64 -> Bool
def W64.is_gt source · line 225 · raw
@a:W64 -> @b:W64 -> Bool
def W64.is_ge source · line 228 · raw
@a:W64 -> @b:W64 -> Bool
def W64.is_zero source · line 231 · raw
@a:W64 -> Bool
def W64.div.go source · line 238 · raw
@n:Nat -> @+a:W64 -> @+b:W64 -> @+q:W64 -> @+r:W64 -> Pair(W64, W64)
def W64.divmod.pick source · line 247 · raw
@z:Bool -> @+a:W64 -> @+b:W64 -> Pair(W64, W64)
def W64.divmod source · line 256 · 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 259 · raw
@p:Pair(W64, W64) -> W64
def W64.snd source · line 263 · raw
@p:Pair(W64, W64) -> W64
def W64.div source · line 267 · raw
@+a:W64 -> @+b:W64 -> W64
def W64.mod source · line 270 · raw
@+a:W64 -> @+b:W64 -> W64
def W64.small.step source · line 277 · 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 286 · raw
@qhi:U32 -> @ql:Pair(U32, U32) -> W64Small
def W64.small.fin source · line 290 · raw
@qh:Pair(U32, U32) -> @+d:U32 -> @+l:U32 -> W64Small
def W64.small.divmod source · line 294 · raw
@a:W64 -> @+d:U32 -> W64Small
def W64.digit source · line 299 · raw
@+d:U32 -> Char
def W64.show.push source · line 302 · raw
@z:Bool -> @acc:String -> @+d:U32 -> String
def W64.small.q source · line 309 · raw
@p:W64Small -> W64
def W64.small.r source · line 314 · raw
@p:W64Small -> U32
def W64.show.go source · line 321 · 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 329 · raw
@z:Bool -> @+a:W64 -> String
def W64.show source · line 336 · raw
@+a:W64 -> String
def W64.hex.pick source · line 340 · raw
@lt:Bool -> @d:U32 -> Char
the 16 hex digits, lower case, most significant first
def W64.hex.digit source · line 347 · raw
@+d:U32 -> Char
def W64.hex.go source · line 350 · raw
@n:Nat -> @+a:W64 -> @acc:String -> String
def W64.show_hex source · line 357 · raw
@a:W64 -> String