Skip to content

Bits ​

Bits(width) represents an unsigned, untyped 2-state bit vector of compile-time width width: UInt (>= 0). When a : Type annotation is omitted on a port, interface field, struct field/getter, or logic signal, Neo defaults to Bits(1).

Constructor & Width ​

  • Bits(width: UInt) — requires width >= 0 (Z3-checked). Bits(0) is valid and elided during hardware emission.
  • Bits(w).width — evaluates to w: UInt.

Literals & Coercion ​

  • Bit-strings: "0101" produces a Constant-timed Bits(4). Only '0' and '1' are allowed (strict 2-state logic; x/z produce invalid_bit_string). "" produces Bits(0).
  • Bare 0 / 1: Automatically coerce to Bits(1) when an expected logic type is present.
  • From Int(w): Int(w) <: Bits(w), so any Int(w) (including v#w and 0xFF#w constants) is implicitly assignable to Bits(w).
  • From UInt / Bool: n.toBits(w) produces Bits(w); b.toBits() produces Bits(1).

Operators ​

Binary Operators ​

OperatorOperandsResult TypeSemantics
&, |, ^Equal-width Bits(w) / Int(w)Int(w) if both operands are Int(w), else Bits(w)Bitwise AND, OR, XOR
==, !=Equal-width Bits(w) / Int(w)Bits(1)Bitwise equality / inequality
&&, ||Bits(1) / Int(1)Bits(1)1-bit logical AND / OR
<<Bits(w) / Int(w) << Bits(s) / Int(s)Int(w) if both operands are Int, else Bits(w)Logical left shift
>>Bits(w) / Int(w) >> Bits(s) / Int(s)Int(w) if both operands are Int, else Bits(w)Logical right shift (zero-fill)
>>>Bits(w) / Int(w) >>> Bits(s) / Int(s)Int(w) if both operands are Int, else Bits(w)Arithmetic right shift (sign-extend MSB)
##Bits(w1) / Int(w1) ## Bits(w2) / Int(w2)Int(w1 + w2) if both operands are Int, else Bits(w1 + w2)MSB-first concatenation (lhs in upper bits, rhs in lower bits)

All binary operators join their operand timings via LUB in the timing lattice.

Unary Operators ​

OperatorResult TypeSemantics
~xBits(w)Bitwise inversion
!xBits(1)Logical negation
&x, |x, ^xBits(1)Reduction AND, OR, XOR

Bit Selection (x{...}) ​

  • x{i}: Selects single bit i (Bits(1)).
  • x{hi:lo}: Selects inclusive range [hi:lo] (Bits(hi - lo + 1)).
  • x{a:b} with a < b: Reversed bit-select; reverses bit order by concatenating bits a, a+1, ..., b MSB-first.
  • x{r1, r2, ...}: Concatenates multiple bit selections MSB-first.
  • All indices are Z3-checked to lie in [0, w - 1]. Bit selections may appear on the LHS of assignments to drive disjoint bit slices.

Methods ​

  • x.asInt() -> Int(w): Reinterprets Bits(w) as Int(w).
  • x.zextend(w2: UInt) -> Bits(w2): Zero-extends to w2 (Z3 verifies w2 >= w).
  • x.repeat(n: Pos) -> Bits(w * n): Concatenates n copies of x (Z3 verifies w >= 1 and n >= 1).
  • x.castTo(T: LogicType) -> T: Reinterprets bits as T (Z3 verifies w == T.width).