What's the difference between a += 1
and a = a+1
in Verilog?
always_comb begin
a = '0;
a += 1;
end
always_comb begin
a= '0;
a = a+1;
end
Is the 2nd case a combinational loop?
2 Answers 2
a+=1
is just a short-hand for a=a+1
. They both are equivalent.
There is no combinational loop in both cases.
a
will be simply driven 1
in both cases. Synthesiser usually flags this as warning or info.
These are equivalent assignment statements in SystemVerilog—there is absolutely no difference. And the two always_comb
blocks do absolutely nothing as they have no sensitivity to any variables. In fact, some tools may generate warnings or errors stating that the blocks do not represent combinational logic.
-
1\$\begingroup\$ The
always_comb
will run once per IEEE1800-2017 § 9.2.2.2.2 always_comb compared to always @* "always_comb
automatically executes once at time zero, whereasalways @*
waits until a change occurs on a signal in the inferred sensitivity list." \$\endgroup\$Greg– Greg2019年12月03日 16:30:22 +00:00Commented Dec 3, 2019 at 16:30 -
\$\begingroup\$ Yes, that's true for simulation. Not sure how synthesis tools treat time 0 behavior \$\endgroup\$dave_59– dave_592019年12月03日 16:32:58 +00:00Commented Dec 3, 2019 at 16:32
Explore related questions
See similar questions with these tags.
+=
with=+
because those expressions are different. \$\endgroup\$