Contact / Report an issue

Constraint modes and Static Constraints

 Constraint Modes 

The constraint_mode() method can be used to disable any particular constraint block.By default constraint_mode value for all the constraint blocks will be 1.

constraint_mode() can be used as follow,
                    addr_range.constraint_mode(0); //disable addr_range constraint

 Static Constraints 

A constraint block can be defined as static, by including static keyword in its definition. static constraint addr_range { addr > 5; }

Any mode change of static constraint will afect in all the objects of same class type.


The Example below shows,
Disabling constraint, and disabling constraint mode in pkt1 is refleced in pkt2.

class packet;
  rand  bit [3:0] addr;

  static constraint addr_range { addr > 5; }

module static_constr;
  initial begin
    packet pkt1;
    packet pkt2;

    pkt1 = new();
    pkt2 = new();

    $display("\taddr = %0d",pkt1.addr);
    $display("\tAfter disabling constraint");
    $display("\taddr = %0d",pkt1.addr);
    $display("\taddr = %0d",pkt2.addr);

 Simulator Output  

addr = 14
After disabling constraint
addr = 2
addr = 6
Execute the above code on