Weighted constraints are soft constraints used to specify a non-uniform distribution of values. A weighted constraint specifies the relative probability that a particular value or set of values is chosen from the current range of legal values. Weighted constraints are specified using the keywords keep soft select. The current range is the range of values as reduced by hard constraints and by soft constraints that have already been applied.
A weighted value will be assigned with the probability of weight/(sum of all weights). Weights are treated as integers. Example 5-7 shows the specification of weighted constraints.
Example shows the distribution for opcodes in an instruction. <' type cpu_opcode: [ ADD, ADDI, SUB, SUBI, AND, ANDI, XOR, XORI, JMP, JMPC, CALL, RET, NOP ] (bits: 4); //Define opcode enumerated type struct instr { opcode: cpu_opcode; //Field opcode keep soft opcode == select { 30: ADD; // 30/60 probability that ADD is selected 20: ADDI; // 20/60 probability that ADDI is selected 10: [SUB..NOP]; // 10/60 probability SUB..NOP are selected //Note that the weights do not have to add up to 100. //They are simply relative weights. }; }; //End of struct instr '>