Arcade.U64
Types
Functions
fn equal(a : U64, b : U64) : Bool needs () do a.hi == b.hi && a.lo == b.lo end
fn shr(a : U64, k : { Int | _ >= 1 && _ <= 31 }) : U64 needs () do let carried = int_and(a.hi, int_shl(1, k) - 1) * int_shl(1, 32 - k) { hi: int_shr(a.hi, k), lo: carried + int_shr(a.lo, k) } end
pfn low16(x : Int) : Int needs () do int_and(x, 65535) end
pfn high16(x : Int) : Int needs () do int_shr(x, 16) end
-- The low 32 bits of x y, for 32-bit x and y. pfn mul_low32(x : Int, y : Int) : Int needs () do let cross = low16(high16(x) low16(y) + low16(x) high16(y)) mask32(low16(x) low16(y) + cross * 65536) end
fn of_int(n : { Int | _ >= 0 }) : U64 needs () do { hi: n / two32(), lo: n % two32() } end
pfn hex_digit(c : Int) : Option(Int) needs () do if c >= 48 && c <= 57 do Some(c - 48) else if c >= 97 && c <= 102 do Some(c - 87) else if c >= 65 && c <= 70 do Some(c - 55) else None end end end end
pfn add_digit(acc : Option(U64), c : Int) : Option(U64) needs () do match (acc, hex_digit(c)) do (Some(v), Some(d)) -> do Some({ hi: mask32(v.hi 16 + v.lo / (two32() / 16)), lo: mask32(v.lo 16 + d) }) end (None, _) -> None (_, None) -> None end end