mrflibble
Advanced Member level 5
Is there any way in verilog to specify a function such that it can take between 0 and lets say 8 arguments?
The arguments are all integers between 0 and 255.
The function will output a 256 bit wide constant.
I can make a function just fine that takes a FIXED number of 8 arguments, and then pad the unused arguments with "0" dummy values. But that's a bit ugly. Is there any better way?
So what I have now is a function where I can call like this:
What I would like:
So this function should work for any combination of 0 to 8 arguments values. But I can only get things to work for a FIXED number of argument values. Hence the best I could do so far is just pass a fix number of 8 arguments, and any non-used argument gets a dummy value (in this case 0).
Any better options?
No system verilog please. XST 13.2 from xilinx takes verilog-2001 just fine, but that's about it.
Thanks for any solutions.
The arguments are all integers between 0 and 255.
The function will output a 256 bit wide constant.
I can make a function just fine that takes a FIXED number of 8 arguments, and then pad the unused arguments with "0" dummy values. But that's a bit ugly. Is there any better way?
So what I have now is a function where I can call like this:
Code:
localparam EXAMPLE_0 = working_fun(0, 0, 0, 0, 0, 0, 0, 0); // works
localparam EXAMPLE_3 = working_fun(3, 42, 99, 0, 0, 0, 0, 0); // works
localparam EXAMPLE_7 = working_fun(3, 42, 99, 100, 101, 199, 240, 242, 0); // works
// with 8 arguments it's obviously the same
Code:
localparam EXAMPLE_0 = wanted_fun(); // what I would like
localparam EXAMPLE_3 = wanted_fun(3, 42, 99); // what I would like
localparam EXAMPLE_7 = wanted_fun(3, 42, 99, 100, 101, 199, 240, 242); // what I would like
// with 8 arguments it's obviously the same
So this function should work for any combination of 0 to 8 arguments values. But I can only get things to work for a FIXED number of argument values. Hence the best I could do so far is just pass a fix number of 8 arguments, and any non-used argument gets a dummy value (in this case 0).
Any better options?
No system verilog please. XST 13.2 from xilinx takes verilog-2001 just fine, but that's about it.
Thanks for any solutions.