Explain the main types of constraint expressions in SystemVerilog—set mem…
Explain the main types of constraint expressions in SystemVerilog—set membership ( inside ), weighted distribution ( dist with := and :/ ), conditional ( -> and if...else ), inline ( with ), and soft constraints—with code examples.
Model answer
In SystemVerilog, **constraints** restrict random variable generation to meaningful stimulus values inside constraint blocks: 1. **Set Membership Constraint ( inside )**: Restricts a random variable to a set of discrete values or closed ranges: 2. **Weighted Distribution Constraint ( dist )**: Assigns relative weights to values or ranges using two operators: - := assigns the specified weight to **every individual value** in the range. - :/ divides the specified weight **equally across all values** in the range. 3. **Conditional Constraints (Implication -> and if...else )**: Applies a constraint when a boolean condition holds: 4. **Inline Constraint ( randomize() with )**: Adds extra call-site constraints at the point where randomize() is invoked without modifying the class definition: 5. **Soft Constraint ( soft )**: Defines a default constraint that is automatically overridden (instead of causing a solver failure) if a higher-priority hard constraint or inline with constraint conflicts with it: