使用接口宽度和$ size自动调整SystemVerilog的大小?

Mar*_*tin 5 size interface parameterized system-verilog

我正在尝试使用SystemVerilog中的标准化存储器接口制作一个模块(在我的情况下是一个DSP),并希望模块中的变量根据所连接接口中的总线宽度自动调整大小.我的理由:这使得代码更容易移植,允许它自动调整到任何连接的接口,而不是要求HDL编码器传递参数,告诉模块将连接到它的所有接口总线的宽度(不是这将是可怕的,没有参数,它似乎更清洁).

但是,我似乎无法让它工作.这是一个说明问题的例子; 以下在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
Run Code Online (Sandbox Code Playgroud)

请注意,width2最终会得到正确的值(9) - 它太晚才能正确设置宽度auto_sized2.我最初认为$size只是在为所有变量分配了它们的宽度之后才进行评估,但这似乎并非如此,因为它$size(data_in)可以很好地设置宽度auto_sized1.

有什么想法吗?同样,这对项目的成功并不重要,我现在对此非常好奇!

谢谢 -

小智 3

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

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
Run Code Online (Sandbox Code Playgroud)