Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the ++ operator in System Verilog blocking or non-blocking?

Good coding convention says that we should use blocking assignments in a combinational block, and non-blocking assignments in a sequential block. I want to use the ++ operator in a combinatorial block, but I don't know if it is blocking. So is this code:

input [3:0] some_bus;
logic [2:0] count_ones;
always_comb begin
  count_ones = '0;
  for(int i=0; i<4; i++) begin
    if(some_bus[i])
      count_ones++;
  end
end

equivalent to this:

input [3:0] some_bus;
logic [2:0] count_ones;
always_comb begin
  count_ones = '0;
  for(int i=0; i<4; i++) begin
    if(some_bus[i])
      count_ones = count_ones + 1;
  end
end

or this:

input [3:0] some_bus;
logic [2:0] count_ones;
always_comb begin
  count_ones = '0;
  for(int i=0; i<4; i++) begin
    if(some_bus[i])
      count_ones <= count_ones + 1;
  end
end

I did look in the 1800-2012 standard but could not figure it out. An answer that points me to the appropriate section in the standard would be appreciated.

like image 652
nguthrie Avatar asked Mar 19 '14 14:03

nguthrie


People also ask

What are blocking and non-blocking statements in Verilog?

Blocking assignment statements are assigned using (=) operator and are executed one after the other in a procedural block. But, it will not prevent the execution of statements that run in a parallel block. There are two initial blocks which are executed in parallel.

What is non-blocking in Verilog?

Non-blocking assignment allows assignments to be scheduled without blocking the execution of following statements and is specified by a <= symbol. It's interesting to note that the same symbol is used as a relational operator in expressions, and as an assignment operator in the context of a non-blocking assignment.

Which one is non-blocking assignment?

The nonblocking assignment operator is the same as the less-than-or-equal-to operator ("<="). A nonblocking assignment gets its name because the assignment evaluates the RHS expression of a nonblocking statement at the beginning of a time step and schedules the LHS update to take place at the end of the time step.

What is blocking and non-blocking?

Blocking refers to operations that block further execution until that operation finishes while non-blocking refers to code that doesn't block execution. Or as Node. js docs puts it, blocking is when the execution of additional JavaScript in the Node. js process must wait until a non-JavaScript operation completes.


1 Answers

According to section 11.4.2 of IEEE Std 1800-2012, it is blocking.

SystemVerilog includes the C increment and decrement assignment operators ++i , --i , i++ , and i-- . These do not need parentheses when used in expressions. These increment and decrement assignment operators behave as blocking assignments.

like image 163
dwikle Avatar answered Sep 26 '22 14:09

dwikle