I have an issue when converting a SystemVerilog file to Verilog-2001 file coming from a GitHub project. It seems that in Verilog-2001, it not possible to place an unrolled loop of a table within a function:
function [31:0] gen_val;
input [31:0] old_val;
input [31:0] new_val;
input [3:0] be;
integer n;
for (n = 0 ; n < 4 ; n = n + 1)
gen_val[n*8+8:n*8] = be[n] ? new_val[n*8+8:n*8] : old_val[n*8+8:n*8];
endfunction
When compiling with Icarus Verilog (iverilog) I get multiple error messages:
./tb_tiny.v:39: error: A reference to a wire or reg (`n') is not allowed in a constant expression.
./tb_tiny.v:39: error: Part select expressions must be constant.
./tb_tiny.v:39: : This lsb expression violates the rule: (n)*('sd8)
./tb_tiny.v:39: error: A reference to a wire or reg (`n') is not allowed in a constant expression.
./tb_tiny.v:39: error: Part select expressions must be constant.
./tb_tiny.v:39: : This msb expression violates the rule: ((n)*('sd8))+('sd8)
.....
Would anyone have an idea about the way to fix this in Verilog-2001 ?
Regards