问题描述
我在 SystemVerilog 中看到一个代码,它有这样的内容:
if(address[2*pointer+:2])做点什么;
在索引这个向量时我应该如何理解+:
?
我发现它被称为位切片,但我找不到关于它的解释.
描述和示例可以在 IEEE Std 1800-2017 §11.5.1矢量位选择和部分选择寻址".第一个IEEE出现是IEEE 1364-2001 (Verilog) §4.2.1矢量位选择和部分选择寻址".这是来自 LRM 的一个直接示例:
logic [31: 0] a_vect;逻辑 [0:31] b_vect;逻辑 [63: 0] 双字;整数 sel;a_vect[ 0 +: 8]//== a_vect[ 7 : 0]a_vect[15 -: 8]//== a_vect[15 : 8]b_vect[ 0 +: 8]//== b_vect[0 : 7]b_vect[15 -: 8]//== b_vect[8 :15]dword[8*sel +: 8]//固定宽度的可变部分选择
如果 sel
为 0,则 dword[8*(0) +: 8] == dword[7:0]
如果 sel
是 7 那么 dword[8*(7) +: 8] == dword[63:56]
左边的值总是起始索引.右边的数字是宽度,必须是正常数.+
和 -
表示选择比起始索引更高或更低索引值的位.
假设 address
是小端 ([msb:lsb]) 格式,那么 if(address[2*pointer+:2])
相当于 if({address[2*pointer+1],address[2*pointer]})
I am seeing a code in SystemVerilog which has something like this:
if(address[2*pointer+:2])
do_something;
How should I understand the +:
when indexing this vector?
I found that it is called bit slicing, but I can't find an explanation about it.
Description and examples can be found in IEEE Std 1800-2017 § 11.5.1 "Vector bit-select and part-select addressing". First IEEE appearance is IEEE 1364-2001 (Verilog) § 4.2.1 "Vector bit-select and part-select addressing". Here is an direct example from the LRM:
If sel
is 0 then dword[8*(0) +: 8] == dword[7:0]
If sel
is 7 then dword[8*(7) +: 8] == dword[63:56]
The value to the left always the starting index. The number to the right is the width and must be a positive constant. the +
and -
indicates to select the bits of a higher or lower index value then the starting index.
Assuming address
is in little endian ([msb:lsb]) format, then if(address[2*pointer+:2])
is the equivalent of if({address[2*pointer+1],address[2*pointer]})
这篇关于使用 + 索引向量和数组:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!