简体   繁体   English

请解释一下这个SystemVerilog语法{>> byte {...}}

[英]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.

相关问题 语法中的 Systemverilog 断言 - Systemverilog assertion throughout syntax SystemVerilog条件语句语法错误 - SystemVerilog conditional statement syntax error 请说明这些Verilog代码? - Please Explain these verilog code? 语法检查数据是否正确(systemverilog) - Syntax to check whether the data is right or not (systemverilog) 如何在SystemVerilog中将可合成字符串分配给字节数组? - How can assign a synthesizable string to a byte array in SystemVerilog? 语法错误。 语句标签仅在SystemVerilog中允许 - Syntax error. Statement labels are only allowed in SystemVerilog 谁能解释SystemVerilog中“ $ sreadmemh”的用法? 我在任何地方都没有清楚的解释 - Can anyone explain the usage of “$sreadmemh” in SystemVerilog? I don't get clear explanation anywhere Verilog/SystemVerilog语法如何使用参数来指示比特流长度&gt; 32位? - Verilog/SystemVerilog syntax how to use a parameter to indicate the bit streamlength when it is > 32 bits? 我是 Verilog 的新手,如果无法合成初始块,那么如何在不重置的情况下初始化寄存器,请有人解释 - I am new to Verilog, If initial block can not be synthesized then how to initialize registers without resetting please someone explain 有人可以解释为什么这会导致组合反馈循环吗? (Vivado Verilog) - Can someone please explain why this causes a combinational feedback loop? (Vivado Verilog)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM