SystemVerilog:在接口数组上折叠和& ...折叠或|在接口数组上

SystemVerilog: Collapsing and & on an array of interface ... Collapsing or | on an array of interface

我正在尝试彻底更改我的一些代码。我在模块端口签名中使用广泛使用的结构的任何地方,我都想用接口替换(如果合适的话)。

我还没有弄清楚的一个逻辑运算是折叠 & or 和折叠 or。

使用规则的位向量很容易做到这一点: 在模块的某个地方,我可以很容易地执行折叠 & 和 |

logic [31:0] vect ;
logic my_sig_and ;
logic my_sig_or ;

always_comb begin
  my_sig_and = &vect ;
  my_sig_or = |vect ;
end

但是,我的问题是,如何跨接口数组对单个位字段执行此操作

我的尝试如下(即使是愚蠢的尝试):

interface myInterface () () ;
    logic valid
    logic[31:0] data
endinterface

尝试 #1:

我在模块某处的尝试:

myInterface () my_intfs [PORTS-1:0] () ; // assume this is assigned to
logic temp_signal ;
logic my_sig_and ;

always_comb begin
    temp_signal = my_intfs[0].ready ;
    for( genvar ii = 1; ii < PORTS; ii++ ) begin
        temp_signal = temp_signal && my_intfs[ii].ready ; // error line
    end
end

always_comb begin
    my_sig_and = temp_signal;
end

错误:“genvar”附近:语法错误,意外的 genvar,需要“;”。

尝试 #2:

我在模块某处的尝试:

myInterface () my_intfs [PORTS-1:0] () ; // assume this is assigned to
logic temp_signal ;
logic my_sig_and ;

always_comb begin
    temp_signal = my_intfs[0].ready ;
    for( int ii = 1; ii < PORTS; ii++ ) begin
        temp_signal = temp_signal && my_intfs[ii].ready ; // error line
    end
end

always_comb begin
    my_sig_and = temp_signal;
end

错误:实例数组的非常量索引 'my_intfs'

尝试 #3:

我在模块某处的尝试:

myInterface () my_intfs [PORTS-1:0] () ; // assume this is assigned to
logic temp_signal ;
logic my_sig_and ;

always_comb begin
    temp_signal = my_intfs[0].ready ;
    for( int ii = 1; ii < PORTS; ii++ ) begin
        temp_signal = temp_signal && my_intfs[ii+:0].ready ; // error line
    end
end

always_comb begin
    my_sig_and = temp_signal;
end

(vlog-13172) 部分后选择的名称-select 可能只是接口端口上的 modport。

尝试 #4:

我在模块某处的尝试:

myInterface () my_intfs [PORTS-1:0] () ; // assume this is assigned to
logic temp_signal ;
logic my_sig_and ;

always_comb begin
    temp_signal = my_intfs[0].ready ;
end

for( genvar ii = 1; ii < PORTS; ii++ ) begin
    always_comb begin
        temp_signal = temp_signal && my_intfs[ii].ready ; // error line
    end
end

always_comb begin
    my_sig_and = temp_signal;
end

(vopt-7033) 变量 'temp_signal' 在组合块中驱动,不能由任何其他进程驱动

尝试 #5:

我在模块某处的尝试:

myInterface () my_intfs [PORTS-1:0] () ; // assume this is assigned to
logic temp_signal ;
logic my_sig_and ;

for( genvar ii = 0; ii < PORTS; ii++ ) begin
    always_comb begin
        temp_signal = temp_signal && my_intfs[ii].ready ; // error line
    end
end

always_comb begin
    my_sig_and = temp_signal;
end

(vopt-7033) 变量 'temp_signal' 在组合块中驱动,不能由任何其他进程驱动。

尝试 #6:

我在模块某处的尝试:

myInterface () my_intfs [PORTS-1:0] () ; // assume this is assigned to
logic temp_signal ;
logic my_sig_and ;

always_comb begin
    temp_signal = &my_intfs.ready ; // error line
end

always_comb begin
    my_sig_and = temp_signal;
end

(vopt-2990) 对解压类型的非法操作。

尝试 #7(愚蠢但值得哈哈):

我在模块某处的尝试:

myInterface () my_intfs [PORTS-1:0] () ; // assume this is assigned to
logic temp_signal ;
logic my_sig_and ;

always_comb begin
    temp_signal = my_intfs.&ready ; // error line
end

always_comb begin
    my_sig_and = temp_signal;
end

“&”附近:语法错误,意外的“&”

尝试 #8 来自 bash/sh 的一些语法,用 @ 引用整个数组(愚蠢但需要哈哈):

我在模块某处的尝试:

myInterface () my_intfs [PORTS-1:0] () ; // assume this is assigned to
logic temp_signal ;
logic my_sig_and ;

always_comb begin
    temp_signal = &my_intfs[@].ready ; // error line
end

always_comb begin
    my_sig_and = temp_signal;
end

“@”附近:语法错误,意外的“@”。

使用将所有接口数组元素分配给占位符逻辑向量的宏有效。在所有赋值完成后简单地折叠逻辑向量。:

somewhere in a module:
myInterface () my_intfs [PORTS-1:0] () ; // assume this is assigned to
logic temp_signal ;
logic my_sig_and ;

`INTF_FIELD_COLLAPSE_AND( blah, my_intfs, valid, PORTS, 1, my_sig_and )


`ifndef INTF_FIELD_COLLAPSE_AND
    `define INTF_FIELD_COLLAPSE_AND( unique, intf, field, size, field_size, output_sig ) \
        logic [size-1:0] [field_size-1:0] my_sig_unique ; \
        for( genvar ii_unique = 0; ii_unique < PORTS; ii_unique++ ) begin \
            always_comb begin \
                my_sig_unique[ii_unique] = intf[ii_unique].field ; \
            end \
        end \
        output_sig = &my_sig_unique ;
`endif

您不能像访问普通位数组那样访问(接口或模块)实例数组。由于潜在参数会覆盖接口端口连接,因此必须使用常量独立访问每个实例。

你应该做的是将接口信号数组分别创建一个本地打包数组,然后你可以对本地数组进行操作。

myInterface my_intfs [PORTS-1:0] () ; 

logic [PORTS-1:0] local_ready;

for(genvar i=0;i<PORTS;i++)
   assign local_ready[i] = my_intfs[i].ready;

assign my_sig_and = &local_ready;