Constraint Priority

In below SV code out of three constraint which have first priority i.e. which will execute first so that you can sure about output…

class slove_before;
  rand integer x,y;
  constraint C {x == 0; x > y; solve y before x; }
endclass

module s_b_59;
  slove_before obj ;
  initial
    begin
      obj = new();
      repeat(5)
      if(obj.randomize())
        $display(" x : %d :: y :%d ",obj.x,obj.y);
      else
        $display("Randomization failed ");
    end
endmodule

With reference to IEEE 1800-2012 Section-18.5.10,

Variables can be solved in an order that is not consistent with the ordering constraints, provided that the outcome is the same.

Here, ‘x==0’ is solved first since it leaves only single value of ‘x’ and it is not dependent on any other statement. Then ‘x>y’ is solved and ‘y’ is solved with some negative value.

Even though the last statement ‘solve y before x’ contradicts the actual solving order, none of the other variable solving statement has been contradicted. The final outcome is same even if ‘y’ was solved first. Hence, the last statement is of not significant over here.

In reply to sharvil111:

There is no ordering of constraints, they are all treated with equal priority (the way they get overridden though inheritance or by the using the ‘soft’ directive is another topic).

Effectively, the ‘solve before’ construct creates an ordering for picking values from the solutions space for each random variable.

Please see constrain random variable result to enumerated type | Verification Academy