• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. same value for a RANDC variable of base class in extended...

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 65
  • Views 13769
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

same value for a RANDC variable of base class in extended class objects

santhog
santhog over 7 years ago

i have a randc variable "index" in c_base. i've two new classes (class_1 & class_2) extended from base_class.  when randomizing the extended class objects, i observed the variable "index" is having same values in C1 & C2 objects. Below is the simplified copy of my code:

class c_base extends uvm_sequence_item;
rand bit [9:0] index;

`uvm_object_utils_begin(c_base)
`uvm_field_int(index,UVM_ALL_ON)
`uvm_object_utils_end
function new(string name="c_base");
super.new(name);
endfunction
endclass

class class_1 extends c_base;
rand bit [3:0] var1;

rand bit [7:0] var2;

rand bit [3:0] var3;

`uvm_object_utils_begin(class_1)
`uvm_field_int(var1,UVM_ALL_ON)
`uvm_field_int(var2,UVM_ALL_ON)
`uvm_field_int(var3,UVM_ALL_ON)
`uvm_object_utils_end

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


class class_2 extends c_base;
rand bit [4:0] var4;

rand bit [10:0] var5;

`uvm_object_utils_begin(class_2)
`uvm_field_int(var4,UVM_ALL_ON)
`uvm_field_int(var5,UVM_ALL_ON)
`uvm_object_utils_end

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

module tst;
class_1 c1[];
class_2 c2[];
c_base q[$];

initial begin
c1=new[20];
c2=new[20];

foreach(c1[i]) begin
c1[i]=class_1::type_id::create($sformatf("c1_%0d",i));
assert( c1[i].randomize() );
q.push_back(c1[i]);
end

foreach(c2[i]) begin
c2[i]=class_2::type_id::create($sformatf("c2_%0d",i));
assert( c2[i].randomize() );
q.push_back(c2[i]);
end
q.sort with(item.index);

$display("---------------");
$display(" Index Name ");
$display("---------------");
for(int i=0; i<q.size();i++) begin
$display(" x%h %s",q[i].index,q[i].get_name());
end

end

endmodule

EdaPlayground link: https://www.edaplayground.com/x/3pk2

For the above code in EdaPlayground, I'm creating 20 objects for both classes and got same index value (x398, x2d7) for a class_1 & class_2 objects. 

What I expected was, the index value of all objects will be unique until all combinations are exercised. 

My intention is to use "index" as the location of SRAM address to store the packed data of each extended class object.

Is this the expected behavior in SimVision15.20??   Can't i get unique values for variable index?  

  • Cancel
  • StephenH
    StephenH over 7 years ago

    It would help if you pasted the output that you're getting, as well as the actual code you're using. The code you pasted above doesn't compile.

    I modified it by moving the "module tst;" line to the top of the file and adding "include uvm_pkg::*;" and including the uvm_macros.svh file to get it to compile. I also had to change "rand" to "randc" for "index".

    What I see when I run it, is a list of unique IDs:

    ---------------
    Index Name
    ---------------
    x016 c2_11
    x020 c1_0
    x04e c1_10
    x052 c1_12
    x069 c1_9
    x06d c2_2
    x09b c1_17
    x0a1 c1_1
    x0a4 c2_8
    x0ab c1_3
    x0b2 c2_16
    x0b5 c2_0
    x0b8 c1_15
    x0de c2_9
    x0ed c2_10
    x0f9 c2_14
    x109 c2_19
    x111 c1_4
    x11a c2_13
    x11e c1_2
    x194 c1_11
    x1be c2_6
    x219 c1_18
    x271 c2_1
    x274 c1_6
    x27e c1_14
    x288 c2_7
    x2e4 c2_15
    x301 c2_3
    x30a c2_17
    x325 c2_18
    x327 c1_19
    x332 c1_5
    x33c c2_4
    x34a c2_5
    x352 c2_12
    x361 c1_7
    x3c0 c1_16
    x3cb c1_13
    x3cc c1_8

    Aside from that, I think perhaps you have a misunderstanding about how inheritance works. "index" is not a shared variable between class instances; there is one instance of "index" for every class instance. Thus if you have 2 instances of c1, there are two separate memory locations for "index", one for the first instance of c1 and one for the second instance. If both class instances start with the same seed, then they will both generate the same sequence of values for "index".

    If you want a truly unique "index" that isn't reused in any instance of c, c1 or c2, then make "index" a static variable so that the memory is shared between all the class instances.

    As a final point, "SimVision" is the GUI debugger, the simulator is called Incisive. Slight smile

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • santhog
    santhog over 7 years ago in reply to StephenH

    Hi StephenH, Sorry for the wrong code. Somehow i might've missed while i was experimenting the code in my local system.

    Thanks for your explanation for inheritance, clearing my assumption in multiple objects of extended classes.

    Also i think, Static variable may not give unique values for multiple objects, as memory is shared.

    Anyway thanks , i've built a workaround for my requirement.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information