我有一个输入,其宽度我想在精化时确定。我不想提供两个参数,而是想确定从单个参数派生的宽度。事情是这样的:SystemVerilog:从参数
module my_module #(
COUNT = 9
) (
[bitwidth(COUNT)-1:0] index
);
我有这对我来说,如果我宣布一个reg内到我的模块但我需要这通过外部端口映射驱动工作的功能。
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;
我该如何做到这一点?我可以利用一个接口(+ modports)来获得我想要的吗?
你在想的。['$ bits'或'$ size'(http://www.asic-world.com/systemverilog/system_task_function3.html)? –
'$ clog2':IEEE标准1800-2012,章节“20.8.1整数学函数” – toolic
'$ bits'将会是合适的,但是当我替换'bitwidth'时,ModelSim告诉我“范围必须以常量表达式为界”。 – hancock