Definitions and basics #
Equations
- UInt128.max = { lo := UInt64.max, hi := UInt64.max }
Instances For
Equations
- instCoeUInt128Real = { coe := UInt128.toReal }
@[irreducible]
Equations
- UInt128.ofNat x = { lo := UInt64.ofNat x, hi := UInt64.ofNat (x / 2 ^ 64) }
Instances For
@[irreducible]
Equations
- UInt128.ofInt x = { lo := UInt64.ofInt x, hi := UInt64.ofInt (x / 2 ^ 64) }
Instances For
128-bit increment #
Complement #
Twos complement negation #
128-bit addition and (twos complement) subtraction #
UInt128 inherits the additive group structure from ℤ
Equations
- One or more equations did not get rendered due to their size.
64 → 128 bit multiplication #
We define the product of two UInt64s, as a 128-bit int. Let s = 2^32. Then we have
x = x1 s + x0
y = y1 s + y0
x y = x1 y1 s^2 + (x1 y0 + x0 y1) s + x0 y0
Using addc, we have
x y = x1 y1 s^2 + (x1 y0 + x0 y1) s + x0 y0
a1, a3 = addc (x1 y0) (x0 y1)
x y = (a3 s + x1 y1) s^2 + a1 s + x0 y0
b1, b2 = split a1
x y = (a3 s + x1 y1 + b2) s^2 + b1 s + x0 y0
c0, c2 = addc (x0 y0) b1
x y = (a3 s + x1 y1 + b2 + c2) s^2 + c0
128 bit shifting #
@[irreducible]
Multiply by 2^(s % 128), discarding overflow bits
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[irreducible]
Divide by 2^(s % 128), rounding down
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- instHShiftRightUInt128UInt64 = { hShiftRight := fun (x : UInt128) (s : UInt64) => x.shiftRight s }
@[irreducible]
Divide by 2^s, rounding up or down
Equations
Instances For
@[simp]
Shifting left by zero does nothing
theorem
UInt128.approx_shiftRightRound
(x : UInt128)
(s : UInt64)
(up : Bool)
:
Rounds (↑(x.shiftRightRound s up)) (↑x / 2 ^ s.toNat) up
shiftRightRound rounds as desired
@[simp]
@[simp]