Parameterization
Modules, structs, unions, and interfaces can all be parameterized at compile time. Because Neo's frontend checks every parameterized declaration symbolically with Z3, a declaration that passes neo check is verified for all valid parameter combinations—not just the ones instantiated in a testbench.
Compile-Time Parameter Types
Declarations accept parameters of the following compile-time meta types:
| Parameter Type | Meaning | Typical Uses |
|---|---|---|
UInt | Non-negative integer (>= 0) | Zero-based indices, Bits(w), Array(T, n), 0#0 |
Pos | Strictly positive integer (>= 1) | Non-empty widths/lengths (data[len - 1], clog2(n), .repeat(n)) |
Bool | Compile-time boolean (true / false) | Conditional hardware generation (if use_reg { ... } else { ... }) |
LogicType | First-class hardware type value | Generic data containers, FIFOs, arbiters, pipelines |
Timing | Symbolic single-cycle timing trigger | Reusable cycle-accurate pipeline stages |
UInt vs Pos
UIntis assumed>= 0. Subtractiona - bis Z3-checked against underflow (a >= b, elseuint_underflow), and/and%are Z3-checked against division by zero (b >= 1, elsedivision_by_zero).UIntvalues also provide.toBits(w)and.toInt(w)to materialize hardware constants.Posis assumed>= 1inside the declaration body and verified>= 1at every call site (argument_invariant_error). UsingPoslets Z3 prove expressions likelen - 1,clog2(len), andx.repeat(n)are always safe without extrawhereclauses.
module ShiftReg(T: LogicType, width: Pos, t: Timing) {
input data(t): Array(T, width),
output head(t): T,
output tail(t): T,
} {
assign head = data[0];
assign tail = data[width - 1]; // Safe: width >= 1
}Bool Parameters and Compile-Time if
Bool supports true, false, !, &&, ||, ^, ==, !=, and .toBits() (converting to a 1-bit Constant Bits(1)). Comparing two UInt values with <, <=, >, >=, ==, or != also produces a Bool.
When an if condition is a compile-time Bool, Neo evaluates it at compile time (and pushes the branch condition into Z3 during symbolic checking):
module OptionalInvert(invert: Bool, w: Pos, t: Timing) {
input x(t): Bits(w),
output y(t): Bits(w),
} {
assign y = if invert { ~x } else { x };
}where Invariants
When parameter constraints go beyond UInt (>= 0) and Pos (>= 1), attach a where clause to any parameterized module, struct, union, or interface:
module SliceHigh(w: Pos, lo: UInt, t: Timing)
where lo: lo < w {
input x(t): Bits(w),
output y(t): Bits(w - lo),
} {
assign y = x{w - 1 : lo};
}Multiple constraints on the same parameter can be grouped with brackets:
where lo: [lo < w, lo % 2 == 0].Inside the body of
SliceHigh, Z3 assumeslo < w, sow - locannot underflow andx{w - 1 : lo}is proven in bounds.At every call site (e.g.,
SliceHigh(16, 8, t)), Z3 proves thewhereinvariant holds and reportsargument_invariant_error(with a related span pointing to the invariant declaration) if it can be violated.
LogicType Parameters and .width
Types in Neo are first-class compile-time values (LogicType). Passing Bits(32), Int(w), MyStruct, or Option(T) works just like passing any other argument:
struct Tagged(T: LogicType, tag_w: Pos) {
tag: Bits(tag_w),
payload: T,
}
module Serializer(T: LogicType, t: Timing) {
input in(t): T,
output raw(t): Bits(T.width),
} {
assign raw = in.castTo(Bits(T.width));
}Compile-Time Lambdas and Logic Functions
- Compile-time lambdas
(a, b) => a + babstract over compile-time values (UInt,Bool,LogicType,Timing). - Hardware logic functions
#[captures](input x(t): T) -> output y(t): U => exprabstract over hardware logic expressions and can be invoked withfn#(arg)or passed toArray.map(fn).
Monomorphization
Parameters are evaluated completely during elaboration (neo-elab). Each distinct set of concrete non-timing arguments produces a specialized concrete module in neo-ir, SystemVerilog, and FIRRTL, with no SystemVerilog runtime parameters required.