Jump to content

`uvm_unpack_arrayN Macro


Recommended Posts


I tried using the `uvm_unpack arrayN macro, but I ran into a problem.

The DUT uses a SPI for accessing a SRAM. The length of the access is dynamic and ends by disabling the chip select. The access command and start address are held in the first three bytes, so I know exactly the start of the payload.

Because of the defined protocol, no metadata can be encoded in the bytestream. So i tried to use `uvm_unpack_arrayN(data,8) to read back my array.

The thing is, when i run this macro without having the packer set to use meta data, the array data will always have zero entries, because sz__ will be always zero. The macro expansion is:

`uvm_unpack_arrayN(data, 8);


int sz__;

if (packer.use_metadata)


if (packer.big_endian) begin

int cnt__ = packer.count + 32;

uvm_bitstream_t tmp__ = sz__;

for (int i=0; i<32; i++)

tmp__ = packer.m_bits[cnt__ - i - 1];

sz__ = tmp__;


else begin

sz__ = packer.m_bits[packer.count +: 32];


packer.count += 32;


data = new[sz__];


foreach (data )



It is easy to work around my issue. I just computed the length and did a foreach:

data = new[packer.get_packed_size() / 8 - 3];


`uvm_unpack_intN(data, 8);

I just wanted to ask if this kind of behaviour is intended by the macro? Maybe it would make sense to init the array only, if metainformation is encoded or if no meta information is encoded and the array is not initialized?

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...