Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
1,902 Views

Parametrically sized localparam assignment

I would like to be able to assign an array of localparams with some kind of static function. For example I don't want to have to do this: 

 

localparam SIZE = 3; typedef logic bar_t; localparam bar_t FOO = {32'd1, 32'd2, 32'd3};  

 

Because, while this works, it isn't fully parametric. I'd like to be able to do something like: 

 

localparam SIZE = 3; typedef logic bar_t; function makeFoo (input integer size); bar_t bar; integer i; for (i = 0; i < size; i++) begin bar = i; end return bar; endfunction localparam bar_t FOO = makeFoo(SIZE);  

 

Unfortunately, size inside of makeFoo isn't static (or at least Modelsim says it isn't). 

 

Anyway, I'm wondering if anyone has a way to do this. I use static functions all the time to define simple localparam types, but this is proving more difficult. 

 

Thanks, 

Todd
0 Kudos
4 Replies
Highlighted
Valued Contributor III
93 Views

So, to answer my own question, this appears to work, while not entirely elegant: 

 

`define MAX_BAR 128 typedef logic bar_t; function bar_t makeFoo (input integer x); bar_t bar; integer i; for (i = 0; i < x; i++) begin bar = i + 1; end return bar; endfunction . . . localparam bar_t FOO = makeFoo(SIZE);  

 

I'd like to be able to size everything only as large as I need it. But for static analysis, it's probably sufficient for most uses to set an upper bound like this. 

 

Again, if anyone has a cleaner way to do this, I'd be interested to see it.
0 Kudos
Highlighted
Valued Contributor III
93 Views

Try this: 

 

module top; localparam SIZE = 3; typedef logic bar_t; typedef bar_t foo_t; function foo_t makeFoo; for(int i=0;i<$size(makeFoo);i++) makeFoo = i; endfunction localparam foo_t FOO = makeFoo; initial $display("%p",FOO); endmodule
0 Kudos
Highlighted
Valued Contributor III
93 Views

Thanks for the response. I tried your suggestion and I get this from Modelsim: 

 

** Error: /some/file.sv(427): (vlog-2118) The function 'makeFoo' is not a valid constant function. ** Error: /some/file.sv(427): Parameter value must be constant.  

 

I'm currently running: 

Model Technology ModelSim DE vsim 10.1 Simulator 2011.12 Dec 5 2011 

which is clearly a bit old, so I'm not sure if that's part of the problem. I know that Modelsim (along with Quartus) does multi-pass static elaboration, but apparently it's having a problem with that here.
0 Kudos
Highlighted
Valued Contributor III
93 Views

You will have to show more code. The example I showed above works in ModelSim 10.1. It works all the way back to ModelSim 6.3 if you add ()'s to FOO = makeFoo();

0 Kudos