Skip to content

Structs ​

Structs group related signals under a single LogicType, enforcing a unified timing and port direction while supporting field-level reads, partial assignments, computed get getters, and parameterization.

Definition ​

neo
struct Packet {
  valid,                // Omitted type defaults to Bits(1)
  addr: Bits(16),
  data: Int(32),
}

struct Pair(T: LogicType) {
  left: T,
  right: T,
}

Fields are packed LSB-first into the flattened bit vector: the first declared field occupies the least significant bits ([w0 - 1 : 0]), and subsequent fields are placed at higher bit offsets. The total width Packet.width equals the sum of all field widths.

Instantiating and Using Structs ​

Unparameterized structs are LogicType values directly; parameterized structs are called like functions:

neo
logic pkt(t): Packet;
logic pair(t): Pair(Int(32));

Struct Literals and .{...} Shorthand ​

Construct a struct value with explicit type syntax MyStruct.{ ... } or inferred .{ ... } shorthand when the target struct type is known from context:

neo
assign pkt = .{
  valid: 1,
  addr: 0x0010#16,
  data: 42#32,
};

Field-name punning is supported when a variable in scope has the same name as the field:

neo
assign pkt = .{ valid, addr, data };

The timing of a struct literal is the least upper bound (LUB) of its field timings in Neo's timing lattice.

Reading and Assigning Fields ​

Fields can be read or assigned individually (provided each field is driven at most once), or the struct can be assigned as a whole:

neo
assign pair.left = a;
assign pair.right = b;

logic sum(t): Int(32) = pair.left + pair.right;

Struct Getters (get) ​

Structs can declare read-only computed properties using get. Inside a getter body, this refers to the struct value and all declared fields and sibling getters are directly in scope:

neo
struct AluPair {
  a: Int(32),
  b: Int(32),
  get sum: Int(32) => a + b,
  get is_equal => this.a == this.b,   // Omitted return type defaults to Bits(1)
}

Getters are purely combinational and read-only (they cannot be assigned to). Direct or mutual getter recursion cycles are statically rejected (recursive_getter).