Skip to content

Int ​

Int(width) is a subtype of Bits(width) (Int(w) <: Bits(w)) that adds integer arithmetic, unsigned comparisons, signed comparisons, and sign extension.

Constructor & Constants ​

  • Int(width: UInt) — requires width >= 0 (Z3-checked). Int(0) is valid.
  • Int(w).width — evaluates to w: UInt.
  • Sized constants: value#width (decimal or hexadecimal 0x...#width, including 0#0) constructs a Constant-timed Int(width). If value exceeds width bits (or cannot be proved to fit in a symbolic width), Neo rejects it with a truncated_constant / possible_truncated_constant error.
  • Bare 0 / 1: Coerce to Int(1) when Int(1) is expected.
  • From UInt: n.toInt(w) constructs an Int(w) constant.
  • From Bits(w): b.asInt() converts Bits(w) to Int(w).

Operators ​

Int(w) supports all Bits(w) operators (&, |, ^, ~, !, reduction &/|/^, &&/|| for width 1, ==, !=, <<, >> logical right shift, >>> arithmetic right shift, ##, and {...} bit selection) plus:

OperatorOperandsResult TypeSemantics
+, -, *, /, %Equal-width Int(w)Int(w)Wrapping / truncated arithmetic (result width matches operand width)
<, <=, >, >=Equal-width Int(w)Bits(1)Unsigned integer comparisons

Note on bit selection: selecting more than 1 bit from an Int produces Int(res_w), while selecting a single bit produces Bits(1).

Methods ​

Int(w) supports all Bits(w) methods (.asInt(), .zextend(w2) -> Int(w2), .repeat(n) -> Int(w * n), .castTo(T)) plus:

  • x.sextend(w2: UInt) -> Int(w2): Sign-extends x to width w2 (Z3 verifies w >= 1 and w2 >= w).
  • x.slt(other: Int(w)) -> Bits(1): Signed less-than comparison ($signed(x) < $signed(other)). Requires w >= 1.
  • x.slte(other: Int(w)) -> Bits(1): Signed less-than-or-equal comparison. Requires w >= 1.
  • x.sgt(other: Int(w)) -> Bits(1): Signed greater-than comparison. Requires w >= 1.
  • x.sgte(other: Int(w)) -> Bits(1): Signed greater-than-or-equal comparison. Requires w >= 1.

All comparison methods join the timings of x and other via LUB.