Arrays & Tuples
Neo provides built-in Array(T, len) and Tuple(T0, T1, ...) aggregate types for fixed-size homogeneous and heterogeneous collections of hardware signals. Both pack their elements LSB-first.
Arrays: Array(T, len)
Array(T, len) creates a fixed-length array of len: UInt elements of type T: LogicType. Element 0 occupies the least significant bits ([T.width - 1 : 0]), and element i occupies [i * T.width + T.width - 1 : i * T.width]. Total width is len * T.width.
Static Indexing (arr[i])
Square-bracket indexing arr[i] takes a compile-time UInt index i. Z3 symbolically verifies 0 <= i < len for all valid parameter values:
module LastElement(T: LogicType, len: Pos, t: Timing) {
input data(t): Array(T, len),
output last(t): T,
} {
// Because `len` is `Pos` (>= 1), Z3 proves `len - 1` cannot underflow
// and `0 <= len - 1 < len`.
assign last = data[len - 1];
}Static indexing can also appear on the left-hand side of assignments to drive individual elements.
Dynamic Indexing (.select(idx))
To multiplex an array using a hardware signal index at runtime, use .select(idx):
module Mux(T: LogicType, len: Pos, t: Timing) {
input table(t): Array(T, len),
input idx(t): Bits(clog2(len)),
output out(t): T,
} {
assign out = table.select(idx);
}- Requires a non-empty array (
len >= 1). idxmust beBits(clog2(len))orInt(clog2(len)).- If
lenis not a power of two andidx >= lenat runtime,.select(idx)safely evaluates to all-zeros (0). - Result timing is the LUB of the array's timing and
idx's timing.
Functional Mapping (.map(fn))
Transform every element of an array using a pure hardware logic function #(input x(t): T) -> output y(t): U => ...:
module IncrementAll(len: Pos, t: Timing) {
input xs(t): Array(Int(16), len),
output ys(t): Array(Int(16), len),
} {
let inc = #(input x(t): Int(16)) -> output y(t): Int(16) => x + 1#16;
assign ys = xs.map(inc);
}The function passed to .map(...) must take exactly one input, declare an output, and perform no external side-effect assignments.
Tuples: Tuple(T0, T1, ...)
Tuple creates an anonymous heterogeneous product type. Element .0 occupies the least significant bits, .1 the next bits, and so on.
module Swap(A: LogicType, B: LogicType, t: Timing) {
input pair(t): Tuple(A, B),
output swapped(t): Tuple(B, A),
} {
assign swapped = (pair.1, pair.0);
}- Construct tuple values with
(e0, e1, ...). - Access or assign individual elements with numeric field syntax
.0,.1, etc. (bounds-checked at compile time). - Tuple literal timing is the LUB of all element timings.
- Query total bit width with
Tuple(A, B).width.
Bit-Width Reinterpretation (.castTo(T))
Any logic value—including Bits, Int, Enum, Struct, Union, Option, Tuple, and Array—supports .castTo(T) to reinterpret its packed bit representation as another LogicType T, provided Z3 proves both types have the exact same total bit width:
logic raw(t): Bits(pair_ty.width) = pair.castTo(Bits(pair_ty.width));