| View previous topic :: View next topic |
| Author |
Message |
kgopikrishna Senior


Joined: Feb 03, 2007 Posts: 312 Location: Bangalore,India
|
Posted: Thu Dec 20, 2007 8:58 pm Post subject: SV randomization() order |
|
|
| Code: | class A;
rand integer Var;
function void pre_randomize;
$display(" A PRE_RANDOMIZATION ");
endfunction
function void post_randomize;
$display(" A POST_RANDOMIZATION ");
endfunction
endclass
class B;
rand A obj_a;
function new();
obj_a = new();
endfunction
function void pre_randomize;
$display(" B PRE_RANDOMIZATION ");
endfunction
function void post_randomize;
$display(" B POST_RANDOMIZATION ");
endfunction
endclass
program pre_post_21;
B obj_b = new();
initial
void'(obj_b.randomize());
endprogram
|
This is what I thought for the above example.
Upon calling the randomize method of B object which contains rand A object, First B prerandomize is called, then A prerandomize method is called, then A is randomized, if a solution was found, new values are assigned to the random A objects properties . If solution was found, for each random object that is a class instance it's post_randomize method is called. That means if randomization is successful next B postrandomize functions is called.
Upon calling B randomize function this is sequence it follow.
B-Prerandomize --> A-prerandomize --> A.randomize --> A-postrandomize --> B-postrandomize
The results I got
| Quote: |
B PRE_RANDOMIZATION
A PRE_RANDOMIZATION
B POST_RANDOMIZATION
A POST_RANDOMIZATION
|
I expected
| Quote: |
B PRE_RANDOMIZATION
A PRE_RANDOMIZATION
A POST_RANDOMIZATION
B POST_RANDOMIZATION
|
Please explaing the order of the randomization flow for this example.
Thanks in Advance _________________ gopi@testbench.in
For SV/UVM/VMM/OVM tutorials ->> www.testbench.in |
|
| Back to top |
|
 |
chrisspear Senior


Joined: Jun 15, 2004 Posts: 202 Location: Marlboro, MA
|
Posted: Mon Dec 24, 2007 5:45 pm Post subject: |
|
|
The following is from the 2005 LRM, and appears to be unchanged in the 2008 draft.
| Quote: | | When obj.randomize() is invoked, it first invokes pre_randomize() on obj and also all of its random object members that are enabled. After the new random values are computed and assigned, randomize() invokes post_randomize() on obj and also all of its random object members that are enabled. |
Looks like b.pre_randomize() is called, then a.pre_randomize(), followed by randomize(), then b.post_randomize(), and a.port_randomize(). That matches what you saw.
Maybe you should pick up a copy of the standard? |
|
| Back to top |
|
 |
Dhaval Senior


Joined: Feb 16, 2006 Posts: 94
|
Posted: Wed Dec 26, 2007 7:15 am Post subject: |
|
|
| Isnt it necessary to call void'(a.randomize) to call pre and post randomize functions? if no then why? |
|
| Back to top |
|
 |
Boone Senior


Joined: Jan 12, 2004 Posts: 32
|
Posted: Wed Jan 02, 2008 9:24 pm Post subject: |
|
|
| Dhaval wrote: | | Isnt it necessary to call void'(a.randomize) to call pre and post randomize functions? if no then why? |
No; In class "B", data member obj_a is prefaced by "rand". It will have an implicit obj_a.randomize() call. |
|
| Back to top |
|
 |
Dhaval Senior


Joined: Feb 16, 2006 Posts: 94
|
Posted: Thu Jan 03, 2008 7:47 am Post subject: |
|
|
| Yes, you are right. My mistake. Its very simple. |
|
| Back to top |
|
 |
nachumk Newbie


Joined: Feb 28, 2012 Posts: 4 Location: Santa Clara, CA
|
Posted: Tue Feb 28, 2012 9:01 pm Post subject: Strongly agree with first poster's question |
|
|
| Seems like the SV standard should walk the elements backwards on post_randomize calls. Makes little sense to me to call the top object and then call post_randomize on its member objects. |
|
| Back to top |
|
 |
sharanbr Senior


Joined: Sep 27, 2004 Posts: 194
|
Posted: Tue Feb 28, 2012 9:58 pm Post subject: |
|
|
Folks,
Please bring me up to speed on SV randomization behavior ...
I was assuming that obj_a has to be explicitly randomized.
Is this new behavior of SV as I vaguely recall that explicit calls to randomization was necessary earlier ...
Some reference to LRM etc. would help ...
Regards,
Sharan |
|
| Back to top |
|
 |
dave_59 Senior


Joined: Jun 22, 2004 Posts: 974 Location: Fremont, CA
|
Posted: Wed Feb 29, 2012 3:27 am Post subject: |
|
|
| I'm pretty sure none of the LRM in this area has changed in a while. There is no implicit call to obj_a.randomize(). However, since obj_a is a rand variable member of obj_b, all of the rand variables in obj_a along with any of its constraints, had there been any, are randomized concurrently. See 18.4 Random Variables in the 1800-2009 LRM. |
|
| Back to top |
|
 |
sharanbr Senior


Joined: Sep 27, 2004 Posts: 194
|
Posted: Wed Feb 29, 2012 9:05 am Post subject: |
|
|
| dave_59 wrote: | | I'm pretty sure none of the LRM in this area has changed in a while. There is no implicit call to obj_a.randomize(). However, since obj_a is a rand variable member of obj_b, all of the rand variables in obj_a along with any of its constraints, had there been any, are randomized concurrently. See 18.4 Random Variables in the 1800-2009 LRM. |
thanks. i did realize after posting that a random class object is no different from any other rand property within the class ... |
|
| Back to top |
|
 |
|