systemverilog使用数组作为模块/函数的端口

问题描述 投票:-1回答:2
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;

我知道在端口列表中使用数组只在systemverilog中支持,而不是verilog。为了使其更具可读性,我想明确显示范围,但这是非法的。功能也会出现同样的问题。我怎么解决这个问题?

system-verilog
2个回答
1
投票

SystemVerilog语法不允许您指定多个范围,该范围必须是最右侧选定的维度。

如果你想要明确,请创建一个typedef并使用强制转换。使用typedef也是一种更好的编程习惯,而不是在代码中散布任意数字。

typedef logic [2:0] blue_port_t[4:1];
typedef logic [0:2] green_port_t[0:3];

module hh ( input green_port_t a, output wire b );

wire blue_port_t c1;
wire green_port_t c2;
wire d;

u_hh_1 hh ( .a(c1          ), .b(d) ); // 
u_hh_2 hh ( .a(blue_port_t'(c1)), .b(d) ); //
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(green_port_t'(c2)), .b(d) ); 

除了记录使用的类型之外,演员不会做任何其他事情。


0
投票

在Verilog中,你应该尝试让你的向量从MS到LS最好以0结尾。这是一个让其他Verilog编码器更容易阅读它的约定。 同样的惯例:记忆应该采用相反的方式:LS从MS开始为零。 (但我已经看到很多代码并非如此。如果你这样做,有些模拟器会发出警告)。

wire [2:0] c1 [0:3];
wire [2:0] c2 [0:3];

如果您希望代码是可合成的,则可以使用二维切片,但索引为[memory_address] [bit-slice]位切片是可选的。如果省略,则获得整个条目。这样你就可以做到:

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]

这是合乎逻辑的,因为它将同时选择存储器的前两个条目,这是任何标准硬件都不支持的。

© www.soinside.com 2019 - 2024. All rights reserved.