Arrays, Tuples & Interfaces
This page specifies Neo's remaining built-in composite logic types, Clock, universal type/value properties, and interfaces.
Array(T, len)
- Constructor:
Array(elem: LogicType, len: UInt)(Z3 checkslen >= 0). - Bit layout (LSB-first): Element
ioccupies[i * T.width + T.width - 1 : i * T.width]. Total width islen * T.width. - Static indexing
arr[i]:imust beUInt; Z3 verifies0 <= i < len(index_out_of_bounds).- Projects
AssignPath(AssignStep::ArrayIndex), allowing individual elements to be assigned when Z3 proves indices are disjoint.
- Dynamic indexing
arr.select(idx):- Requires
len >= 1(argument_invariant_error). idxmust beBits(clog2(len))orInt(clog2(len)).- Returns
Twith timingjoin(arr.timing, idx.timing). - Out-of-range runtime indices (
idx >= lenwhenlenis not a power of two) evaluate to all-zeros (0).
- Requires
- Functional mapping
arr.map(fn):fnmust be a pure hardware logic function#(input x(...): T) -> output y(...): U => ...with 1 input, a declared output, and no external captures (#[...]).- Returns
Array(U, len)with the output timing offn.
Tuple(T0, T1, ...)
- Constructor:
Tuple(T0: LogicType, T1: LogicType, ...)(any number of element types, including emptyTuple()). - Bit layout (LSB-first): Element
.0sits at bit0, element.1immediately above it, etc. Total width issum(Ti.width). - Literals:
(e0, e1, ...); timing is the LUB of all element timings. - Element access:
tup.0,tup.1, ... (bounds-checked at compile time). ProjectsAssignPath(AssignStep::TupleIndex) for independent element assignment.
Clock
- Built-in 1-bit
LogicType(Clock.width == 1). - Every
Clock-typed port or wire receives a distinctClockDomain::Signalidentity used byTiming(clk),Dynamic(clk), andseq clk { ... }for static CDC verification. - See Timing & Clock Domains.
Interfaces & Decoupled(T)
User-Defined Interfaces
neo
pub interface Stream(T: LogicType, t: Timing) {
output data(t): T,
input ack(t): Bits(1),
}- Declared with
interface Name(params...) [where ...] { (input|output) field(timing)[: Type], ... }. - Directions in the
interfacebody are written from the provider's perspective:- In a
providesmodule,outputfields are assignable andinputfields are read-only. - In a
consumesmodule, directions invert (inputfields are assignable,outputfields are read-only). - Accessing a submodule's interface (
sub.intf) inverts perspective relative to the parent module.
- In a
connect(a, b):- Valid at module top level (not inside
comb/seq). - Requires identical nominal interface kind and Z3-equal arguments (
connect_type_mismatch). - Requires opposite effective directions (
connect_same_direction), seamlessly supporting both peer-to-peer (connect(prod.bus, cons.bus)) and passthrough (connect(sub.bus, parent_bus)) wiring. - Marks all assignable fields on both sides as driven in the single-assignment tracker.
- Valid at module top level (not inside
Built-In Decoupled(T)
Decoupled(T: LogicType) is a built-in interface equivalent to:
neo
interface Decoupled(T: LogicType) {
input ready(*): Bits(1),
output req(*): Option(T),
}- Both fields have dynamic
(*)(ClockDomain::Any) timing. - Works with
provides,consumes, andconnect(a, b)just like user-defined interfaces. - Flattens during elaboration to
<name>_ready(1 bit) and<name>_req(1 + T.widthbits).
Universal Properties & Methods
<LogicType>.width: Evaluates to a compile-timeUIntequal to the packed bit width of anyLogicType(including genericT: LogicTypeparameters, structs, unions, options, tuples, arrays, enums,Bits,Int, andClock).val.castTo(T: LogicType): Reinterprets anyLogicValasTwhile preserving its timing, provided Z3 provesval_ty.width == T.width.