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:
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 => ConstantLocal 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:
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):
comb {
if sel {
out_a = x;
out_b = y;
} else {
out_a = y;
out_b = x;
}
}Neo enforces strict safety rules in comb blocks:
- 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). - Consistent branch assignments (latch prevention): Every branch of an
if,case, ormatchinsidecombmust assign the exact same set of signals, and everyifinsidecombmust have anelsebranch. Missing assignments in a branch are rejected (inconsistent_conditional_assignments), guaranteeing latch-free combinational hardware. - Write-before-read ordering: Within a
combblock, 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 ...)):
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:
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
tto a non-local register target insideseqadvances the timing by+1cycle, matching a target of timingt + 1. - Optional
elsefor hold: Unlikecomb, anifinsideseqmay omitelse(or assign different subsets of registers across branches); unassigned registers naturally retain their state. seq-local combinational temporaries: Alogicvariable declared inside aseqblock behaves as a combinational temporary (no+1cycle delay), making intermediate calculations easy to express without introducing extra pipeline registers. If an uninitializedseq-local is written conditionally (e.g., in anifwithoutelse), it deterministically defaults to0when the branch is not taken (matching both SystemVerilog and FIRRTL backends):
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
seqreportsclock_domain_mismatch, and assigning to a target in an incompatible clock domain reportsseq_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:
assign out = sel ? a : b;
comb {
out = if sel { a } else { b };
}case Expressions & Exhaustiveness
case matches on Enum, Bits, or Int values:
comb {
out = case mode {
"00" => a + b,
"01" => a - b,
"10" => a & b,
_ => 0#32,
};
}Neo statically verifies case exhaustiveness:
- For
Enumtypes, every variant must be matched unless a_wildcard arm is present (non_exhaustive_case). - For
Bits(w)andInt(w)with concrete widthw <= 8, Neo checks whether all2^wvalues are covered; wider or symbolic widths require a_wildcard arm. - Duplicate constant patterns trigger a
duplicate_case_armwarning, a_arm when all values are already covered triggers anunreachable_wildcardwarning, and placing_before the last arm triggers anon_trailing_wildcardwarning.
match Expressions
match destructures tagged union and Option(T) values exhaustively. See Unions & Option for details.