[英]Please explain this SystemVerilog syntax {>>byte{…}}
The answer for the following program is {6,7,8} but I don't understand why, please explain a bit: 以下程序的答案是{6,7,8},但我不明白为什么,请解释一下:
module q ();
typedef byte byteq[$];
initial begin
byte ans[$];
ans = byteq'({>>byte{24'h060708}});
$display("A:expect '{6,7,8} get %p", ans);
end
endmodule
The >> operator is not logical shift in this context, but it is called stream operator. >>运算符在此上下文中不是逻辑移位,但它被称为流运算符。
Stream operators determine the order in which blocks of data are streamed: >> causes blocks of data to be streamed in left-to-right order, while << causes blocks of data to be streamed in right-to-left order. 流操作符确定流式传输数据块的顺序:>>导致数据块以从左到右的顺序流式传输,而<<导致数据块以从右到左的顺序流式传输。
Consider the following lines for example: 例如,请考虑以下行:
$display ("%h", {>>byte{24'h060708}} );
$display ("%h", {<<byte{24'h060708}} );
In both, the number 24'h060708 should be first sliced into bytes (called slice_size). 在两者中,数字24'h060708应首先切成字节(称为slice_size)。 The first one prints the bytes from left to right, whereas the second one prints them from right to left. 第一个从左到右打印字节,而第二个从右到左打印它们。 Therefor, the output is: 因此,输出是:
060708
080706
Now, in line ans = byteq'({>>byte{24'h060708}});
现在,在行ans = byteq'({>>byte{24'h060708}});
you are using bit-stream casting, which casts 24'h060708
number sliced in bytes represented from left to right into byteq, which is a queue of bytes. 你正在使用比特流转换,它将24'h060708
表示的24'h060708
数字切换成byteq,这是一个字节队列。
For a full explanation, refer to IEEE Std 1800-2012 § 11.4.14 Streaming operators (pack/unpack) 有关完整说明,请参阅IEEE Std1800-2012§11.4.14 流媒体运营商(打包/解包)
The slice_size determines the size of each block, measured in bits. slice_size确定每个块的大小,以位为单位。 If a slice_size is not specified, the default is 1. If specified, it may be a constant integral expression or a simple type. 如果未指定slice_size ,则默认值为1.如果指定,则它可以是常量整型表达式或简单类型。 If a type is used, the block size shall be the number of bits in that type. 如果使用类型,则块大小应为该类型中的位数。 If a constant integral expression is used, it shall be an error for the value of the expression to be zero or negative. 如果使用常量积分表达式,则表达式的值为零或负数时应该是一个错误。
The stream_operator<<
or>>
determines the order in which blocks of data are streamed:>>
causes blocks of data to be streamed in left-to-right order, while<<
causes blocks of data to be streamed in right-to-left order. stream_operator<<
或>>
确定流式传输数据块的顺序:>>
导致数据块以从左到右的顺序流式传输,而<<
导致数据块以右向顺序流式传输左命令。 Left-to-right streaming using>>
shall cause the slice_size to be ignored and no re-ordering performed. 使用>>
从左到右的流式传输将导致slice_size被忽略并且不执行重新排序。 Right-to-left streaming using<<
shall reverse the order of blocks in the stream, preserving the order of bits within each block. 使用<<
从右到左的流传输将反转流中块的顺序,保留每个块内的位的顺序。 For right-to-left streaming using<<
, the stream is sliced into blocks with the specified number of bits, starting with the right-most bit. 对于使用<<
从右到左的流,流被切成具有指定位数的块,从最右边的位开始。 If as a result of slicing the last (left-most) block has fewer bits than the block size, the last block has the size of the remaining bits; 如果作为切片的结果,最后一个(最左边)的块具有比块大小更少的位,则最后一个块具有剩余位的大小; there is no padding or truncation. 没有填充或截断。
In your case {>>byte{24'h060708}
creates the stream {8'h06, 8'h07, 8'h08}
. 在你的情况下{>>byte{24'h060708}
创建流{8'h06, 8'h07, 8'h08}
。 byteq'()
is casting the stream into bytes, but it is unnecessary since the stream is already matches the correct size. byteq'()
将流转换为字节,但由于流已经匹配正确的大小,因此它是不必要的。 ans = {>>byte{24'h060708}};
will have the same result. 会有相同的结果。 If you change the stream_operator to <<
the stream would be {8'h08, 8'h07, 8'h06}
. 如果将stream_operator更改为<<
流将是{8'h08, 8'h07, 8'h06}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.