It is possible to use unlimited arrays.
Unfortunately, SystemVerilog does not have decent support for unlimited arrays. It seems that LRM is equated with unlimited dynamics, which suggests that it is almost impossible to create something synthesized. VHDL has unlimited arrays that are supported by tools and incredibly useful, so it is unfortunate that SystemVerilog did not enable this feature properly.
Here is an example:
function automatic logic parity(input logic data[]); logic p = 0; for (int i=0; i<data.size(); i++) p ^= data[i]; return p; //return = ^data; <--- not allowd on unpacked arrays? endfunction logic [7:0] data_in; logic result; logic data_in_unpacked [] = new[$bits(data_in)]; always_comb begin // Convert to unpacked array (better way to do this?) for (int i=0; i<$bits(data_in); i++) data_in_unpacked[i] = data_in[i]; result = parity(data_in_unpacked); end
It works on Modelsim on EDAPlayground here: http://www.edaplayground.com/x/3tS
EDIT 1: updated the code - I just realized that you can call new[] on initialization and thus statically, so in theory synthesis tools can support this. It would be interesting to synthesize this and see ...
EDIT 2: I think that I will try to synthesize and not surprisingly, Quartus does not like:
Error (10170): Verilog HDL syntax error when testing .sv (10) next to the text "]"; waiting for the operand
Error (10170): Verilog HDL syntax error when testing .sv (18) next to the text "]"; waiting for the operand
Error (10112): Ignored "my_parity" design block when testing .sv (2) due to previous errors
Chiggs
source share