verilog - 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
“@”附近:语法错误,意外的“@”。
解决方案
使用将所有接口数组元素分配给占位符逻辑向量的宏有效。在所有分配完成后简单地折叠逻辑向量。:
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
推荐阅读
- c# - 如何在 ASP.NET Core 3 上同时使用 Azure AD 身份验证和身份?
- qaf - com.qmetry.qaf.automation.step.client.ScenarioFactory.getTestsFromFile() 抛出异常
- python - Bash 中有没有办法确定字符串中是否存在字符?
- r - 将 P 值添加到组箱线图中的比较
- php - SQL - 结合两个具有不同 WHERE 原因的 COUNT 和 GROUP BY 用户名
- google-calendar-api - Google 日历重复活动的结束日期错误
- google-chrome - 如何将 cookie 从请求标头匹配到文件
- python-3.x - 如何让字典迭代更快
- reactive-programming - Reactive 越多越好吗?
- android - 从 Google Play 商店获取已发布应用的列表