Section 18.5.13 Soft constraints of the LRM mentions
class Packet;
rand bit mode;
rand int length;
constraint deflt {
soft length inside {32,1024};
soft mode -> length == 1024;
// Note: soft mode -> {length == 1024;} is not legal syntax,
// as soft needs to be followed by an expression
}
endclass
Assume there are additional 2 random properties: rand int depth; rand int width
If user wanted to club multiple constraints ( within{ } ) as part of implication constraint, they would typically write it as ::
When tested on the main three EDA tools ( 2025 version ), I observe that they treat the following as legal syntax ( although LRM explicitly mentions it as illegal )
Out of the 3 tools, one gives a warning. But they only work with simple forms that are easy to translate into the syntax I showed you. I think it’s because we all know how lazy SystemVerilog verification engineers are when it comes to writing code. I’d recommend sticking with the legal syntax form.
The restriction isn’t limited to the implication operator. The following is also illegal:
soft mode -> unique {length, width};
What might be confusing is that the -> operator is used to represent both the logical implication operator in a Boolean expression and a constraint expression. Constraint expressions are supersets of Boolean expressions.
(2) Sometimes, the -> symbol is not a logical implication operator. Just like the symbol <=, depending on the context, it could mean a non-blocking assignment or a less-than-or-equal. In a constraint, the syntax after the -> operator must be a Boolean expression for it to be considered a logical implication. Otherwise, it is considered a constraint implication.
(1) The soft keyword must be followed by a boolean expression, which is essentially an integral expression that can be compared to zero. On the other hand, unique {length, width} is not an expression; it is a constraint. Consequently, the expression mode -> unique {length, width} cannot be considered a logical expression.