gpt4 book ai didi

interface - 使用接口(interface)宽度和 $size 自动 SystemVerilog 可变大小?

转载 作者:行者123 更新时间:2023-12-02 11:29:26 24 4
gpt4 key购买 nike

我正在尝试在 SystemVerilog 中制作一个具有标准化内存接口(interface)的模块(在我的例子中是 DSP),并且希望模块中的变量根据附加接口(interface)中的总线宽度自动调整大小。我的理由是:这使得代码更加可移植,允许它自动调整大小以适合任何连接的接口(interface),而不是要求 HDL 编码器传递参数来告诉模块将连接到它的所有接口(interface)总线的宽度(不是那个)这太糟糕了,如果没有参数,它看起来会更干净)。

但是,我似乎无法让它发挥作用。这是一个说明问题的例子;以下在 Quartus II 12.1 中综合:

// 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) 有效非常适合设置 auto_sized1 的宽度。

有什么想法吗?再说一遍,这对于项目的成功并不重要,我此时主要是好奇!

谢谢-

最佳答案

看起来像是一个编译器错误。我可能会在接口(interface)定义中使用参数。

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

关于interface - 使用接口(interface)宽度和 $size 自动 SystemVerilog 可变大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14307306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com