Jump to content

Streaming operator for unpacking a bitstream

Recommended Posts

I'm stuck on a problem I encountered with a use of the streaming operator to unpack into a dynamic array.  Rather than write procedural code, I thought I could use it actually with some amount of success.  Here is what the code more or less looks like:



uvm_pack_bitstream_t bit_vector;
bit bit_array[];
bit_vector = packer.get_packed_bits();
{<<{bit_array with [0 +: packer.count]}} = bit_vector;

Yes, I'm trying to use "unadvertised" features of the UVM packer here.  This has worked in many cases, but there is one case that led to the following:



# ** Fatal: Width do not match. Stream larger than variable.


I thought maybe the packer count was too large compared to the bits returned from the packer, but similar scenarios had executed previously in the simulation without error.


BTW, this is the only thing reported in the error, which is followed by the file and line number where it occurred (i.e. the streaming operator above).


So, any ideas or insight as to what is going on here?



Link to comment
Share on other sites

I think you have the streaming operator on the wrong side of the assignment. You want a limited part of bit_vector to fill bit_array, not all of bit_vector (which is 32K bits) to fill a limited part of bit_array.



bit_array = {<<{bit_vector with [0+:packer.count()]}};
Link to comment
Share on other sites

Thanks, Dave.  Actually, the with range needed to match the declared range of bit_vector:



bit_array = {<<{bit_vector with [packer.count-1:0]}};


The fatal was resolved; I overlooked something, and it had nothing to do with the streaming assignment after all.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...