Streaming 32-bit to 8-bit

I am trying to stream each byte of a 32-bit word in a queue like so:


bit [31:0] queue[$];
bit[7:0]   data;
foreach(queue[i]) begin
    for (int j=0; j<4; j++) begin
        data = {data, {>> 8{queue[i]}}};
    end
end

However, this only fetches the least-significant byte of the queue. What is the proper syntax to stream each byte from the queue?

In reply to Robert.Lanier:

We don’t know the byte ordering you want. It would help if you gave some sample values and showed how you wanted data to be streamed. For example

module top;
  bit [31:0] queue[$] = {32'h01234567,32'h89ABCDEF};
  bit[7:0]   data;

  initial 
    foreach(queue[i]) 
      for (int j=0; j<4; j++) begin
        data = queue[i][j*8+:8];
        $displayh(data);
      end
endmodule

Displays

# 67
# 45
# 23
# 01
# ef
# cd
# ab
# 89
1 Like

In reply to dave_59:

In reply to Robert.Lanier:
We don’t know the byte ordering you want. It would help if you gave some sample values and showed how you wanted data to be streamed. For example

module top;
bit [31:0] queue[$] = {32'h01234567,32'h89ABCDEF};
bit[7:0]   data;
initial 
foreach(queue[i]) 
for (int j=0; j<4; j++) begin
data = queue[i][j*8+:8];
$displayh(data);
end
endmodule

Displays

# 67
# 45
# 23
# 01
# ef
# cd
# ab
# 89

I should have mentioned I am trying to fetch LSB first, thank you for pointing this out.

I had started using the same solution you have shown, but preferred to use the streaming concept rather rather than specific values from the data word. However, after reviewing section 11.5.1 Vector bit-select and part-select addressing of the SystemVerilog LRM (1800-2017), this is the solution I was looking for.

Thank you again for the help!

In reply to Robert.Lanier:

If you really wanted to use the streaming operator, data would have to be defined as a queue.

module top;
  bit [31:0] queue[$] = {32'h01234567,32'h89ABCDEF};
  bit[7:0]   data[$];
  initial begin
      queue.reverse;
      data = {<<8{queue}  };
      $displayh("%p",data);
   end
endmodule

In reply to dave_59:

In reply to Robert.Lanier:
If you really wanted to use the streaming operator, data would have to be defined as a queue.

module top;
bit [31:0] queue[$] = {32'h01234567,32'h89ABCDEF};
bit[7:0]   data[$];
initial begin
queue.reverse;
data = {<<8{queue}  };
$displayh("%p",data);
end
endmodule

Is this because the LHS and RHS need to be of the same type when using a streaming operator?

In reply to Robert.Lanier:

The LHS has to have enough bits (or dynamically resized) to hold all the bits on the RHS.