SNUG Boston 2006 13 Standard Gotchas in Verilog and SystemVerilog
if (!rst_n) State <= WAITE;
else State <= NextState;
...
endmodule: chip
In the example above, the always_ff flip-flop in module chip is supposed to reset on a negative
edge of
rst_n. The testbench sets rst_n to zero at the beginning of simulation, and holds it low
for 3 nanoseconds. However, in the testbench,
rst_n is a 2-state type, which begins simulation
with a value of zero. Setting rst_n to zero does not change its value, and therefore does not cause
a negative edge on rst_n. Since the testbench does not cause a negative edge on rst_n, the
always_ff sensitivity list for the flip-flop in module chip does not trigger, and the flip-flop does
not reset asynchronously. If rst_n were held low at least one clock cycle, the flip-flop would
reset synchronously when clock occurred. In this example, though, the test stimulus does not hold
rst_n low a full clock cycle, and therefore the reset is completely missed. GOTCHA!
How to avoid this gotcha: This gotcha can be avoided in a number of ways. One way is to
initialize the 2-state reset signal to the non reset value with a blocking assignment, and then to the
reset value with a nonblocking assignment: This will trigger the always_ff blocks waiting for a
negative edge of reset. Additionally, the nonblocking assignment will ensure that all the
always_ff blocks are active before the transition to zero occurs.
initial begin
rst_n = 1; // initialize to inactive value
rst_n <= 0; // set reset to active value using nonblocking assign
#3ns rst_n = 1;
...
A second way to avoid this gotcha is to ensure that the reset is held longer then a clock period,
thus using the clock to trigger the always_ff block. This is not a recommended approach, due to
reset acting like a synchronous reset, rather than an asynchronous reset, which means that the
RTL simulation does not match the gate-level simulation or the design intent.
A third way to fix this gotcha is to use 4-state types instead of 2-state types for active-low signals.
4-state variable types will begin simulation with a value of X. Assigning a 4-state type a value of
zero, even at simulation time zero, will cause an X to zero transition, which is a negative edge.
Note: VCS version 2006.06 does not fully adhere to the IEEE SystemVerilog standard for 2-state
types. The standard says that 2-state types should begin simulation with a value of zero. In VCS,
2-state variable types automatically transition to zero sometime during simulation time zero. This
will cause a negative edge transition at simulation time zero, which might, depending on event
ordering, trigger the design procedural blocks that are looking for a negative edge transition. This
tool-specific, non-standard behavior can hide this 2-state reset gotcha. Engineers should not rely
on this tool-specific behavior as a solution to the gotcha. It is dependent on event ordering, and, at
some future time, VCS could implement the 2-state behavior as it is specified in the standard.
3.2 Locked state machines
Gotcha: 2-state state machines can lock up in the start-up state.
By default, enumerated types are 2-state types, and the default value of the first label in the
enumerated list is zero. Functional logic based on 2-state enumerated data types can have gotchas.