Hi All ,
Section 18.5.12 of the LRM discuses about function call in constraints . One of the key points is :
Functions shall be called before constraints are solved, and their return values shall be treated as state variables.
It then gives an example :
class B;
rand int x, y;
constraint C { x <= F(y); }
constraint D { y inside { 2, 4, 8 } ; }
endclass
So y gets solved / picked before x i.e there is an implicit solving order.
If I were to change constraint to :
class B;
rand bit[3:0] y ,z ;
rand bit[4:0] x ;
constraint C { x <= Func2(); }
function int Func2();
y + z ;
endfunction
endclass
[Q1] In this casewould there still be an implicit solving/picking order ( although there are no input to the function ) ?
Section 13.2 of the LRM says :
“A nonvoid function can be used as an operand in an expression; the value of that operand is the value returned by the function.”
So another possible scenario is that Func2 ( or any function without input arguments in general ) relates to section 13.2 of the LRM rather then section 18.5.12.
This means that the constraint could be in-lined to :
constraint C { x <= int'( y + z ); }
Now there would be no implicit ordering between the 3 random variables .
[Q2] In case Func2() relates to section 13.2 of the LRM , are there any restrictions on what’s legal/illegal within the function ?
Section 18.5.12 has a list of restrictions for a function with input arguments called in a constraint . Eg : Static variable can’t be declared in such a function