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
         packet.addr_range.constraint_mode(0);

 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.

 Example-1: 


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; }
endclass

module static_constr;
  initial begin
    packet pkt1;
    packet pkt2;

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

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

 Simulator Output  

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