Jump to content

UVM pack and unpack


Recommended Posts

The following example of packing and unpacking does not work. Integral fields (length) get packed and unpacked properly but arrays do not get unpacked (unless I'm unpacking to an existing data structure that previously allocated space for the array). Is this a known issue?

program test;

import uvm_pkg::*;
`include "uvm_macros.svh"

class my_item extends uvm_sequence_item;

  rand int length;
  rand bit [7:0]  payload[];

  constraint data_length_cons      { length inside { [1:10] }; }
  constraint data_payload_sizecons { payload.size() == length; }

  `uvm_object_utils_begin(my_item)
    `uvm_field_int(length, UVM_ALL_ON + UVM_DEC)
    `uvm_field_array_int(payload, UVM_ALL_ON)
  `uvm_object_utils_end

endclass

initial begin

  my_item a = new();
  my_item b = new();
  bit bitstream[];
  int num_bits = 0;

  a.randomize();
  `uvm_info("a", {"\n", a.sprint()}, UVM_NONE);
  num_bits = a.pack(bitstream);
  b.unpack(bitstream);
  `uvm_info("b", {"\n", b.sprint()}, UVM_NONE);

end

endprogram : test

Typical output for the unpacked object will look like:

UVM_INFO n.sv(32) @ 0: reporter [b]
--------------------------------------------
Name               Type          Size  Value
--------------------------------------------
uvm_sequence_item  my_item       -     @465
  length           integral      32    'd8
  payload          da(integral)  0     -
--------------------------------------------
Link to comment
Share on other sites

This is handled by the automation macros, but by default the packer doesn't generate the extra "metadata" needed to do this.

In your case, you have a redundant length field, but there's no automated association between that length and the array size.

Link to comment
Share on other sites

I'm not following; the length property is redundant so why does it need to be considered for the unpacking? If I take the length property out and hard-code in the constraint the size of the array, how is the problem going to be different? The array will still be packed the same way.

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.

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