[source]

Class uvm_packer

uvm_pkg::uvm_packer + abstract : bit + big_endian : bit + bitstream[] : bit + byte_size : byte + count : int + fabitstream[] : bit + m_bits : uvm_pack_bitstream_t + m_packed_size : int + nopack : bit + physical : bit + policy : uvm_recursion_policy_enum + reverse_order : bit + scope : uvm_scope_stack + use_metadata : bit + word_size : int + enough_bits(): bit + get_bit(): bit unsigned + get_bits(): void + get_byte(): byte unsigned + get_bytes(): void + get_int(): int unsigned + get_ints(): void + get_packed_bits(): uvm_pack_bitstream_t + get_packed_size(): int + index_error(): void + is_null(): bit + pack_bits(): void + pack_bytes(): void + pack_field(): void + pack_field_int(): void + pack_ints(): void + pack_object(): void + pack_real(): void + pack_string(): void + pack_time(): void + put_bits(): void + put_bytes(): void + put_ints(): void + reset(): void + set_packed_size(): void + unpack_bits(): void + unpack_bytes(): void + unpack_field(): uvm_bitstream_t + unpack_field_int(): uvm_integral_t + unpack_ints(): void + unpack_object(): void + unpack_object_ext(): void + unpack_real(): real + unpack_string(): string + unpack_time(): time uvm_pkg::uvm_scope_stack scope

Collaboration Diagram of uvm_packer

Variables

Name

Type

Description

physical

bit

This bit provides a filtering mechanism for fields.

The abstract and physical settings allow an object to distinguish between two different classes of fields. It is up to you, in the uvm_object::do_pack and uvm_object::do_unpack methods, to test the setting of this field if you want to use it as a filter.

abstract

bit

This bit provides a filtering mechanism for fields.

The abstract and physical settings allow an object to distinguish between two different classes of fields. It is up to you, in the uvm_object::do_pack and uvm_object::do_unpack routines, to test the setting of this field if you want to use it as a filter.

use_metadata

bit

This flag indicates whether to encode metadata when packing dynamic data, or to decode metadata when unpacking. Implementations of uvm_object::do_pack and uvm_object::do_unpack should regard this bit when performing their respective operation. When set, metadata should be encoded as follows:

  • For strings, pack an additional null byte after the string is packed.

  • For objects, pack 4 bits prior to packing the object itself. Use 4'b0000 to indicate the object being packed is null , otherwise pack 4'b0001 (the remaining 3 bits are reserved).

  • For queues, dynamic arrays, and associative arrays, pack 32 bits indicating the size of the array prior to packing individual elements.

big_endian

bit

This bit determines the order that integral data is packed (using pack_field, pack_field_int, pack_time, or pack_real) and how the data is unpacked from the pack array (using unpack_field, unpack_field_int, unpack_time, or unpack_real). When the bit is set, data is associated msb to lsb; otherwise, it is associated lsb to msb.

The following code illustrates how data can be associated msb to lsb and lsb to msb:

class mydata extends uvm_object;

  logic[15:0] value = 'h1234;

  function void do_pack (uvm_packer packer);
    packer.pack_field_int(value, 16);
  endfunction

  function void do_unpack (uvm_packer packer);
    value = packer.unpack_field_int(16);
  endfunction
endclass

mydata d = new;
bit bits[];

initial begin
  d.pack(bits);  // 'b0001001000110100
  uvm_default_packer.big_endian = 0;
  d.pack(bits);  // 'b0010110001001000
end
bitstream

bit

variables and methods primarily for internal use local bits for (un)pack_bytes

fabitstream

bit

field automation bits for (un)pack_bytes

count

int

used to count the number of packed bits

scope

uvm_scope_stack

reverse_order

bit

flip the bit order around

byte_size

byte

set up bytesize for endianess

word_size

int

set up worksize for endianess

nopack

bit

only count packable bits

policy

uvm_recursion_policy_enum

Functions

virtual function void pack_field ( uvm_bitstream_t value, int size ) [source]

Packs an integral value (less than or equal to 4096 bits) into the packed array. size is the number of bits of value to pack. Pack_field

virtual function void pack_field_int ( uvm_integral_t value, int size ) [source]

Packs the integral value (less than or equal to 64 bits) into the pack array. The size is the number of bits to pack, usually obtained by $bits . This optimized version of pack_field is useful for sizes up to 64 bits. Pack_field_int

virtual function void pack_bits ( bit value, int size ) [source]

Packs bits from upacked array of bits into the pack array.

See pack_ints for additional information. Pack_bits

virtual function void pack_bytes ( byte value, int size ) [source]

Packs bits from an upacked array of bytes into the pack array.

See pack_ints for additional information. Pack_bytes

virtual function void pack_ints ( int value, int size ) [source]

Packs bits from an unpacked array of ints into the pack array.

The bits are appended to the internal pack array. This method allows for fields of arbitrary length to be passed in, using the SystemVerilog stream operator.

For example

bit[511:0] my_field;
begin
  int my_stream[];
  { << int {my_stream}} = my_field;
  packer.pack_ints(my_stream);
end

When appending the stream to the internal pack array, the packer will obey the value of big_endian (appending the array from MSB to LSB if set).

An optional size parameter is provided, which defaults to '-1'. If set to any value greater than '-1' (including 0), then the packer will use the size as the number of bits to pack, otherwise the packer will simply pack the entire stream.

An error will be asserted if the size has been specified, and exceeds the size of the source array. Pack_ints

virtual function void pack_string ( string value ) [source]

Packs a string value into the pack array.

When the metadata flag is set, the packed string is terminated by a null character to mark the end of the string.

This is useful for mixed language communication where unpacking may occur outside of SystemVerilog UVM. Pack_string

virtual function void pack_time ( time value ) [source]

Packs a time value as 64 bits into the pack array. Pack_time

virtual function void pack_real ( real value ) [source]

Packs a real value as 64 bits into the pack array.

The real value is converted to a 6-bit scalar value using the function $real2bits before it is packed into the array. Pack_real

virtual function void pack_object ( uvm_object value ) [source]

Packs an object value into the pack array.

A 4-bit header is inserted ahead of the string to indicate the number of bits that was packed. If a null object was packed, then this header will be 0.

This is useful for mixed-language communication where unpacking may occur outside of SystemVerilog UVM. Pack_object

virtual function bit is_null ( ) [source]

This method is used during unpack operations to peek at the next 4-bit chunk of the pack data and determine if it is 0.

If the next four bits are all 0, then the return value is a 1; otherwise it is 0.

This is useful when unpacking objects, to decide whether a new object needs to be allocated or not. Is_null

virtual function uvm_bitstream_t unpack_field ( int size ) [source]

Unpacks bits from the pack array and returns the bit-stream that was unpacked. size is the number of bits to unpack; the maximum is 4096 bits. Unpack_field

virtual function uvm_integral_t unpack_field_int ( int size ) [source]

Unpacks bits from the pack array and returns the bit-stream that was unpacked.

size is the number of bits to unpack; the maximum is 64 bits. This is a more efficient variant than unpack_field when unpacking into smaller vectors. Unpack_field_int

virtual function void unpack_bits ( bit value, int size ) [source]

Unpacks bits from the pack array into an unpacked array of bits. Unpack_bits

virtual function void unpack_bytes ( byte value, int size ) [source]

Unpacks bits from the pack array into an unpacked array of bytes. Unpack_bytes

virtual function void unpack_ints ( int value, int size ) [source]

Unpacks bits from the pack array into an unpacked array of ints.

The unpacked array is unpacked from the internal pack array. This method allows for fields of arbitrary length to be passed in without expanding into a pre-defined integral type first.

For example

bit[511:0] my_field;
begin
  int my_stream[] = new[16]; // 512/32 = 16
  packer.unpack_ints(my_stream);
  my_field = {<<{my_stream}};
end

When unpacking the stream from the internal pack array, the packer will obey the value of big_endian (unpacking the array from MSB to LSB if set).

An optional size parameter is provided, which defaults to '-1'. If set to any value greater than '-1' (including 0), then the packer will use the size as the number of bits to unpack, otherwise the packer will simply unpack the entire stream.

An error will be asserted if the size has been specified, and exceeds the size of the target array. Unpack_ints

virtual function string unpack_string ( int num_chars ) [source]

Unpacks a string.

num_chars bytes are unpacked into a string. If num_chars is -1 then unpacking stops on at the first null character that is encountered. If num_chars is not -1, then the user only wants to unpack a specific number of bytes into the string.

virtual function time unpack_time ( ) [source]

Unpacks the next 64 bits of the pack array and places them into a time variable. Unpack_time

virtual function real unpack_real ( ) [source]

Unpacks the next 64 bits of the pack array and places them into a real variable.

The 64 bits of packed data are converted to a real using the $bits2real system function. Unpack_real

virtual function void unpack_object ( uvm_object value ) [source]

Unpacks an object and stores the result into value .

value must be an allocated object that has enough space for the data being unpacked. The first four bits of packed data are used to determine if a null object was packed into the array.

The is_null function can be used to peek at the next four bits in the pack array before calling this method.

virtual function int get_packed_size ( ) [source]

Returns the number of bits that were packed. Get_packed_size

virtual function void unpack_object_ext ( uvm_object value ) [source]

Unpack_object

virtual function uvm_pack_bitstream_t get_packed_bits ( ) [source]

Get_packed_bits

virtual function bit unsigned get_bit ( int unsigned index ) [source]

Get_bit

virtual function byte unsigned get_byte ( int unsigned index ) [source]

Get_byte

virtual function int unsigned get_int ( int unsigned index ) [source]

Get_int

virtual function void get_bits ( bit unsigned bits ) [source]

Get_bits

virtual function void get_bytes ( byte unsigned bytes ) [source]

Get_bytes

virtual function void get_ints ( int unsigned ints ) [source]

Get_ints

virtual function void put_bits ( bit unsigned bitstream ) [source]

Put_bits

virtual function void put_bytes ( byte unsigned bytestream ) [source]

Put_bytes

virtual function void put_ints ( int unsigned intstream ) [source]

Put_ints

virtual function void set_packed_size ( ) [source]

Set_packed_size

function void index_error ( int index, string id, int sz ) [source]

Index_ok

function bit enough_bits ( int needed, string id ) [source]

Enough_bits

function void reset ( ) [source]

Reset