Skip to content

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 checks len >= 0).
  • Bit layout (LSB-first): Element i occupies [i * T.width + T.width - 1 : i * T.width]. Total width is len * T.width.
  • Static indexing arr[i]:
    • i must be UInt; Z3 verifies 0 <= 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).
    • idx must be Bits(clog2(len)) or Int(clog2(len)).
    • Returns T with timing join(arr.timing, idx.timing).
    • Out-of-range runtime indices (idx >= len when len is not a power of two) evaluate to all-zeros (0).
  • Functional mapping arr.map(fn):
    • fn must 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 of fn.

Tuple(T0, T1, ...) ​

  • Constructor: Tuple(T0: LogicType, T1: LogicType, ...) (any number of element types, including empty Tuple()).
  • Bit layout (LSB-first): Element .0 sits at bit 0, element .1 immediately above it, etc. Total width is sum(Ti.width).
  • Literals: (e0, e1, ...); timing is the LUB of all element timings.
  • Element access: tup.0, tup.1, ... (bounds-checked at compile time). Projects AssignPath (AssignStep::TupleIndex) for independent element assignment.

Clock ​

  • Built-in 1-bit LogicType (Clock.width == 1).
  • Every Clock-typed port or wire receives a distinct ClockDomain::Signal identity used by Timing(clk), Dynamic(clk), and seq 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 interface body are written from the provider's perspective:
    • In a provides module, output fields are assignable and input fields are read-only.
    • In a consumes module, directions invert (input fields are assignable, output fields are read-only).
    • Accessing a submodule's interface (sub.intf) inverts perspective relative to the parent module.
  • 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.

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, and connect(a, b) just like user-defined interfaces.
  • Flattens during elaboration to <name>_ready (1 bit) and <name>_req (1 + T.width bits).

Universal Properties & Methods ​

  • <LogicType>.width: Evaluates to a compile-time UInt equal to the packed bit width of any LogicType (including generic T: LogicType parameters, structs, unions, options, tuples, arrays, enums, Bits, Int, and Clock).
  • val.castTo(T: LogicType): Reinterprets any LogicVal as T while preserving its timing, provided Z3 proves val_ty.width == T.width.