配置如下
reg [3:0] myreg;
always@(...) begin
...
if(myreg) begin <events> end ...
end
如何在不引用打包数组中的位之间的特定位和逻辑运算的情况下如何引用“myreg”?
编辑:请您提供您解释的这种行为记录在哪里?由于允许这种语义结构,我想应该有一些关于它的文档......谢谢!
编辑1:到目前为止,感谢您的所有答案。让我们重新关注以下两点:
是的,@ Morgan是正确的Xillinx ISE和Questasim正在做同样的事情,当我合成以下代码时。
module aa( input clk,
input rst_n,
input [4:0] my_reg,
output reg chk
);
always @ (posedge clk or negedge rst_n)
begin
if (!rst_n) begin
chk <= 1'bz;
end else begin
if (my_reg) begin
chk <= 1'b1;
end
else begin
chk <= 1'b0;
end
end
end
endmodule
Verilog应该像这样:
myreg | result | comment
------|--------|--------
0000 | 1'b0 | FALSE - all bit bits are zero
0010 | 1'b1 | TRUE - at least one bit is one
001X | 1'b1 | TRUE - at least one bit is one
000X | 1'bX | FALSE - we don't know whether all bits are zero or not
and if interprets 1'bX as FALSE
从这个EDA Playground example VCS 2014.2解释:
if (myreg) begin
...
作为myreg的OR位减少,即:
if ( |myreg == 1'b1) begin
...
正如Greg发现LRM的相关(SystemVerilog IEEE 1800-2012标准)部分是第12.4节
它的计算结果为false(即,值为零或值为x或z),
提供的代码if (myreg)
是有效的,但是如果使用未初始化的寄存器,则x或z将评估为假而不是传播x,您可能会发现RTL和门级仿真之间存在差异,初始x将评估为false而不是可能为1并评估为真。
根据if(myreg)
§12.4条件if-else语句,if(myreg != 0)
与IEEE Std 1800-2012相同
条件语句(或if-else语句)用于决定是否执行语句。形式上,语法在语法12-2中给出。
conditional_statement ::= // from A.6.6 [ unique_priority ] if ( cond_predicate ) statement_or_null { else if ( cond_predicate ) statement_or_null } [ else statement_or_null ] unique_priority ::= unique | unique0 | priority cond_predicate ::= expression_or_cond_pattern { &&& expression_or_cond_pattern } expression_or_cond_pattern ::= expression | cond_pattern cond_pattern ::= expression matches pattern语法12-2-if-else语句的语法(摘自附件A) 如果cond_predicate表达式求值为true(即,具有非零已知值),则应执行第一个语句。如果它的计算结果为false(即,值为零或值为x或z),则不应执行第一个语句。如果存在else语句且cond_predicate表达式为false,则应执行else语句。因为if表达式的数值被测试为零,所以某些快捷方式是可能的。例如,以下两个语句表达相同的逻辑:
if(expression) if(expression != 0)
请注意,LRM正在检查表达式是否为非零值。它不限制宽度,甚至不考虑它是否为有符号类型。负数将是真的,只有零是错误的。
合成器可以进行逐位压缩,这与零相比是等效的逻辑。