Bits and Int
Bits(w) and Int(w) are Neo's core bit-vector types. Both carry a compile-time width w: UInt (including zero-width Bits(0) and Int(0)).
Bits(w)represents an untyped bit string supporting bitwise operations, shifts, concatenation, bit selection, and equality.Int(w)is a subtype ofBits(w)(Int(w) <: Bits(w)): anInt(w)can be used wherever aBits(w)is expected, and adds arithmetic (+,-,*,/,%), unsigned comparisons (<,<=,>,>=), signed comparisons (.slt,.slte,.sgt,.sgte), and sign extension (.sextend).
Literals and Constants
Strict 2-State Bit-String Literals
Quoted bit strings create Constant values of type Bits(len). Neo enforces strict 2-state logic—only 0 and 1 characters are permitted (x and z are rejected at compile time):
logic nibble: Bits(4) = "1010";
logic empty: Bits(0) = "";Sized Integer Constants (value#width) and Hex Literals
To construct a sized Int(width) constant, use value#width. Both decimal and hexadecimal (0x...) literals are supported, and width may be any UInt expression (including 0):
logic a: Int(32) = 42#32;
logic b: Bits(16) = 0xCAFE#16; // Int(16) coerces to Bits(16)
logic zero_wide: Int(0) = 0#0;
logic param_const: Int(width) = 1#width;If a constant value requires more bits than width (or cannot be proved to fit in a symbolic width), Neo rejects it with a truncated_constant or possible_truncated_constant error.
Bare 0 and 1 Coercion
When a Bits(1) or Int(1) type is expected (such as in assignments, if conditions, &&/||, or struct fields), bare 0 and 1 automatically coerce to 1-bit logic constants:
logic en(t): Bits(1) = 1;
logic ready(t) = 0;Outside a logic-typed context, bare integers like 0, 1, or 0xFF have compile-time type UInt. You can also explicitly convert a UInt to hardware constants with .toBits(w) or .toInt(w).
Operators
Bitwise, Logical, and Reduction Operators
- Binary bitwise:
&,|,^(operands must have equal width) - Unary bitwise NOT:
~x(preserves type and width) - Unary logical NOT:
!x(returnsBits(1)) - Unary reductions:
&x(AND-reduce),|x(OR-reduce),^x(XOR-reduce) — all returnBits(1) - 1-bit logical:
&&,||(require 1-bit operands; returnBits(1)) - Equality:
==,!=(returnBits(1))
Shifts
<<: Logical left shift>>: Logical right shift (zero-fills from the MSB)>>>: Arithmetic right shift (sign-extends from the MSB)
Arithmetic and Comparisons (Int only)
- Arithmetic:
+,-,*,/,%(results wrap/truncate to operand width) - Unsigned comparisons:
<,<=,>,>=(returnBits(1)) - Signed comparisons:
a.slt(b),a.slte(b),a.sgt(b),a.sgte(b)(require width>= 1; returnBits(1))
Concatenation (##)
The ## operator concatenates two Bits or Int values MSB-first (left occupies the upper bits, right occupies the lower bits):
logic word(t): Bits(64) = hi_32 ## lo_32;Bit Selection ({...})
Use curly braces to extract single bits, inclusive ranges, or multiple concatenated slices:
logic bit0(t): Bits(1) = val{0}; // Single bit
logic low_byte(t): Bits(8) = val{7:0}; // Inclusive slice [7:0] (MSB:LSB)
logic rev_byte(t): Bits(8) = val{0:7}; // Reversed range (a < b): flips bit order
logic packed(t): Bits(4) = val{1, 5:3}; // Concatenates bit 1 (MSB) with bits 5..3All bit indices are Z3-checked to lie within [0, width - 1]. Bit selections can also appear on the left-hand side of assignments to drive disjoint bit slices of a wire.
Methods and Type Width
x.asInt(): Reinterprets aBits(w)(orInt(w)) asInt(w).x.zextend(w2): Zero-extendsBits(w)orInt(w)to widthw2(Z3 verifiesw2 >= w).x.sextend(w2): Sign-extendsInt(w)to widthw2(Z3 verifiesw >= 1andw2 >= w).x.repeat(n): Concatenatesncopies ofx(Z3 verifiesw >= 1andn >= 1, returning widthw * n).x.castTo(T): Reinterprets any logic value asTwhen Z3 proves both types have identical total bit width.<LogicType>.width: Evaluates to the compile-timeUIntbit width of any logic type (e.g.,Int(32).widthis32).
For the full operator and method specification, see the Bits Reference and Int Reference.