Hello,
I’ve written this following constraint.
//--------------------------------------------------------
class array ;
rand int unsigned len[];
constraint c_len {
foreach (len[i])
len[i] inside {[1:255]} ;
len.sum < 1024 ;
len.size() inside {[1:8]} ;
}
endclass
//--------------------------------------------------------
How constraint solver works? or How does the statements inside constraint gets execute and in which sequence? or How constraint solver solves the inter-dependency of variables inside constraint?
for eg. in above constraint size of the array should be randomize before the assignment of values using foreach loop.
but i’ve written len.size after assignment then also it’s working.
I mean how does it randomizes all the three things and in which order and can you please explain me w.r.t. timing?
//--------------------------------------------------------
class one;
rand int a, b, c, d;
constraint c_one {
b < a ;
a > 34 ;
d < c ;
c >= 23 ;
}
endclass
//--------------------------------------------------------
In this class one, variable b is dependent on variable a and the same case for variable d and c, respectively.
So, how the constraint solver will solve this inter-dependency of variables?
All the constraints inside the constraint solver runs parallely and they are “anded” together to get the constrained value.
For example in the second case : - CONSTRAINT LOGIC → b < a && a > 34 && d < c && c >=23. So each of a,b,c and d get random value based on the CONSTRAINT LOGIC
Prashant
Does it solve all the constraint statements at zero timestamp?
And what about first example i.e., array?
another query: if constraint like c_one is given
constraint c_one {(b=0) → (c=1) ;} //bit b, c ;
then how it’ll decide that firstly it has to solve b and then c? or how does it solve this constraint?
In reply to Mittal Maru:
Because randomize() is a function, it must execute with no delay. foreach loops get unrolled so that each iteration becomes a separate constraint.
The simplest way of explaining how the constraints work is to think of table with columns for each random variable, and a row for each possible combination of values that satisfy the constraints (where all constraint expressions evaluate true). After that, one row gets randomly picked, so all random variable values get selected at once.
Actually implementing it that way would be very inefficient. The LRM does not specify how to implement constrain solvers as long as the behavior essentially matches the simple description I gave.
There are cases where some random variables must get values before others, and the random size of an array is one one them.
In reply to dave_59:
In reply to Mittal Maru:
Because randomize() is a function, it must execute with no delay. foreach loops get unrolled so that each iteration becomes a separate constraint.
The simplest way of explaining how the constraints work is to think of table with columns for each random variable, and a row for each possible combination of values that satisfy the constraints (where all constraint expressions evaluate true). After that, one row gets randomly picked, so all random variable values get selected at once.
Actually implementing it that way would be very inefficient. The LRM does not specify how to implement constrain solvers as long as the behavior essentially matches the simple description I gave.
There are cases where some random variables must get values before others, and the random size of an array is one one them.
Hi Dave, you have given a wonderful example of table.
But please can you describe those cases where some random variables must get values before others?
And what about implication constraint mentioned below?
if constraint like c_one is given
constraint c_one {(b=0) -> (c=1) ;} //rand bit b, c ;
then how it’ll decide that firstly it has to solve b and then c? or how does it solve this constraint?
constraint c_one {(b=0) -> (c=1) ;}
Implication replaces boolean expression.
If want to know it, check SystemVerilog or PSL LRM.
You can download SystemVerilog LRM from IEEE Standards .
And,
But please can you describe those cases where some random variables must get values before others?
As to manage randomize order, check 18.5 in SystemVerilog LRM.
In reply to Mittal Maru:
Hi Maru
as Dave Clearly mentioned, there is no specific way as is told in LRM and there should be no need for it.
so you should understand only tools and their working
if the implication operator says “it is like some directive case if by randomization b comes 0 then take C’s value as 1.” that’s it.
if I consider b and c as 2-bit rand variables. and if you write constraints like below
constraint c1 { b=0 → c=1;}
so the constraint tool’s algorithm will understand by seeing your Coding that take any random value of b [0,1,2,3] and if it comes other than 0 , then take any random value of c [0,1,2,3]
but if b comes to 0 then take c’s value as 1
it is as simple as.