Verification Guild
A Community of Verification Professionals

 Create an AccountHome | Calendar | Downloads | FAQ | Links | Site Admin | Your Account  

Login
Nickname

Password

Security Code: Security Code
Type Security Code
BACKWARD

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Modules
· Home
· Downloads
· FAQ
· Feedback
· Recommend Us
· Web Links
· Your Account

Advertising

Who's Online
There are currently, 50 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here

  
Verification Guild: Forums

 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile  ProfileDigest    Log inLog in 

SV randomization() order

 
Post new topic   Reply to topic    Verification Guild Forum Index -> Main
View previous topic :: View next topic  
Author Message
kgopikrishna
Senior
Senior


Joined: Feb 03, 2007
Posts: 312
Location: Bangalore,India

PostPosted: Thu Dec 20, 2007 8:58 pm    Post subject: SV randomization() order Reply with quote

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
View user's profile Send e-mail Visit poster's website
chrisspear
Senior
Senior


Joined: Jun 15, 2004
Posts: 202
Location: Marlboro, MA

PostPosted: Mon Dec 24, 2007 5:45 pm    Post subject: Reply with quote

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
View user's profile Send e-mail Visit poster's website
Dhaval
Senior
Senior


Joined: Feb 16, 2006
Posts: 94

PostPosted: Wed Dec 26, 2007 7:15 am    Post subject: Reply with quote

Isnt it necessary to call void'(a.randomize) to call pre and post randomize functions? if no then why?
Back to top
View user's profile Send e-mail Yahoo Messenger
Boone
Senior
Senior


Joined: Jan 12, 2004
Posts: 32

PostPosted: Wed Jan 02, 2008 9:24 pm    Post subject: Reply with quote

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
View user's profile
Dhaval
Senior
Senior


Joined: Feb 16, 2006
Posts: 94

PostPosted: Thu Jan 03, 2008 7:47 am    Post subject: Reply with quote

Yes, you are right. My mistake. Its very simple.
Back to top
View user's profile Send e-mail Yahoo Messenger
nachumk
Newbie
Newbie


Joined: Feb 28, 2012
Posts: 4
Location: Santa Clara, CA

PostPosted: Tue Feb 28, 2012 9:01 pm    Post subject: Strongly agree with first poster's question Reply with quote

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
View user's profile
sharanbr
Senior
Senior


Joined: Sep 27, 2004
Posts: 194

PostPosted: Tue Feb 28, 2012 9:58 pm    Post subject: Reply with quote

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
View user's profile
dave_59
Senior
Senior


Joined: Jun 22, 2004
Posts: 974
Location: Fremont, CA

PostPosted: Wed Feb 29, 2012 3:27 am    Post subject: Reply with quote

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
View user's profile Send e-mail Visit poster's website
sharanbr
Senior
Senior


Joined: Sep 27, 2004
Posts: 194

PostPosted: Wed Feb 29, 2012 9:05 am    Post subject: Reply with quote

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
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    Verification Guild Forum Index -> Main All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Verification Guild © 2006 Janick Bergeron
Web site engine's code is Copyright © 2003 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.197 Seconds