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)— requireswidth >= 0(Z3-checked).Bits(0)is valid and elided during hardware emission.Bits(w).width— evaluates tow: UInt.
Literals & Coercion
- Bit-strings:
"0101"produces aConstant-timedBits(4). Only'0'and'1'are allowed (strict 2-state logic;x/zproduceinvalid_bit_string).""producesBits(0). - Bare
0/1: Automatically coerce toBits(1)when an expected logic type is present. - From
Int(w):Int(w) <: Bits(w), so anyInt(w)(includingv#wand0xFF#wconstants) is implicitly assignable toBits(w). - From
UInt/Bool:n.toBits(w)producesBits(w);b.toBits()producesBits(1).
Operators
Binary Operators
| Operator | Operands | Result Type | Semantics |
|---|---|---|---|
&, |, ^ | 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
| Operator | Result Type | Semantics |
|---|---|---|
~x | Bits(w) | Bitwise inversion |
!x | Bits(1) | Logical negation |
&x, |x, ^x | Bits(1) | Reduction AND, OR, XOR |
Bit Selection (x{...})
x{i}: Selects single biti(Bits(1)).x{hi:lo}: Selects inclusive range[hi:lo](Bits(hi - lo + 1)).x{a:b}witha < b: Reversed bit-select; reverses bit order by concatenating bitsa, a+1, ..., bMSB-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): ReinterpretsBits(w)asInt(w).x.zextend(w2: UInt)->Bits(w2): Zero-extends tow2(Z3 verifiesw2 >= w).x.repeat(n: Pos)->Bits(w * n): Concatenatesncopies ofx(Z3 verifiesw >= 1andn >= 1).x.castTo(T: LogicType)->T: Reinterprets bits asT(Z3 verifiesw == T.width).