Verilog 中的常量填充
Constant padding in Verilog
这是相关的示例行为 Verilog 代码
module constant;
reg [7:0] foo;
initial begin
foo = 1'bz;
$display("%H", foo);
end
endmodule
Icarus Verilog 给了我
$ iverilog -o constant constant.v
$ ./constant
0Z
然而,根据this website(以及我正在上的 FPGA 课程的讲师),
If number is smaller than the size constant, then it will be padded to the left with zeros. If the most significant bit of a specified number has an unknown (x) or high-impedance (z) value, then that value will be used to pad to the left.
在那种情况下,输出应该是 ZZ
而不是 0Z
。我很确定这是由于规范的更改(可能是 Verilog 1995 中的 ZZ
和 Verilog 2001 中的 0Z
或其他),但导致每种行为的标准是什么?我试过在线搜索规范,但它们似乎不是免费提供的,例如 this one 需要购买或订阅。
作为奖励,我在哪里可以找到 Verilog 各种规范的变化摘要?
SystemVerilog IEEE 1800-2017 说:
If the size of the unsigned number is smaller than the size specified for the literal constant, the unsigned number shall be padded to the left with zeros. If the leftmost bit in the unsigned number is an x or a z, then an x or a z shall be used to pad to the left, respectively. If the size of the unsigned number is larger than the size specified for the literal constant, the unsigned number shall be truncated from the left.
但是,这里的数字不小于大小常量——这里的大小是1'bz中的“1”。
对于表达式结果的转换,标准是这样说的:
Automatic type conversions from a smaller number of bits to a larger number of bits involve zero extensions if unsigned or sign extensions if signed. Automatic type conversions from a larger number of bits to asmaller number of bits involve truncations of the most significant bits (MSBs).
因为这是一个无符号表达式和结果,所以 1'bz 文字表达式然后被零扩展以适应 foo 的 8 位大小。
所有人都可以从 IEEE 网站免费下载 IEEE 1800-2017。
我相信您混淆了数字文字(如 8'bz
)与表达式中的值发生的情况。数字文字将指定的 z
或 z
填充到指定的宽度。但是一旦在表达式中,无符号值就会被填充为 0,而有符号值会像您的讲师所说的那样被填充。
只有 latest version of the IEEE standard is freely available—older version must be purchased. This website 显示了对 SystemVerilog 标准的最新更改。
这是相关的示例行为 Verilog 代码
module constant;
reg [7:0] foo;
initial begin
foo = 1'bz;
$display("%H", foo);
end
endmodule
Icarus Verilog 给了我
$ iverilog -o constant constant.v
$ ./constant
0Z
然而,根据this website(以及我正在上的 FPGA 课程的讲师),
If number is smaller than the size constant, then it will be padded to the left with zeros. If the most significant bit of a specified number has an unknown (x) or high-impedance (z) value, then that value will be used to pad to the left.
在那种情况下,输出应该是 ZZ
而不是 0Z
。我很确定这是由于规范的更改(可能是 Verilog 1995 中的 ZZ
和 Verilog 2001 中的 0Z
或其他),但导致每种行为的标准是什么?我试过在线搜索规范,但它们似乎不是免费提供的,例如 this one 需要购买或订阅。
作为奖励,我在哪里可以找到 Verilog 各种规范的变化摘要?
SystemVerilog IEEE 1800-2017 说:
If the size of the unsigned number is smaller than the size specified for the literal constant, the unsigned number shall be padded to the left with zeros. If the leftmost bit in the unsigned number is an x or a z, then an x or a z shall be used to pad to the left, respectively. If the size of the unsigned number is larger than the size specified for the literal constant, the unsigned number shall be truncated from the left.
但是,这里的数字不小于大小常量——这里的大小是1'bz中的“1”。
对于表达式结果的转换,标准是这样说的:
Automatic type conversions from a smaller number of bits to a larger number of bits involve zero extensions if unsigned or sign extensions if signed. Automatic type conversions from a larger number of bits to asmaller number of bits involve truncations of the most significant bits (MSBs).
因为这是一个无符号表达式和结果,所以 1'bz 文字表达式然后被零扩展以适应 foo 的 8 位大小。
所有人都可以从 IEEE 网站免费下载 IEEE 1800-2017。
我相信您混淆了数字文字(如 8'bz
)与表达式中的值发生的情况。数字文字将指定的 z
或 z
填充到指定的宽度。但是一旦在表达式中,无符号值就会被填充为 0,而有符号值会像您的讲师所说的那样被填充。
只有 latest version of the IEEE standard is freely available—older version must be purchased. This website 显示了对 SystemVerilog 标准的最新更改。