User guide
24-83
SystemVerilog Testbench Constructs
A default constraint does not override other default constraints under
any condition. Thus, if you declare all constraint blocks as default,
then none of them will be overridden.
program P;
class C;
rand reg[3:0] x;
default constraint c1 {x == 0;}
endclass
class D extends C;
constraint d1 {x > 5;}
endclass
initial
begin
D d = new();
d.randomize();
d.d1.constraint_mode(0);
d.randomize();
end
endprogram
In the example, the default constraint in block c1 is overriden by the
non-default constraint in block d1. The first call to randomize picks a
value between 6 and 15 for x, since the non-default constraint is
applicable. The default constraint is ignored. The second call
switches off the non-default constraint, and a value of 0 will be
picked for x in the call to randomize because the default constraint is
applied.
program P;
class D;
rand reg[3:0] x;
reg y;
default constraint c1 {x >= 3; x <= 5;}
constraint d1 {y -> x > 5;}
endclass