always, always_comb and always_ff explained
Compare Verilog always with SystemVerilog always_comb and always_ff, including sensitivity, assignment and single-driver rules.
always
Verilog always is general purpose. The sensitivity list and body determine whether it models combinational logic, a latch or sequential logic.
always @* y = (sel) ? a : b;
always @(posedge clk) q <= d;
@* automatically includes signals read by the block and is safer than a hand-maintained combinational sensitivity list.
always_comb
SystemVerilog always_comb expresses combinational intent. Tools build the sensitivity set, execute the block once at time zero, and can diagnose variables written by another process. Every output still needs an assignment on every path.
always_comb begin
next_state = state;
if (advance) next_state = state + 1'b1;
end
Do not use nonblocking assignments or intentional storage in always_comb. A missing branch can still imply a latch and should be reported by lint.
always_ff
always_ff states that a process models flip-flops or other event-controlled state. A variable written in it must not be written by another process.
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) q <= '0;
else q <= d;
end
Use nonblocking assignments for state. Keep combinational next-state calculation in always_comb and state updates in always_ff.
Choosing the construct
- Existing Verilog:
always @*for combinational logic and edge-sensitivealwaysfor registers. - SystemVerilog RTL: prefer
always_combandalways_ffbecause they communicate intent and enable stronger checks. - Use
always_latchonly when a level-sensitive latch is deliberate and documented.