首页 > 解决方案 > SystemVerilog:在界面数组上折叠和&...折叠或| 在接口数组上

问题描述

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

我还没有弄清楚的一个逻辑操作是折叠 & 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) 部分选择后的选定名称可能只是接口端口上的 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

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

标签: verilogsystem-verilogvivadoquestasim

解决方案


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

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

推荐阅读