Consider the following snippet (please let me know if you need me to include more):
always @(posedge CLK)
begin
if (RST == 1'b1)
OUT <= 4'b0000;
else
OUT <= OUT + 1
end
The above, let's say, is part of some DUT. Now suppose in my testbench which instantiates this DUT that I update CLK
(0 -> 1) and RST
(1 -> 0) at the same time; more precisely, suppose that both are updated in different procedural blocks (so they are concurrent) in the same t=100 time slot's active region (both are blocking assignments). Is there any possibility of nondeterministic/simulator-dependent behavior?
I think the crux/answer to my question will depend on how Verilog treats event-controlled evaluation. I see two possibilities:
(1) RST
gets updated to 0 before the CLK
signal gets updated to 1. Then, when the CLK
signal gets updated there is no problem because the always
block above, which is sensitive to this edge on the CLK
signal, generates an evaluation event in the same t=100 time slot's active region and, eventually, we get OUT <= OUT + 1
as desired.
(2) But what if CLK
updated first? In this case, the always
block above, which is sensitive to this edge on the CLK
signal, generates an evaluation event in the same t=100 time slot's active region. Does this evaluation event occur (a) after or (b) before the RST
update?
(a) In this case, there is no problem since RST
will already be updated and the same decision as in (1) above will be taken.
(b) In this case we will take the wrong path.
Does Verilog have a defined behavior in this case, or is it up to the simulator (in which case code should not be written like this and, perhaps, the RST
update should be done at some time slot before t=100)?