Interface 使用接口宽度和$size的自动SystemVerilog变量大小?
我正在尝试在SystemVerilog中制作一个具有标准化内存接口的模块(在我的例子中是一个DSP),并希望模块中的变量根据连接接口中的总线宽度自动调整大小。我的理由是:通过允许代码自动调整到任何连接接口的大小,这使得代码更具可移植性,而不是要求HDL编码器传入参数,告诉模块将连接到它的所有接口总线的宽度(并不是说这会很糟糕,只是没有参数看起来更干净) 然而,我似乎无法让它发挥作用。这里有一个例子说明了这个问题;以下内容在Quartus II 12.1中进行了综合:Interface 使用接口宽度和$size的自动SystemVerilog变量大小?,interface,size,parameterized,system-verilog,Interface,Size,Parameterized,System Verilog,我正在尝试在SystemVerilog中制作一个具有标准化内存接口的模块(在我的例子中是一个DSP),并希望模块中的变量根据连接接口中的总线宽度自动调整大小。我的理由是:通过允许代码自动调整到任何连接接口的大小,这使得代码更具可移植性,而不是要求HDL编码器传入参数,告诉模块将连接到它的所有接口总线的宽度(并不是说这会很糟糕,只是没有参数看起来更干净) 然而,我似乎无法让它发挥作用。这里有一个例子说明了这个问题;以下内容在Quartus II 12.1中进行了综合: // Top level m
// Top level module with some 15-bit ports
module top ( input [14:0] data_in,
output [14:0] data_out1, data_out2,
data_out3, data_out4 );
test_interface my_interface(); // Initialize the interface
test_module my_module(.*); // Initialize & connect module
endmodule
// Define a simple interface:
interface test_interface ();
logic [8:0] my_port;
endinterface
// Define the module:
module test_module ( input [14:0] data_in,
test_interface my_interface,
output [14:0] data_out1, data_out2,
data_out3, data_out4 );
localparam width1 = $size(data_in); // should be 15
localparam width2 = $size(my_interface.my_port); // should be 9
logic [width1-1:0] auto_sized1; // gets correct size (14:0)
logic [width2-1:0] auto_sized2; // **PROBLEM**: gets size of 0:0!
always_comb begin
auto_sized1 = 5; // ok
auto_sized2 = 5; // problem; value now truncated to 1
data_out1 = data_in + width1; // Yields data_in + 15 (ok)
data_out2 = data_in + width2; // Yields data_in + 9 (ok...!)
data_out3 = data_in + auto_sized1; // Yields data_in + 5 (ok)
data_out4 = data_in + auto_sized2; // Yields data_in + 1 (problem)
end
endmodule
请注意,width2
最终会得到正确的值(9)-对于它来说,正确设置auto_sized2
的宽度为时已晚。我最初认为,$size
只是在所有变量都分配了宽度之后才进行计算,但情况似乎也并非如此,因为$size(data_in)
对于设置自动大小1
的宽度来说效果很好
有什么想法吗?再说一次,这对项目的成功并不重要,我对这一点很好奇
谢谢-看起来像个编译器错误。我可能会在接口定义中使用参数
module top ( input [14:0] data_in,
output [14:0] data_out1, data_out2,
data_out3, data_out4 );
test_interface #(.port_size(8)) my_interface(); // Initialize the interface
test_module my_module(.*); // Initialize & connect module
endmodule
interface test_interface ();
parameter port_size = 1;
logic [port_size-1:0] my_port;
endinterface
module test_module ( input [14:0] data_in,
test_interface my_interface,
output [14:0] data_out1, data_out2,
data_out3, data_out4 );
localparam width1 = $size(data_in);
localparam width2 = my_interface.port_size;
endmodule
同意Adam的回答,看起来像个编译器错误。您的原始代码可以与Incisive和Questa一起正常工作。感谢您查看它,@dwinkle-很高兴知道代码本身没有问题。感谢您的快速回复!是的,如果它是一个编译器错误(看起来确实如此),那么最好使用参数来解决它。