Skip to content

Logic Values & Control Flow ​

Logic values represent hardware wires and registers in Neo. Unlike Verilog's untyped bit vectors, every logic value carries a strong LogicType, a cycle timing, and a clock domain.

Declaring Logic Values ​

Declare internal signals with the logic keyword:

neo
logic flag(t);                    // Defaults to Bits(1)
logic bus(t): Bits(32);           // Uninitialized wire (must be assigned once)
logic sum(t): Int(32) = a + b;    // Declared with an inline initializer
logic mask: Bits(4) = "1010";     // Omitted timing => Constant

Local logic declarations can appear at the top level of a module, inside assign { ... } blocks, or inside comb and seq blocks.

Continuous Assignments (assign) ​

Static combinational wiring uses either a single assign statement or a grouped assign { ... } block:

neo
assign out = a + b;

assign {
  sub.a = a;
  sub.b = b;
  out = sub.out;
}

Inside assign, source timing must be assignable to the target's timing without advancing cycles (e.g., t to t, or Constant to anything).

Combinational Blocks (comb) ​

Use comb for conditional combinational logic (analogous to always_comb in SystemVerilog):

neo
comb {
  if sel {
    out_a = x;
    out_b = y;
  } else {
    out_a = y;
    out_b = x;
  }
}

Neo enforces strict safety rules in comb blocks:

  1. Single assignment: Every signal (or disjoint struct field / tuple element / bit slice / array index) may be assigned at most once across the module. Double-driving any signal is a compile-time error (multi_assignment).
  2. Consistent branch assignments (latch prevention): Every branch of an if, case, or match inside comb must assign the exact same set of signals, and every if inside comb must have an else branch. Missing assignments in a branch are rejected (inconsistent_conditional_assignments), guaranteeing latch-free combinational hardware.
  3. Write-before-read ordering: Within a comb block, reading a signal and then assigning to it later in the same block is rejected (comb_read_before_write).

Partial-Order Operator Precedence ​

Neo intentionally uses a partial-order precedence parser to avoid subtle hardware operator bugs. Standard hierarchies (*///% over +/-, arithmetic/bitwise/shift over comparisons </==, and comparisons over &&/||) bind automatically, while ambiguous combinations—such as mixing &, |, and ^ with each other or with +/-, or mixing && with ||—require explicit parentheses (ambiguous_operator_precedence).

Sequential Blocks (seq and seq clk) ​

Use seq for edge-triggered flip-flop logic (analogous to always_ff @(posedge ...)):

neo
seq {
  if en {
    reg_out = next_val;
  }
  // Optional `else`: when omitted, `reg_out` holds its previous value.
}

To clock a sequential block with an explicit Clock-typed port or wire instead of __defaultClock, pass the clock identifier after seq:

neo
seq fast_clk {
  // Reads and writes are checked against `fast_clk`'s clock domain
  fast_reg = fast_in;
}

Key seq semantics:

  • +1 cycle advancement: Assigning a value of timing t to a non-local register target inside seq advances the timing by +1 cycle, matching a target of timing t + 1.
  • Optional else for hold: Unlike comb, an if inside seq may omit else (or assign different subsets of registers across branches); unassigned registers naturally retain their state.
  • seq-local combinational temporaries: A logic variable declared inside a seq block behaves as a combinational temporary (no +1 cycle delay), making intermediate calculations easy to express without introducing extra pipeline registers. If an uninitialized seq-local is written conditionally (e.g., in an if without else), it deterministically defaults to 0 when the branch is not taken (matching both SystemVerilog and FIRRTL backends):
neo
seq {
  logic sum(t): Int(32) = a + b;
  out = sum + c; // `out` has timing `t + 1`
}
  • Cross-domain checking: Reading a signal from an incompatible clock domain inside seq reports clock_domain_mismatch, and assigning to a target in an incompatible clock domain reports seq_block_clock_mismatch.

Expression-Based Control Flow ​

if, case, match, and the ternary operator cond ? a : b are all expressions in Neo and can produce values directly:

neo
assign out = sel ? a : b;

comb {
  out = if sel { a } else { b };
}

case Expressions & Exhaustiveness ​

case matches on Enum, Bits, or Int values:

neo
comb {
  out = case mode {
    "00" => a + b,
    "01" => a - b,
    "10" => a & b,
    _ => 0#32,
  };
}

Neo statically verifies case exhaustiveness:

  • For Enum types, every variant must be matched unless a _ wildcard arm is present (non_exhaustive_case).
  • For Bits(w) and Int(w) with concrete width w <= 8, Neo checks whether all 2^w values are covered; wider or symbolic widths require a _ wildcard arm.
  • Duplicate constant patterns trigger a duplicate_case_arm warning, a _ arm when all values are already covered triggers an unreachable_wildcard warning, and placing _ before the last arm triggers a non_trailing_wildcard warning.

match Expressions ​

match destructures tagged union and Option(T) values exhaustively. See Unions & Option for details.