05-08-2019 10:38 AM
Hello,
In my design I've got a for-generate statement as follows:
logic_array : for stage in 0 to (stage_count-1) generate
then under that for-generate statement I've got an if-generate statement which should only be elaborated when the for-generate loop parameter stage is an odd value. Under that if-generate statement I've got a constant declaration in the declarative part which is dependent on the stage parameter and expects it to be odd valued. The code for all that is as follows:
odd_stages : if ((stage mod 2) = 1) generate -- only if odd value constant comp_array_end_index : natural := comp_count-((stage-1)/2); begin
The value of comp_count is the same as loop parameter stage up to a certain value which is 4 in this case (it's a triangle waveform so after that it starts to decrease). When I try to simulate the design I get the following error with a reference to the line where I declear that constant
ERROR: [VRFC 10-1537] value -2 is out of target constraint range 0 to 2147483647
I understand that when stage is 0 then this error can be expected as calculation would be -2. This seems to be the case, except that if-generate statement should only be elaborated when stage is odd value so 1,3,5 etc. So in relation to this constant declaration the value stage should never be 0.
Am I missing something about if-generate statements? Are the constants under declarative part still decleared even if the if-generate expression is false?
05-08-2019 11:30 AM - edited 05-08-2019 11:30 AM
Yes, I believe that it does what it says (tries to assign -2 to natural). However I didn't understand how it can result in a value of -2 if stage is never 0, but I think I found my mistake. I was focused on the wrong end of the for-generate index array. As I said the comp_count is actually values of triangle waveform so after 4 it starts decreasing and in the other end it results -2 because stage keeps increasing. Silly mistake.
Can you please explain why " repeating the same variable for every interation of the generate seems suspect."? The value isn't same for each iteration, but it changes over each iteration.
05-08-2019 10:51 AM - edited 05-08-2019 10:52 AM
I only glanced at this... but isn't it just complaining that you are trying to put a negative value in a natural (e.g is ((stage-1)/2) is ever less than comp_count would ever result in a negative number, it would be out of range for a natural... (and it thinks it does as it shows -2 as the result)
Secondarily... repeating the same variable for every interation of the generate seems suspect.
Hope that Helps
If so, Please mark as solution accepted. Kudos also welcomed. :-)
05-08-2019 11:30 AM - edited 05-08-2019 11:30 AM
Yes, I believe that it does what it says (tries to assign -2 to natural). However I didn't understand how it can result in a value of -2 if stage is never 0, but I think I found my mistake. I was focused on the wrong end of the for-generate index array. As I said the comp_count is actually values of triangle waveform so after 4 it starts decreasing and in the other end it results -2 because stage keeps increasing. Silly mistake.
Can you please explain why " repeating the same variable for every interation of the generate seems suspect."? The value isn't same for each iteration, but it changes over each iteration.
05-08-2019 11:38 AM
Good, I am glad you resolved it.
As for the 'suspect' ... as long as you know the 'generate' keyword is 'replicating' logic... not a runtime loop, then you are good to go...
e.g. if something like
const X : integer := 1;
const X : integer := 2;
const X : integer := 3;
...
would be invalid then it would be suspect
Hope that Helps
If so, Please mark as solution accepted. Kudos also welcomed. :-)
05-08-2019 01:13 PM
I see, thank you for explaining.