With ncsim the following code throws the error:
Bit-select or part-select index out of declared bounds.
However, the commented out code which does exactly the same thing doesn't. Am I missing something or is the compiler mistaken?
module pd__test;
genvar i, j;
reg [10-1:0] assign_from_reg;
reg [256:0] assign_to_reg;
generate
for (i=0; i<2; i=i+1) begin
for (j=0; j<13; j=j+1) begin
always @* begin
if (i+2*j < 25) begin
// gives me an index out of bounds error
assign_to_reg[10*(i+2*j)+9 : 10*(i+2*j)] = assign_from_reg;
// gives me no such error, however the indices are the same
// assign_to_reg[10*(i+2*j)+9 -: 10] = assign_from_reg;
end else begin
// do something else
end
end
end
end
endgenerate
endmodule
I ran a python script to print the indeces to double check:
for i in range(2):
for j in range(13):
if (i+(2*j) < 25):
print("[", 10*(i+(2*j))+9, ":", 10*(i+(2*j)), "]")
Prints:
[ 9 : 0 ]
[ 29 : 20 ]
[ 49 : 40 ]
[ 69 : 60 ]
[ 89 : 80 ]
[ 109 : 100 ]
[ 129 : 120 ]
[ 149 : 140 ]
[ 169 : 160 ]
[ 189 : 180 ]
[ 209 : 200 ]
[ 229 : 220 ]
[ 249 : 240 ]
[ 19 : 10 ]
[ 39 : 30 ]
[ 59 : 50 ]
[ 79 : 70 ]
[ 99 : 90 ]
[ 119 : 110 ]
[ 139 : 130 ]
[ 159 : 150 ]
[ 179 : 170 ]
[ 199 : 190 ]
[ 219 : 210 ]
[ 239 : 230 ]