|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



RANDOMIZATION CONTROLABILITY


Controlability



Additional to the controllability feauters supported by SystemVerilog, following are more points with which controlabiity can be achieved.

In the following example, MACROS MIN_D and MAX_D are defined. Set the MIN and MAX values in the pre_randomize as shown. As MIN_D and MAX_D are macros, they can be assigned from command line. Biggest disadvantage for the method shown below is dynamic controllability.



EXAMPLE:
`define MAX_D 100
`define MIN_D 50
class Base;
rand integer Var;
integer MIN,MAX;
constraint randge { Var < MAX ; Var > MIN ;}
function void pre_randomize ();
this.MIN = `MIN_D;
this.MAX = `MAX_D;
$display( " PRE_RANDOMIZE : MIN = %0d , MAX = %0d ",MIN,MAX);
endfunction
endclass

program inhe_42;
Base obj;
initial
begin
obj = new();
for(int i=0 ; i < 100 ; i++)
if(obj.randomize())
$display(" Randomization sucsessfull : Var = %0d ",obj.Var);
else
$display("Randomization failed");
end
endprogram


RESULTS:

# PRE_RANDOMIZE : MIN = 50 , MAX = 100
# Randomization sucsessfull : Var = 91
# PRE_RANDOMIZE : MIN = 50 , MAX = 100
# Randomization sucsessfull : Var = 93
# PRE_RANDOMIZE : MIN = 50 , MAX = 100
# Randomization sucsessfull : Var = 77
# PRE_RANDOMIZE : MIN = 50 , MAX = 100
# Randomization sucsessfull : Var = 68
# PRE_RANDOMIZE : MIN = 50 , MAX = 100
# Randomization sucsessfull : Var = 67
# PRE_RANDOMIZE : MIN = 50 , MAX = 100
# Randomization sucsessfull : Var = 52
# PRE_RANDOMIZE : MIN = 50 , MAX = 100
# Randomization sucsessfull : Var = 71
# PRE_RANDOMIZE : MIN = 50 , MAX = 100
# Randomization sucsessfull : Var = 98
...etc.




As in this example,a single object is created and randomized 100 times. Due to this,pre_reandomize is called 100 times, which may not be preferred.
By assigning the values while declaration itself this can be avoided. Simpler way to achieve the above logic.



EXAMPLE:
`define MAX_D 100
`define MIN_D 50
class Base;
rand integer Var;
integer MIN = `MIN_D;
integer MAX = `MAX_D;
constraint range { Var < MAX ; Var > MIN ;}
endclass

program inhe_43;
Base obj;
initial
begin
obj = new();
for(int i=0 ; i < 100 ; i++)
if(obj.randomize())
$display(" Randomization sucsessfull : Var = %0d ",obj.Var);
else
$display("Randomization failed");
end
endprogram

RESULTS:

# Randomization sucsessfull : Var = 91
# Randomization sucsessfull : Var = 93
# Randomization sucsessfull : Var = 77
# Randomization sucsessfull : Var = 68
# Randomization sucsessfull : Var = 67
# Randomization sucsessfull : Var = 52
# Randomization sucsessfull : Var = 71
# Randomization sucsessfull : Var = 98
# Randomization sucsessfull : Var = 69
# Randomization sucsessfull : Var = 70
...etc.



With the above approach also, dynamic controlability is lost. For dynamic controllability, define a task, pass this values as arguments when ever the changed is needed.



EXAMPLE:
class Base;
rand integer Var;
integer MIN = 10,MAX = 20; // Define default values,If function set is not called,with this it will work
constraint randge { Var < MAX ; Var > MIN ;}
task set (integer MIN,integer MAX);
this.MIN = MIN;
this.MAX = MAX;
$display( " SET : MIN = %0d , MAX = %0d ",MIN,MAX);
endtask
endclass

program inhe_44;
Base obj;

initial
begin
obj = new();
obj.set(0,100) ;
for(int i=0 ; i < 5 ; i++)
if(obj.randomize())
$display(" Randomization sucsessfull : Var = %0d ",obj.Var);
else
$display("Randomization failed");

obj.set(50,100) ;
for(int i=0 ; i < 5 ; i++)
if(obj.randomize())
$display(" Randomization sucsessfull : Var = %0d ",obj.Var);
else
$display("Randomization failed");
end
endprogram
RESULTS:

# SET : MIN = 0 , MAX = 100
# Randomization sucsessfull : Var = 24
# Randomization sucsessfull : Var = 68
# Randomization sucsessfull : Var = 43
# Randomization sucsessfull : Var = 11
# Randomization sucsessfull : Var = 4
# SET : MIN = 50 , MAX = 100
# Randomization sucsessfull : Var = 52
# Randomization sucsessfull : Var = 71
# Randomization sucsessfull : Var = 98
# Randomization sucsessfull : Var = 69
# Randomization sucsessfull : Var = 70




More simpler way to dynamically modifying the constraints is by modifying the data members of class via object reference.



EXAMPLE:
class Base;
rand integer Var;
integer MIN = 20,MAX =30;
constraint randge { Var < MAX ; Var > MIN ;}
endclass

program inhe_45;
Base obj;

initial
begin
obj = new();
obj.MIN = 0;
obj.MAX = 100;
for(int i=0 ; i < 5 ; i++)
if(obj.randomize())
$display(" Randomization sucsessfull : Var = %0d ",obj.Var);
else
$display("Randomization failed");
$display("MIN and MAX changed");

obj.MIN = 50;
obj.MAX = 100;
for(int i=0 ; i < 5 ; i++)
if(obj.randomize())
$display(" Randomization sucsessfull : Var = %0d ",obj.Var);
else
$display("Randomization failed");
end
endprogram

RESULTS:

# Randomization sucsessfull : Var = 24
# Randomization sucsessfull : Var = 68
# Randomization sucsessfull : Var = 43
# Randomization sucsessfull : Var = 11
# Randomization sucsessfull : Var = 4
# MIN and MAX changed
# Randomization sucsessfull : Var = 52
# Randomization sucsessfull : Var = 71
# Randomization sucsessfull : Var = 98
# Randomization sucsessfull : Var = 69
# Randomization sucsessfull : Var = 70

Index
Constrained Random Verification
Verilog Crv
Systemverilog Crv
Randomizing Objects
Random Variables
Randomization Methods
Checker
Constraint Block
Inline Constraint
Global Constraint
Constraint Mode
External Constraints
Randomization Controlability
Static Constraint
Constraint Expression
Variable Ordering
Constraint Solver Speed
Randcase
Randsequence
Random Stability
Array Randomization
Constraint Guards
Titbits

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright 2007-2017 :: all rights reserved www.testbench.in::Disclaimer