0

What issue occurs in simulation or synthesis if I assign a non-constant value to initial value of for loop variable in VHDL or Verilog? E.g- If I write a test case like:

module dut(input clk, d, output reg [5:0] q);
 integer i, j, k, l;
always @(posedge clk)
 begin
for(i =k;j < 4;k++, l++) begin
q[i] <= d;
end
end
 endmodule

What will be the issue?

1
  • In VHDL IEEE Std 1076.6-2004 (RTL Synthesis, withdrawn) 8.8.9 Loop statement For a discrete range that appears as part of a parameter specification, the bounds of the discrete range shall be specified directly or indirectly as static values belonging to an integer type. IEEE Std 1076-2008 9.4 Static expressions limits those to a locally (9.4.2) or a globally (9.4.3) static range. Indirectly includes position number for enumerated values (5.2 Scalar types, 5.2.2 Enumerated types). Discrete range (5.3.2.1) includes a range expression, a subtype indication (6.3) and range attribute (5.2.1). Commented Aug 6, 2018 at 21:51

2 Answers 2

2

What will be the issue?

The issue is that you can only use the code in simulation. That is: you will not be able to synthesize the code and produce hardware from it.

In synthesis the for-loop is unrolled and hardware is generated for each step through the loop. For that the synthesis tool must know during compile time how often the loop is executed.

Sign up to request clarification or add additional context in comments.

Comments

1

A for can be written as a do-while loop

for(<Initialization>;<Condition>;<Iteration>) <Statement>;

<Initialization>;
do
 begin
 <Statement>;
 <Iteration>;
end
while (<Condition>);

So once the clause i=kexecutes, it does not matter what happens to the value of k.

Synthesis requires that the total number of loop iterations be computed at compile time. You have to provide expressions that can be evaluated at compile time. So most likely if the starting and ending iteration values are not constants, the loop will not be synthesizable.

Comments

Your Answer

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.