What is meaning of Streaming Operator

int j = { “A”, “B”, “C”, “D” };
{ << 16 {j}} // generates stream “C” “D” “A” “B”
{ << 4 { 6’b11_0101 }} // generates stream 'b0101_11

hello sir i new to system verilog can you tell me why we are using streaming operator and i gone through some of example >> and << operator but this two example i am not able to understand what does 16 before concatenation in line 2 and in line 3 what is meaning of 4 and how it genrate the stream of 0101_11,beacuse answer must start from either left to right or right to left…

You should take a look at section 6.24.3 Bit stream casting first. A bit-stream cast is used to convert a data type of any shape made solely of bits to another data type of another shape. For example

typedef bit [7:0] array_of_bytes_t[16]];
typedef bit [31:0] array_of_words_t[4];
array_of_bytes_t a1;
array_of_words_t a2;

a1 = array_of_bytes'(a2);

The case will create a stream from a2 by taking the left most word bit (31) from the left most array element (0) and then proceed to take bits left-to-right in the word and left-to-right in the array. Then the stream will be assigned to a1 by taking the stream left to right and assigning bits to a1 in a similar left-to-right manner. The two data types must also have the exact same total number of bits.

But some times, you need something other than a simple left-to-right stream of bits, or don’t have the exact same number of bits in the two data types. That’s when you use the streaming operator. The >> or << is used to specify whether you want to stream left-to-right, or right-to-left respectively. The number after the << or >> specify that you want to stream some other chunk other than 1 bit (16 or 4 bits in your example.

So {<< 16 {j}} says you want to stream right-to-left in chunks of 16 bits. It will create a stream taking the right most chunk of j[15:0] first, followed by the chunk to the left j[31:16], which is effectively {j[15:0],j[31:16]}

{ << 4 { 6’b11_0101 }} says take the right most chunk of 4 bits first, which is effectively {4’b0101,2’b11}

1 Like

In reply to dave_59:

thanks sir i understand the concept of operator streaming and casting but though i am not clear with example-2 << 4 { 6’b11_0101 }} means right to left with 4’bits aor my first 4-bit must be 1010 why its 0101(because this stream is starting from left to right)???

In reply to SHREYAS PATEL:

The chunks, in this case the groups of 4 bits, are always streamed left to right.

In reply to dave_59:

thanks sir now i got it

In reply to SHREYAS PATEL:

Hello Dave,

I have a dynamic array of 32 bits which I would like to write into a byte memory. Say I have something like the following:

bit[31:0] rdata;

for example:

rdata = '{32’h5a5a_abcd, 32’h1234_5678}

I would like to write the bytes as 8’hcd (location # 0), 8’hab (location # 1), 8’h5a (location # 2), 8’h5a (location # 3),8’h78 (location # 4), 8’h56 (location # 5),8’h34 (location # 6), 8’h12 (location # 7).

Is it possible to achieve this using steaming operators ?

Thanks,
Madhu

In reply to mseyunni:

There is an example of this on page 240 of the 1800-2012 LRM(11.4.14.2 Re-ordering of the generic stream). You can use either 8 or byte to indicate you want chunks of 8 bits.