I have an input whose width I want to determine at elaboration time. Instead of feeding two parameters I want to determine the width derived from a single parameter. Something like this:
module my_module #(
COUNT = 9
) (
[bitwidth(COUNT)-1:0] index
);
I have a function which works for me if I declare a reg internal to my module but I need this to be driven externally via the port map.
function integer bitwidth;
input integer n;
integer exp2, width;
begin
width=1;
for (exp2=1; exp2<<1 <= n; exp2=exp2<<1)
width=width+1;
bitwidth = width;
end
endfunction
reg [bitwidth(COUNT)-1:0] this_works = COUNT;
How do I accomplish this? Can I utilize an interface (+modports) to get me what I want?
$bitsor$size? - Ross Rogers$bitswould be appropriate but when I replacebitwidthModelSim tells me "Range must be bounded by constant expressions". - hancock$clog2does it. Not sure why it doesn't like$bits. - hancock