The first comparison, 34 <= var1, returns either 0 or 1. The second comparison therefore becomes either:
0 <= 43
or:
1 <= 43
Both are true, so the constraint does not actually restrict var1.
Could you please confirm whether my understanding is correct? Also, is there any other reason why chained relational expressions such as 34 <= var1 <= 43 should be avoided in SystemVerilog constraints?
Section 11.2 explains the operator precedence in SystemVerilog. Using the same operator (<=) results in evaluation from left to right, so your understanding is correct.
Constraints are evaluated as boolean expressions which are either 0 or 1, with only the true expressions being valid.
As long as you follow the operator precedence, you can create any expression you desire, but it’s usually better from a code readability standpoint to make simple expressions.
Thanks for the clarification. I’m aware that inside {[34:43]} is the preferred way.
My main doubt was only about how SystemVerilog evaluates:
34 <= var1 <= 43
Is it exactly treated as (34 <= var1) <= 43, where the first comparison gives 0 or 1, making the second comparison always true?
I just wanted to confirm whether this is the only reason it fails as a range check.