Hi,
I have tried to pack/unpack the data of different widths and facing some issues as mentioned below. please help
- Example : I am trying to convert byte array to 33 bit chunk array where as the chunk array width is 1024 bits and size is dynamic . first i am converting byte array to bit stream array and then into 33 bit chunk array .
module test;
bit[7:0] byte_a[];
bit[32:0] chunk_a[];
bit bit_stream_q[$];
bit[1023:0] chunk_a_2[];
initial begin
byte_a = '{8'hAA,8'hBB,8'hCC,8'hDD,8'hEE};
bit_stream_q = {>>{byte_a}}; // pack into bit stream array.
chunk_a = {>>{bit_stream_q}};
$display("byte_array :%0p", byte_a);
$display("bit_queue :0p", bit_stream_q);
$display("chunk_a:%p",chunk_a);
end
endmodule
Actual output :
byte_array :'{'haa, 'hbb, 'hcc, 'hdd, ‘hee}
chunk_a:’{'h1557799bb, 'h1b8000000}
Why the ouptut is not like aabbccdd{lowe bye of e} .
Please help
You have a typo in your code. [32:0]
should be [31:0]
Hi Dave,
Intentionally i make it 33 bit wide since i need to pack the byte array to 33 bit chunk array.
Requirement : i have a byte array bit[7:0] byte_a : which will give me payload in terms of bytes.
Now i need to convert in to configurable chunk sizes{33,20,66,…1023} .
so i have created a chunk array bit[1023:0]chunk_a;
for example: if my chunk size is 33 : then each element of chunk array must contain 33b form the generated payload(bytes) wihtout loosing any payload data.
Please help
The streaming operator works on contiguous streams of bits performing a packing operation. It also left-justifies the stream padding zeros on the right.
In your original example, the source stream {>>{byte_a}}
is 40 bits (5 bytes). There is no need to have the intermediate bit_stream_q
array except if you wanted to see that stream for debugging. The destination stream chunk_a
is a dynamic array of 33 bits. The streaming operator is going to put the first 33 bits of the source stream into the first element of the destination stream. That is equivalent to the following assignments:
chunk_a[0][32: 25] = byte_a[0];
chunk_a[0][24: 17] = byte_a[1];
chunk_a[0][16: 9] = byte_a[2];
chunk_a[0][ 8: 1] = byte_a[3];
{chunk_a[0][0], chunk[1][32:26]} = byte_a[4];
chunk_a[1][ 25:0] = '0;
If what you really want is integral number of bites right justified in each element of your chunk, you’ll have to use some combination of loops and streaming operators. It would help to have complete examples that shows the data structures you want before and after.
module tb;
bit[7:0] byte_a[];
bit[1023:0] chunk_a[];
bit bit_stream_q[];
int chunk_size = 33;
initial begin
end
initial begin
byte_a = '{8'hAA,8'hBB,8'hCC,8'hDD,8'hEE};
bit_stream_q = {>>{byte_a}};
$display("bit_stream_q:%p",bit_stream_q);
chunk_a = new[2];
foreach(chunk_a[i]) begin
chunk_a[i]={>>{bit_stream_q with [i*33+:33]}};
chunk_a[i]= chunk_a[i] >> 991 & ((1<<33)-1);
//{>>{bit_stream_q with [i*33+:33]}} = chunk_a[i];
//chunk_a[i] = {>>{{byte_a}} with [i*33+:33]};
end
foreach(chunk_a[i]) $display("chunk[%0d]:%0b",i,chunk_a[i]);
$display("chunk_a[i]:%p",chunk_a);
end
endmodule:tb
this is the code i am trying dave.
I have a dynamic array of byte payload whose size can be configurable.
in my chunk_a each element is of chunk size : 33
Please provide some inputts.
Thanks in Advance.
Please format your code making your code easier for others to read. I have done that for you.
Please show the output you are looking for with at least 2 different chunk sizes.
input data : {byte0, byte1,byte2,byte3,byte4,byte5,byte6,byte7,byte8}
output must be
chunk_a[0] = {byte0,byte1,byte2,byte3,lower bit of byte4}
chunk_a[1] = {remaining bits byte4(7bits),byte5,byte6,byte7,lower 2 bits of byte 8}
Please help in gettting the output like this format dave.