Soft Constraints For SystemVerilog
Soft Constraints For SystemVerilog
Soft Constraints For SystemVerilog
By Akiva Michelson Ace Verification 2008 Ace Verification All rights reserved
Layered constraints:
In my experience, verification environments are most robust when they are built in a layered fashion. A. Component layer Absolute constraints of the class/object being constrained. B. Knobs layer Default values and distributions used in the current DUT's verification environment C. Test Layer Specific constraints for the current test (only if required) For example: In a packet generator there
Example of environment constraints: constraint env_c { pkt_length dist { 64 :/ 10 ; [65:128] :/ 60 ; [129:1000] :/ 30}; } Example of test constraints: constraint t1_c { pkt_length == 64; } In most cases these three level of constraints live in harmony. When the test does not add a constraint the 'default' environment constraints are used, and when the test does use a constraint the constraint overrides the environment constraint. The following examples show problems which may arise: Test1 constraint t2_c { pkt_length dist { 1200 :/ 10 ; [1201:1300] :/ 10 ; [1301:1500] :/ 10}; } Test2 constraint t3_c { pkt_length == 15; };
In both of these cases the test will contradict the environment constraints. In SystemVerilog the user is given the option to "turn off" the constraint. But this needs to be done in procedural code and the user needs to know the name of the constraint or constraints1.
Solution:
Ace Verification has developed a small library for providing pseudo soft constraints for SystemVerilog users. The package is available free of charge at the following link: http://www.aceverification.com/softconstraints_pkg.htm The library provides four macros which can be used as soft constraints. `soft_eq(<Variable>, <value>) // The variable is constraint to the value `soft_gt(<Variable>, <value>) // The variable is constrained to greater than the value `soft_lt(<Variable>, <value>) // The variable is constrained to less than the value `soft_rng(<Variable>,<value>) // Allows the user to define a 'soft' range for a variable For example:
class example2; rand bit [7:0] rand bit [7:0] b1; b2;
// Soft constraints (Can be overwritten by other constraints constraint c_1 { `soft_eq(b1,32); // b1 will be equal to 32 `soft_lt(b2,48); // b2 will be generated less then 48 } endclass
In my opinion turning off constraints is a poor programming practice which yields far more problems than it solves