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


Tutorials



CONSTRAINT MODE


Disabling Constraint Block



SystemVerilog supports to change the status of constraint block dynamically. To change the status of a Constraint block, built in constraint_mode() method is used. By default all the constraint blocks are active. When it is called as task, the arguments to the task determines the operation to be performed. If the arguments are 0 or 1, then all the constraints blocks are effected.



EXAMPLE:
class rand_mo;
rand integer Var1;
rand integer Var2;
constraint Var_1 { Var1 == 20;}
constraint Var_2 { Var2 == 10;}
endclass

program rand_mo_p_38;
rand_mo obj = new();
initial
begin
void'(obj.randomize()); //By default all constraints are active.
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
obj.constraint_mode(0); //Both constraints Var_1 and Var_2 are turned off.
void'(obj.randomize());
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
obj.constraint_mode(1); //Both constraints Var_1 and Var_2 are turned on.
void'(obj.randomize());
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
end
endprogram

RESULTS:

# Var1 : 20 Var2 : 10
# Var1 : 733126180 Var2 : -119008195
# Var1 : 20 Var2 : 10




If the arguments are Variable name, then only the status of that constraint block is changed.



EXAMPLE:
class rand_mo;
rand integer Var1;
rand integer Var2;
constraint Var_1 { Var1 == 20;}
constraint Var_2 { Var2 == 10;}
endclass

program rand_mo_p_38;
rand_mo obj = new();
initial
begin
void'(obj.randomize());
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
obj.Var_1.constraint_mode(0);
void'(obj.randomize());
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
obj.Var_1.constraint_mode(1);
void'(obj.randomize());
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
end
endprogram

RESULTS:

Var1 : 20 Var2 : 10
Var1 : 3w456456 Var2 : 10
Var1 : 20 Var2 : 10




When it is called as function, it returns the active status of the specified constraint block.



EXAMPLE:
class rand_mo;
rand integer Var1;
rand integer Var2;
constraint Var_1 { Var1 == 20;}
constraint Var_2 { Var2 == 10;}

endclass

program rand_mo_p_38;
rand_mo obj = new();
initial
begin
void'(obj.randomize()); //By default all constraints are active.
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
obj.Var_1.constraint_mode(0); //Both constraint Var_1 is are turned off.
void'(obj.randomize());
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
if (obj.Var_1.constraint_mode())
$display("Var_1 constraint si active");
else
$display("Var_1 constraint si inactive");

if (obj.Var_2.constraint_mode())
$display("Var_2 constraint si active");
else
$display("Var_2 constraint si inactive");

void'(obj.randomize());
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
end
endprogram


RESULTS:

Var1 : 20 Var2 : 10
Var1 : -2048772810 Var2 : 10
Var_1 constraint si inactive
Var_2 constraint si active
Var1 : -673275588 Var2 : 10





If you are changing the status of a constraint block, which is not existing, then there should be a compilation error else contact your Application engineer to file the bug.



EXAMPLE:
class rand_mo;
rand integer Var1;
rand integer Var2;
constraint Var_1 { Var1 == 20;}
constraint Var_2 { Var2 == 10;}
endclass

program rand_mo_p_38;
rand_mo obj = new();
initial
begin
void'(obj.randomize());
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
obj.Var_3.constraint_mode(0);
void'(obj.randomize());
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
if(obj.Var_3.constraint_mode())
$display(" Vat_1 constraint block is off");
void'(obj.randomize());
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
end
endprogram

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