i64.bend checks
raw source on the hub · import 0x9f15483a7cabc6e91e5092cc41829c43/i64.bend as I64
bend-i64: a SIGNED 64-bit integer in pure Bend, two's complement over Word(64n). Source: https://github.com/phenomenon0/bend-i64
The arithmetic is bit-identical to unsigned two's complement — add, sub, mul and the bitwise ops ride the same width-64 Word.* instantiations. The signed layer is interpretation: negation as 0 - x, SIGNED comparison by biasing both operands with the sign bit (x XOR 2^63) before the unsigned compare, and arithmetic right shift that replicates the sign.
The law is machine-checked: add_comm is proved by instantiating Base's own generic inductive lemma Word.add_comm(64n, ...) — and it transfers to the signed reading exactly because addition ignores the sign.
Speed: same as its unsigned twin — every op walks the generic Word(64n) layer (reference-grade on hot loops; bench in the repo README). A native word-64 lowering turns the same semantics into machine-speed ops — merged in the omen fork, proposed upstream. Cold paths today: IDs, deltas, proofs.
Boundaries, stated honestly: - to_nat is valid for 0 <= v <= 2^48-1 (Nat immediate limit); negative values read as their bit pattern and are documented, not converted. - shl.n / shr.s.n are bit-at-a-time folds (n small); O(n). - Division is not implemented yet. - No FFI, no intrinsics, no unsafe; checked on stock Bend 2.0.17.
Note on order: dotted defs (x.y) are defined before their first call — this file keeps that discipline throughout (see tests note in the README).
1 import
import Base
Laws
law add_comm provedsource · line 212 · raw
@a:I64 -> @b:I64 -> {add(a, b) == add(b, a) : I64}
Types
type I64 source · line 30 · raw
Data
I64@data:Word(64n) -> I64
Definitions
def shl.n.w source · line 35 · raw
@n:Nat -> @w:Word(64n) -> Word(64n)
def sign_mask.w source · line 40 · raw
Word(64n)
def bias.w source · line 43 · raw
@x:Word(64n) -> Word(64n)
def cmp.eq source · line 46 · raw
@c:Cmp -> Bool
def cmp.lt source · line 52 · raw
@c:Cmp -> Bool
def cmp.gt source · line 58 · raw
@c:Cmp -> Bool
def ge.cmp source · line 64 · raw
@c:Cmp -> Bool
def ge.w source · line 70 · raw
@x:Word(64n) -> Bool
def scmp.w source · line 73 · raw
@a:Word(64n) -> @b:Word(64n) -> Cmp
def shrs.pick source · line 76 · raw
@sgn:Bool -> @y:Word(64n) -> Word(64n)
def shrs.w source · line 81 · raw
@+x:Word(64n) -> Word(64n)
def zero source · line 86 · raw
I64
def one source · line 89 · raw
I64
def minus_one source · line 92 · raw
I64
def min source · line 95 · raw
I64
def max source · line 98 · raw
I64
def add source · line 103 · raw
@a:I64 -> @b:I64 -> I64
def sub source · line 108 · raw
@a:I64 -> @b:I64 -> I64
def mul source · line 113 · raw
@a:I64 -> @b:I64 -> I64
def inc source · line 118 · raw
@a:I64 -> I64
def neg source · line 123 · raw
@a:I64 -> I64
def and source · line 130 · raw
@a:I64 -> @b:I64 -> I64
def or source · line 135 · raw
@a:I64 -> @b:I64 -> I64
def xor source · line 140 · raw
@a:I64 -> @b:I64 -> I64
def not source · line 145 · raw
@a:I64 -> I64
def shl source · line 152 · raw
@a:I64 -> I64
def shl.n source · line 157 · raw
@n:Nat -> @a:I64 -> I64
def shr source · line 162 · raw
@a:I64 -> I64
def shr.s source · line 167 · raw
@a:I64 -> I64
def shr.s.n source · line 172 · raw
@n:Nat -> @a:I64 -> I64
def cmp source · line 179 · raw
@a:I64 -> @b:I64 -> Cmp
def is_eq source · line 184 · raw
@a:I64 -> @b:I64 -> Bool
def is_lt source · line 187 · raw
@a:I64 -> @b:I64 -> Bool
def is_gt source · line 190 · raw
@a:I64 -> @b:I64 -> Bool
def is_neg source · line 193 · raw
@a:I64 -> Bool
def not.b source · line 198 · raw
@b:Bool -> Bool
def to_nat source · line 205 · raw
@a:I64 -> Nat