2
\$\begingroup\$

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?

toolic
10.8k11 gold badges31 silver badges35 bronze badges
asked Dec 3, 2019 at 1:38
\$\endgroup\$
1
  • \$\begingroup\$ It's the same thing. Just make sure you don't mistake += with =+ because those expressions are different. \$\endgroup\$ Commented Dec 3, 2019 at 6:19

2 Answers 2

5
\$\begingroup\$

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.

answered Dec 3, 2019 at 5:56
\$\endgroup\$
2
\$\begingroup\$

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.

answered Dec 3, 2019 at 5:36
\$\endgroup\$
2
  • 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, whereas always @* waits until a change occurs on a signal in the inferred sensitivity list." \$\endgroup\$ Commented Dec 3, 2019 at 16:30
  • \$\begingroup\$ Yes, that's true for simulation. Not sure how synthesis tools treat time 0 behavior \$\endgroup\$ Commented Dec 3, 2019 at 16:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.