wide.bend checks
raw source on the hub · import bend-float64@0.1.4.0/wide.bend as Wide
bend-float64's integers wider than a word: unsigned 64-bit (two U32 words, W64) and 128-bit (two W64, W128) arithmetic, enough for float64 significands: add, sub, compare, shifts (with a sticky "jam" of the bits shifted out), leading zeros, and the full 64 x 64 -> 128-bit product. Pure; shifts by a U32 amount, never by 32 or more inside a word.
1 import
import Base
Types
type W64 source · line 7 · raw
Data
W64@hi:U32 -> @lo:U32 -> W64
type W128 source · line 10 · raw
Data
W128@hi:W64 -> @lo:W64 -> W128
Definitions
def shl32 source · line 16 · raw
@+x:U32 -> @+k:U32 -> U32
x * 2^k mod 2^32, for k in 0 .. 31 (k's bits above the fifth are ignored)
def shr32 source · line 20 · raw
@+x:U32 -> @+k:U32 -> U32
x / 2^k rounded down, for k in 0 .. 31 (k's bits above the fifth are ignored)
def clz32 source · line 24 · raw
@+x:U32 -> U32
leading zero bits of a word, 32 for 0
def ctz32 source · line 36 · raw
@+x:U32 -> U32
trailing zero bits of a word, 32 for 0 (the lowest set bit isolated, then its position)
def w source · line 41 · raw
@+x:U32 -> W64
def add_go source · line 44 · raw
@+ah:U32 -> @+bh:U32 -> @+al:U32 -> @+lo:U32 -> W64
def add source · line 48 · raw
@a:W64 -> @b:W64 -> W64
a + b, mod 2^64
def sub source · line 54 · raw
@a:W64 -> @b:W64 -> W64
a - b, mod 2^64
def lt source · line 59 · raw
@a:W64 -> @b:W64 -> Bool
def le source · line 64 · raw
@a:W64 -> @b:W64 -> Bool
def eq source · line 67 · raw
@a:W64 -> @b:W64 -> Bool
def is_zero source · line 72 · raw
@a:W64 -> Bool
def or source · line 77 · raw
@a:W64 -> @b:W64 -> W64
def and source · line 82 · raw
@a:W64 -> @b:W64 -> W64
def not source · line 87 · raw
@a:W64 -> W64
def shl_go source · line 92 · raw
@+h:U32 -> @+l:U32 -> @+k:U32 -> W64
def shl source · line 98 · raw
@a:W64 -> @+k:U32 -> W64
a * 2^k mod 2^64, any k
def shr_go source · line 103 · raw
@+h:U32 -> @+l:U32 -> @+k:U32 -> W64
def shr source · line 109 · raw
@a:W64 -> @+k:U32 -> W64
a / 2^k rounded down, any k
def jam_or source · line 114 · raw
@s:W64 -> @lost:Bool -> W64
def shr_jam source · line 118 · raw
@+a:W64 -> @+k:U32 -> W64
a / 2^k rounded down, with the lowest bit set when any bit shifted out was set (the "sticky" bit), any k
def clz source · line 123 · raw
@a:W64 -> U32
leading zero bits, 64 for 0
def low source · line 128 · raw
@a:W64 -> U32
def high source · line 133 · raw
@a:W64 -> U32
def lo16 source · line 140 · raw
@+x:U32 -> U32
def hi16 source · line 143 · raw
@+x:U32 -> U32
def mul32_mid source · line 146 · raw
@+mid:U32 -> @+hh:U32 -> @+lh:U32 -> @+hl:U32 -> @+lo:U32 -> W64
def mul32_go source · line 149 · raw
@+al:U32 -> @+ah:U32 -> @+bl:U32 -> @+bh:U32 -> @+lo:U32 -> W64
def mul32 source · line 153 · raw
@+a:U32 -> @+b:U32 -> W64
the 64-bit product of two words
def mul64_top source · line 156 · raw
@t2:W64 -> @+h11:U32 -> @+r1:U32 -> @+r0:U32 -> W128
def mul64_mid source · line 161 · raw
@t1:W64 -> @+r0:U32 -> @+h01:U32 -> @+h10:U32 -> @+h11:U32 -> @+l11:U32 -> W128
def mul64_go source · line 166 · raw
@p00:W64 -> @p01:W64 -> @p10:W64 -> @p11:W64 -> W128
def mul64 source · line 172 · raw
@a:W64 -> @b:W64 -> W128
the full 128-bit product of two 64-bit numbers
def add128_go source · line 179 · raw
@+lo:W64 -> @+al:W64 -> @+ah:W64 -> @+bh:W64 -> W128
def add128 source · line 182 · raw
@a:W128 -> @b:W128 -> W128
def sub128 source · line 187 · raw
@a:W128 -> @b:W128 -> W128
def lt128 source · line 192 · raw
@a:W128 -> @b:W128 -> Bool
def is_zero128 source · line 197 · raw
@a:W128 -> Bool
def clz128 source · line 202 · raw
@a:W128 -> U32
def low128 source · line 207 · raw
@a:W128 -> W64
def shl128 source · line 213 · raw
@a:W128 -> @+k:U32 -> W128
a * 2^k mod 2^128, for k in 0 .. 63
def shr_jam128_go source · line 218 · raw
@+h:W64 -> @+l:W64 -> @+k:U32 -> W128
def shr_jam128 source · line 225 · raw
@a:W128 -> @+k:U32 -> W128
a / 2^k rounded down, the lowest bit set when any bit shifted out was set, any k
def hi128 source · line 232 · raw
@a:W128 -> W64
def lo128 source · line 237 · raw
@a:W128 -> W64
def shl128g source · line 243 · raw
@a:W128 -> @+k:U32 -> W128
a * 2^k mod 2^128, any k
def shr128 source · line 250 · raw
@a:W128 -> @+k:U32 -> W128
a / 2^k rounded down, any k
def eq128 source · line 256 · raw
@a:W128 -> @b:W128 -> Bool
def lost128 source · line 262 · raw
@+a:W128 -> @+k:U32 -> Bool
whether a / 2^k drops a set bit
def w128 source · line 265 · raw
@+x:W64 -> W128
def mulhi_go source · line 268 · raw
@hh:W128 -> @hl:W128 -> @lh:W128 -> @ll:W128 -> W128
def mulhi source · line 275 · raw
@a:W128 -> @b:W128 -> W128
floor(a * b / 2^128)
def ctz source · line 281 · raw
@a:W64 -> U32
trailing zero bits, 64 for 0
def ctz128 source · line 287 · raw
@a:W128 -> U32
trailing zero bits, 128 for 0