Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System Verilog- Wait statements

I'm confused about the exact meaning of the wait statement.

What happens in this case:

forever begin
    wait (vif.xn_valid == 1'b1);
    @(posedge vif.clk);
end

Is the wait statement blocking? Is the

@(posedge vif.clk)

executed every time inside the loop, regardless of the evaluation of the wait expression?

And in this case:

forever begin
    wait(vif.cyc_tic == 1'b1) @(posedge vif.clk) #0 fact_log2_samp_t = vif.fact_log2_samp;
end

Is the code after the wait (#0 fact_log2_samp_t = vif.fact_log2_samp; ) executed only if the evaluation of the wait expression is true?

like image 203
sarad Avatar asked Jan 24 '26 23:01

sarad


1 Answers

In this case

forever begin
    wait (vif.xn_valid == 1'b1);
    @(posedge vif.clk);
end

the loop blocks until the expression (vif.xn_valid == 1'b1) is true, then it blocks until there is a posedge on vif.clk.

A wait statement blocks until the condition is true. If the condition is already true then execution carries on immediately.

In this case:

forever begin
    wait(vif.cyc_tic == 1'b1) @(posedge vif.clk) #0 fact_log2_samp_t = vif.fact_log2_samp;
end

the loop blocks until the expression (vif.cyc_tic == 1'b1) is true, then it blocks until there is a posedge on vif.clk. It is the same as:

forever begin
    wait(vif.cyc_tic == 1'b1);
    @(posedge vif.clk);
    #0 fact_log2_samp_t = vif.fact_log2_samp;
end
like image 177
Matthew Taylor Avatar answered Jan 26 '26 13:01

Matthew Taylor