In reply to bmorris:
The solve before constraint is one of the most misunderstood constructs in SystemVerilog. It is not really a constraint in that it has no effect on the available solution set. It only effects the distribution in the choice of values among the available solutions.
If the three sets of instructions have an equal number of non-overlapping values, then solve before will have absolutely no effect, and can be removed without changing any results.
Without any constraints, there are 3 possible values for set, and 256 possible values for inst. The constraints give us 9 possible solutions, still with 3 values for set, but only 9 possible values for inst (because each value for set only allows 3 values for inst). If you look at the total possible allowed combinations of set and inst, you will see that each of the values of set are in the solution space 3 times.
Solution space
set inst
SET1 1
SET1 2
SET1 3
SET2 34
SET2 35
SET2 36
SET3 114
SET3 115
SET3 116
When you call randomize() without any solve before constraint, the solver will pick one of these solutions randomly with a uniform distribution. So the probability of of picking SET1 is 3/9 or 1/3rd. The probability of picking a value of any instruction is 1/9. If we change the example so that each set had 5 instructions, then the total number of solutions would go up to 15, but the probability of picking SET1 is still 5/15 or 1/3rd.
But now let’s change the example so that the number of instructions in each set is different. For example, SET1 has 3 instructions, SET2 has 7 instructions, and SET3 has 90 instructions. Now the total number of possible solutions is 100, and the probability of picking SET1 is 3/100 or 3%. The probability of picking a any particular instruction is 1/100. If we add the solve set before inst construct, that doesn’t change the fact that there are still only 100 possible solutions. Instead of picking a random solution from the collection of 100 possible, pick a value for set from the possible choices in the solution space first, eliminate the solutions that don’t have set with the value you picked, then proceed to pick a value for inst from the remaining solutions. By picking a value for set first, you now have a 1/3 probability of picking SET1, SET2, or SET3. But now the probability of picking one instruction from SET1 is (1/3)(1/3) or 1/9, and the probability of picking any instruction from SET3 is (1/3)(1/90) or 1/270.
Going back to the original example with
obj.randomize() with { inst == 1 };
This works without having to constrain set==SET1 because the 2 out of the 3 implication constraints could not be satisfied if set did not have the value SET1. (i.e. if set==SET2 then set==SET2 → inst inside {[34:36]}; cannot be satisfied if inst is constrained to 1. Also, thesolve set before inst has no effect because the total solution space is constrained to have only one value for set anyways.