A constraint_expression is any Openvera expression or one of the constraint specific
operators, -> (Implication) and dist.
Set Membership
A set membership is a list of expressions or a range.This operator searches for the existences of the value in the specified expression or range and returns 1 if it is existing.
EXAMPLE: class set_mem{
randinteger Var;
constraint range { Var in {0,1,{50,60},{90,100}}; }
taskpost_randomize(){
printf("%0d__",Var);
}
}
program set_mem_p{
set_mem obj=new();
repeat(10)
void = obj.randomize();
}
RESULTS:
1__51__93__1__0__56__0__94__1__0__
If you want to define a range which is outside the set,use nagation.
EXAMPLE: class set_mem{
randbit [0:2] Var;
constraint range { !( Var in {0,1,5,6};)}
taskpost_randomize(){
printf("%0d__",Var);
}
}
program set_mem_p{
set_mem obj=new();
repeat(10)
void = obj.randomize();
}
RESULTS:
2__7__2__4__7__3__3__4__2__7__
Weighted Distribution
There are two types of distribution operators.
The := operator assigns the specified weight to the item or, if the item is a range, to every value in the range.
The :/ operator assigns the specified weight to the item or, if the item is a range, to the range as a whole. If
there are n values in the range, the weight of each value is range_weight / n.
Var dist { 10 := 1; 20 := 2 ; 30 := 2 }
The probabulity of having 10,20,30 is in the ration of 1,2,2 respectively.
Var dist { 10 := 1; 20 := 2 ; [30:32] := 2 }
The probabulity of having 10,20,30,31,32 is in the ration of 1,2,2,2,2 respectively.
If you use the := operator each element of the range has the assigned weight.
If you want to weight for the whole group,use :/ and the weight is distributed equally for each element in that group.
Var dist { 10 := 1; 20 := 2 ; [30:32] :/ 2 }
The probabulity of having 10,20,30,31,32 is in the ration of 1,2,2/3,2/3,2/3 respectively.
To demonstrate the distribution property,hear is an example.
EXAMPLE: class Dist{
randinteger Var;
constraint range { Var dist { {0,1} := 50 , {2,7} := 50 }; }
}
Both the reults show,how may times each value occured.
NOTE:If no wait is specified for items,the default weight is 1.
Weight 0 is also allowed.
NOTE:Variable declared as randc are not allowed int dist.
Implication
Implication operator can be used to predirect a relation.The syntax is expression -> constraint set.
If the expression is true,then the constraint solver should satisfy the constraint set.
The booliean equvalant of a -> b is (!a || b).
randbit a;
randbit [3:0] b;
constraint c { (a == 0) -> (b == 1); }
The probabulity of a = 0 is 1/2**5,as bidirectional constraints are solved at once,the solver pics the random value from the possible set of {a,b} which has 2**5 solutions.
EXAMPLE: class impli{
randbit Var;
randbit [3:0] b;
constraint c { (Var == 0) => (b == 1); }
}
Iterative constraints allow Constraining individual fixed-size, dynamic, associative, or queue elements.
foreach construct specifies iteration over the elements of array.
EXAMPLE: class Eth_pkt{
rand byte Payload[*] ;
constraint size_c { Payload.size() inside {[46:1500]}; }
constraint element_c { foreach ( Payload[ i ] ) Payload[ i ] inside {[50:100]}; }
}