Jump to content

cloning a register


Recommended Posts

Hello,

 

I am running a simulation on a DUT that has a register model.

what i wish to do is hold a copy of that register model so that at certain times during the simulation

i can compare a current value of a register to a former value of that register taken at a previous point in time.

i don't want to save only the data of the registers, but an array of registers that will hold a copy of the whole register object,

including all of it's fields and other attributes.

 

i tried to create an array of type uvm_reg                                             uvm_reg registers_copy[]

and then use clone to copy a register to that array                               $cast(registers_copy, registers.clone());

 

but i get an error:

UVM_FATAL /tools/snps/vcs/current/etc/uvm-1.1/reg/uvm_reg.svh(3102) @ 3520.6ns: reporter [RegModel] RegModel registers cannot be cloned

 

how can i create a copy of my register model at certain points in time?

 

Thanks for your help,

Assaf

Link to comment
Share on other sites

You're going to have to implement your own copying scheme. It might get tricky because of all the 'local' fields in the register classes, but there's no way around it. At the same time, you could just store the register values at a certain point in time and when you need to do something with them, you can unpack those values in a temporary register of that type to extract the individual fields.

Link to comment
Share on other sites

thanks for your response.

the problem with this approach is that i want to do it automatically (foreach registers...) and each register has different fields so i won't know how exactly to store the values.

i could save: a value, how many fields, the size of each field etc.

but it creates a lot of code...

 

there must be an easy way to create a copy of a register...

 

Thx,

Assaf

Link to comment
Share on other sites

  • 2 years later...

Hi,

Here my two cents. Cloning of register blocks is not intended in UVM. Therefore, there are several checkers that warns you about that.

One way to do this is implementing a custom clone function inside the register block for each field. This is something that can be done with some perl scripting (if you have many registers and fields).

See a small snip on how to do that (only with one register and field EXPECTED_SUM_2)

 

   class hmac_sha256_regblock extends uvm_reg_block;
      `uvm_object_utils(hmac_sha256_regblock)
      //This function has been included in the automatic generated register block from UVM using the script
      typedef hmac_sha256_regblock this_regblocktype;
       virtual function this_regblocktype clone_reg_block(input int clone_mode=0, input string unique_regblockstr_id="dummy");
         automatic this_regblocktype dummyregblock;
         dummyregblock = this_regblocktype::type_id::create($sformatf( "hmac_sha256_regblock_%s",unique_regblockstr_id));
         dummyregblock.build();
         if ((clone_mode==0)||(clone_mode==1)) begin
             dummyregblock.inst_EXPECTED_SUM_2.EXPECTED_SUM_2.set(this.inst_EXPECTED_SUM_2.EXPECTED_SUM_2.get());
         end
         if ((clone_mode==0)||(clone_mode==2)) begin
             assert(dummyregblock.inst_EXPECTED_SUM_2.EXPECTED_SUM_2.predict(this.inst_EXPECTED_SUM_2.EXPECTED_SUM_2.get_mirrored_value()) );            
         end
         return dummyregblock;
      endfunction:clone_reg_block 


      rand EXPECTED_SUM_2 inst_EXPECTED_SUM_2; // Computation settings

.....
  endclass

In your sequence you can call the clone function in the following way

m_regblock_cloned_base = REGBLOCK.clone_reg_block(0);

This will create a frozen/dummy block that has the same values that you had for the register model at that point of the simulation.

I hope it helps

Jonathan

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