~/bend-docscommunity

wide.bend checks

raw source on the hub · import bend-float64@0.1.2.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

type W128 source · line 10 · raw

Data

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 w source · line 37 · raw

@+x:U32 -> W64

def add_go source · line 40 · raw

@+ah:U32 -> @+bh:U32 -> @+al:U32 -> @+lo:U32 -> W64

def add source · line 44 · raw

@a:W64 -> @b:W64 -> W64

a + b, mod 2^64

def sub source · line 50 · raw

@a:W64 -> @b:W64 -> W64

a - b, mod 2^64

def lt source · line 55 · raw

@a:W64 -> @b:W64 -> Bool

def le source · line 60 · raw

@a:W64 -> @b:W64 -> Bool

def eq source · line 63 · raw

@a:W64 -> @b:W64 -> Bool

def is_zero source · line 68 · raw

@a:W64 -> Bool

def or source · line 73 · raw

@a:W64 -> @b:W64 -> W64

def and source · line 78 · raw

@a:W64 -> @b:W64 -> W64

def not source · line 83 · raw

@a:W64 -> W64

def shl_go source · line 88 · raw

@+h:U32 -> @+l:U32 -> @+k:U32 -> W64

def shl source · line 94 · raw

@a:W64 -> @+k:U32 -> W64

a * 2^k mod 2^64, any k

def shr_go source · line 99 · raw

@+h:U32 -> @+l:U32 -> @+k:U32 -> W64

def shr source · line 105 · raw

@a:W64 -> @+k:U32 -> W64

a / 2^k rounded down, any k

def jam_or source · line 110 · raw

@s:W64 -> @lost:Bool -> W64

def shr_jam source · line 114 · 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 119 · raw

@a:W64 -> U32

leading zero bits, 64 for 0

def low source · line 124 · raw

@a:W64 -> U32

def high source · line 129 · raw

@a:W64 -> U32

def lo16 source · line 136 · raw

@+x:U32 -> U32

def hi16 source · line 139 · raw

@+x:U32 -> U32

def mul32_mid source · line 142 · raw

@+mid:U32 -> @+hh:U32 -> @+lh:U32 -> @+hl:U32 -> @+lo:U32 -> W64

def mul32_go source · line 145 · raw

@+al:U32 -> @+ah:U32 -> @+bl:U32 -> @+bh:U32 -> @+lo:U32 -> W64

def mul32 source · line 149 · raw

@+a:U32 -> @+b:U32 -> W64

the 64-bit product of two words

def mul64_top source · line 152 · raw

@t2:W64 -> @+h11:U32 -> @+r1:U32 -> @+r0:U32 -> W128

def mul64_mid source · line 157 · raw

@t1:W64 -> @+r0:U32 -> @+h01:U32 -> @+h10:U32 -> @+h11:U32 -> @+l11:U32 -> W128

def mul64_go source · line 162 · raw

@p00:W64 -> @p01:W64 -> @p10:W64 -> @p11:W64 -> W128

def mul64 source · line 168 · raw

@a:W64 -> @b:W64 -> W128

the full 128-bit product of two 64-bit numbers

def add128_go source · line 175 · raw

@+lo:W64 -> @+al:W64 -> @+ah:W64 -> @+bh:W64 -> W128

def add128 source · line 178 · raw

@a:W128 -> @b:W128 -> W128

def sub128 source · line 183 · raw

@a:W128 -> @b:W128 -> W128

def lt128 source · line 188 · raw

@a:W128 -> @b:W128 -> Bool

def is_zero128 source · line 193 · raw

@a:W128 -> Bool

def clz128 source · line 198 · raw

@a:W128 -> U32

def low128 source · line 203 · raw

@a:W128 -> W64

def shl128 source · line 209 · raw

@a:W128 -> @+k:U32 -> W128

a * 2^k mod 2^128, for k in 0 .. 63

def shr_jam128_go source · line 214 · raw

@+h:W64 -> @+l:W64 -> @+k:U32 -> W128

def shr_jam128 source · line 221 · raw

@a:W128 -> @+k:U32 -> W128

a / 2^k rounded down, the lowest bit set when any bit shifted out was set, any k