system-verilog - 两个不同向量宽度的逻辑相等

标签 system-verilog vivado

为什么两个不同宽度的向量的逻辑相等会产生如下输出?

module eq_test;

logic check;
logic [3:0] cmp_0;
logic       cmp_1 = 1'b0;

initial begin
    for (int i = 0; i < 16; i++) begin
        cmp_0 = i;
        check = (cmp_0 == cmp_1);
        $display("%b == %b is %b", cmp_0, cmp_1, check);
    end
end

endmodule

使用 Vivado 模拟器

0000 == 0 is 1
0001 == 0 is 0
0010 == 0 is 0
0011 == 0 is 0
0100 == 0 is 0
0101 == 0 is 0
0110 == 0 is 0
0111 == 0 is 0
1000 == 0 is 0
1001 == 0 is 0
1010 == 0 is 0
1011 == 0 is 0
1100 == 0 is 0
1101 == 0 is 0
1110 == 0 is 0
1111 == 0 is 0

我可以假设宽度较小的变量cmp_1被扩展(无符号扩展)为较大的变量宽度cmp_0,是这样吗?

最佳答案

是的,宽度较小的变量会扩展到宽度较大的变量。

IEEE Std 1800-2017 第 11.6.1 节对此进行了描述表达式位长度的规则

The number of bits of an expression (known as the size of the expression) shall be determined by the operands involved in the expression and the context in which the expression is given.

在表 11-21 中,== 运算符有以下注释:

Operands are sized to max(L(i),L(j))

其中ij表示操作数的表达式,L(i)表示所表示的操作数的位长度>我

这对于所有模拟器都是如此,而不仅仅是 Vivado。

关于system-verilog - 两个不同向量宽度的逻辑相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71051611/

相关文章:

fpga - 比特流加密

verilog - 仿真结果与综合原理图不匹配

Verilog 在不改变内部状态的情况下对模块输出施加力

verilog - 上升沿检测 sysverilog

header - SystemC 和 Verilog 之间的通用头文件

verilog - 在 Verilog 中调用模块

vhdl - 向 Vivado 2014.4 添加库

verilog - systemverilog 中逻辑语句的非常量索引

fopen - 我怎么知道我在系统verilog中的当前路径?

algorithm - 询问带IP核的FPGA设计