System verilog systemverilog使用阵列作为模块/函数的端口
我知道只有systemverilog支持在端口列表中使用数组,而不是verilog。为了使其更具可读性,我希望显式显示范围,但这是非法的。函数也会出现同样的问题。如何解决此问题?SystemVerilog语法不允许您指定多个范围,该范围必须是最右边的选定维度 如果您希望明确,请创建System verilog systemverilog使用阵列作为模块/函数的端口,system-verilog,System Verilog,我知道只有systemverilog支持在端口列表中使用数组,而不是verilog。为了使其更具可读性,我希望显式显示范围,但这是非法的。函数也会出现同样的问题。如何解决此问题?SystemVerilog语法不允许您指定多个范围,该范围必须是最右边的选定维度 如果您希望明确,请创建typedef并使用强制转换。使用typedef也是一种更好的编程实践,而不是在代码中散布任意数字 module hh ( input [2:0] a [0:3], output b ); wire [2:0] c1
typedef
并使用强制转换。使用typedef也是一种更好的编程实践,而不是在代码中散布任意数字
module hh ( input [2:0] a [0:3], output b );
wire [2:0] c1 [4:1];
wire [0:2] c2 [0:3];
wire d;
u_hh_1 hh ( .a(c1 ), .b(d) ); // it is right;
u_hh_2 hh ( .a(c1[4:1][2:0]), .b(d) ); // illegal slice name;
u_hh_3 hh ( .a(c2 ), .b(d) ); // it is right,
// and in the netlist,
// the bits of c2 is swapped to a;
u_hh_4 hh ( .a(c2[0:3][2:0]), .b(d) ); // illegal slice name;
强制转换除了记录正在使用的类型外,不执行任何操作。在Verilog中,您应该尝试使向量从MS变为LS,最好以0结尾。这是一个惯例,使得其他Verilog程序员更容易阅读它
同样的惯例:记忆应该走相反的方向:从LS到MS,从零开始。(但我看到很多代码都不是这样的。如果您这样做,一些模拟器会发出警告) 如果希望代码能够合成,可以使用二维切片,但索引是[内存地址][位切片],位切片是可选的。如果省略了它,您将获得整个条目。 因此,您可以:
wire [2:0] c1 [0:3];
wire [2:0] c2 [0:3];
你永远无法做到:
c1[1][1:0] // LS 2 bits of second entry of memory c1
c1[0] // First memory entry of c1 which is 3 bits wide
这是合乎逻辑的,因为它会同时选择内存的前两个条目,这是任何标准硬件都不支持的
c1[1][1:0] // LS 2 bits of second entry of memory c1
c1[0] // First memory entry of c1 which is 3 bits wide
c1[1:0]