User guide

24-96
SystemVerilog Testbench Constructs
class B;
rand integer x[$]; rand bit[1:0] k;
constraint b1 {
x.size() == k; k != 2;
foreach(x, i) {
$void(k-1) == i -> x[i] == 0;
}
}
endclass
The constraints x.size() = k; k != 2; are solved for, since the
use of the $void() function call renders k unconstrained in the
constraint inside the foreach loop.
The use of $void() in this example specifies that k is solved for
before any of the members of the x array.
The following example illustrates the other important semantic:
Example 24-5
class B;
rand integer x[$];
rand bit[1:0] k;
constraint b1 {
x.size() == $void(k);
k != 2;
foreach(x, i) {
k-1 == i -> x[i] == 0;
}
}
endclass
In this case, k has to be solved before x.size(), and x.size()
needs to be solved before expanding the foreach loop. Hence, there
is an implicit ordering between x.size() and x[i], requiring that
x.size() gets solved first. As a result, the sequence in which the
constraints will be solved:
1. k is solved for using the constraints k !=2.
2. x.size() is solved for using the constraints x.size() == k.