verilog - 模块输入的宽度可以在模块内部确定吗?
问题描述
在 SystemVerilog IEEE Std 1800-2017 第 328 页中,显示了以下示例:
module ram_model (address, write, chip_select, data);
parameter data_width = 8;
parameter ram_depth = 256;
localparam addr_width = clogb2(ram_depth);
input [addr_width - 1:0] address;
input write, chip_select;
inout [data_width - 1:0] data;
//define the clogb2 function
function integer clogb2 (input [31:0] value);
value = value - 1;
for (clogb2 = 0; value > 0; clogb2 = clogb2 + 1)
value = value >> 1;
endfunction
logic [data_width - 1:0] data_store[0:ram_depth - 1];
//the rest of the ram model
endmodule: ram_model
由模块内部函数的输出“addr_width”确定的“地址”输入宽度有什么意义?
解决方案
该代码来自第 13.4.3 节常量函数。
这里的关键是clogb2
满足成为常数函数的所有标准。正如 Std 所述,常量函数调用在细化时进行评估。由于这发生在运行时之前,因此返回的值被视为常量。
并非所有功能都可以这种方式使用。
另请参阅 IEEE Std 1800-2017,第 23.10.4 节细化注意事项,以进一步讨论细化时间。
推荐阅读
- sql - 当天获取最新状态
- reactjs - Flask MongoEngine 动态 ORM
- python - 带有 QStandardItemModel 的 item.setData 触发了段错误
- mysql - 在数据库中缓存大型数据框
- sql-server - 为 AD 用户运行带有 -E 选项的 SQLCMD 时失败
- kubernetes - Kubernetes hpa cpu 利用率
- vba - 如何使用 XMLHTTP60 对象从 VBA 中的重定向 URI 获取授权码值?
- android - for 语句在 while 语句结束之前返回
- cloud - ICP4D(IBM Cloud Pak for Data)也可以用作数据质量工具吗?
- javascript - 是否可以从 javascript 中的“构造函数”调用类方法?