Jump to content
Sign in to follow this  
meenu

pack function

Recommended Posts

pack function in UVM

I have a class

class A extends uvm_sequence_item;

...

rand bit[3:0]a;

rand bit[121:0]b;

rand bit[162:122]c;

rand bit[511:163]d;

...

endclass

I have another class

class B extends uvm_sequence_item;

....

rand bit[511:0]field;

...

endclass

I would like to assign to field the packed version of all the fields of class A.

ie. B b1;

A a1;

b1 = pack(all fields of a1);

How can i use the uvm pack function for this??

Need immediate help

Share this post


Link to post
Share on other sites

hi,

why not

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

   class ac extends uvm_object;
       rand bit[3:0]a;
       rand bit[121:0]b;
       rand bit[162:122]c;
       rand bit[511:163]d;

       `uvm_object_utils_begin(ac)
       `uvm_field_int(a,UVM_DEFAULT)
       `uvm_field_int(b,UVM_DEFAULT)
       `uvm_field_int(c,UVM_DEFAULT)
       `uvm_field_int(d,UVM_DEFAULT)   
       `uvm_object_utils_end     

       function new (string name="");
           super.new(name);
       endfunction  
   endclass

   class bc extends uvm_object;
       rand bit[511:0]field;
       `uvm_object_utils(bc)   
       function new (string name="");
           super.new(name);
       endfunction     
   endclass

   initial begin
       ac ma = new;
       bc mb = new;
       bit d[];

       ma.pack(d);
       $display({>>{d}});

   end
endmodule

Share this post


Link to post
Share on other sites

hi,

why not

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

    class ac extends uvm_object;
        rand bit[3:0]a;
        rand bit[121:0]b;
        rand bit[162:122]c;
        rand bit[511:163]d;

        `uvm_object_utils_begin(ac)
        `uvm_field_int(a,UVM_DEFAULT)
        `uvm_field_int(b,UVM_DEFAULT)
        `uvm_field_int(c,UVM_DEFAULT)
        `uvm_field_int(d,UVM_DEFAULT)   
        `uvm_object_utils_end     

        function new (string name="");
            super.new(name);
        endfunction  
    endclass

    class bc extends uvm_object;
        rand bit[511:0]field;
        `uvm_object_utils(bc)   
        function new (string name="");
            super.new(name);
        endfunction     
    endclass

    initial begin
        ac ma = new;
        bc mb = new;
        bit d[];
        
        ma.pack(d);
        $display({>>{d}});
    
    end
endmodule

Hi uwes

This packs into bits. If i would like to pack them into bytes, what should i use ?

Share this post


Link to post
Share on other sites

use pack_bytes instead of pack

it works pretty well, but now i face a different situation .

what if

module test187;

import uvm_pkg::*;

`include "uvm_macros.svh"

class ac extends uvm_object;

rand bit[31:0]a;

rand bit[121:32]b;

rand bit[162:122]c;

rand bit[511:163]d;

`uvm_object_utils_begin(ac)

`uvm_field_int(a,UVM_DEFAULT)

`uvm_field_int(b,UVM_DEFAULT)

`uvm_field_int(c,UVM_DEFAULT)

`uvm_field_int(d,UVM_DEFAULT)

`uvm_object_utils_end

function new (string name="");

super.new(name);

endfunction

endclass

class bc extends uvm_object;

rand bit[511:0]field;

`uvm_object_utils(bc)

function new (string name="");

super.new(name);

endfunction

endclass

initial begin

ac ma = new;

bc mb = new;

bit d[];

ma.pack(d);

$display({>>{d}});

end

endmodule

Am assigning variable a of class ac with the value {16'h00,8'h5,8'h5} via a task.

When i pack, the value am expecting is

byte 0 = 0

byte 1 = 5

byte 2 = 0

byte 3 = 5

byte 4 = 0

byte 5 = 0

byte 6 =0

byte 7= 0

all bytes are packed properly, except for the first eight bytes which are packed in reverse order :

byte 0 = 0

byte 1 = 0

byte 2 = 0

byte 3 = 0

byte 4 = 0

byte 5 = 5

byte 6 =0

byte 7=5

byte 8=..

.

.

.

byte 63=..

why does this happen?

Edited by meenu

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×