|
|
|
|
|
|
|
|
|
|
|
|
pre/post randomize()
|
|
|
Every class contains built-in pre_randomize() and post_randomize() tasks, that are automatically called by randomize() before and after it computes new random values. |
|
|
|
|
|
Syntax |
|
|
|
|
|
function void pre_randomize();
function void post_randomize();
|
|
|
|
|
|
When obj.randomize() is invoked, it first invokes pre_randomize() on obj and also all of its random object members that are enabled. Pre_randomize() then recursively calls super.pre_randomize(). |
|
|
|
|
|
Post_randomize() then recursively calls super.post_randomize(). You may overload the pre_randomize() in any class to perform initialization and set pre-conditions before the object is randomized. |
|
|
|
|
|
You may overload the post_randomize() in any class to perform cleanup, print diagnostics, and check post-conditions after the object is randomized. |
|
|
|
|
|
|
|
|
|
|
|
Example : pre/post randomize()
|
|
|
|
|
|
1 program pre_post_randomize;
2
3 class frame_t;
4 rand bit [7:0] data;
5 bit parity;
6 constraint c {
7 data > 0;
8 }
9 function void pre_randomize();
10 begin
11 $write("pre_randomize : Value of data %b and parity %b\n",data,parity);
12 end
13 endfunction
14 function void post_randomize();
15 begin
16 parity = ^data;
17 $write("post_randomize : Value of data %b and parity %b\n",data,parity);
18 end
19 endfunction
20 endclass
21
22 initial begin
23 frame_t frame = new();
24 integer i = 0;
25 $write("-------------------------------\n");
26 $write("Randomize Value\n");
27 $write("-------------------------------\n");
28 i = frame.randomize();
29 $write("-------------------------------\n");
30 end
31 endprogram
You could download file pre_post_randomize.sv here
|
|
|
|
|
|
Simulation Output : pre/post randomize()
|
|
|
|
|
|
-------------------------------
Randomize Value
-------------------------------
pre_randomize : Value of data 00000000 and parity 0
post_randomize : Value of data 00000110 and parity 0
-------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|