Enable/Disable specific constraints:

In below example we can understand how we can enable or disable a specific constraint whenever we need to do.

class rmode; 
  rand int a; 
  rand int b; 
  constraint ct_a { a == 50;} 
  constraint ct_b { b == 100;} 

program main; 
  rmode rnd = new(); 
  initial begin 
    $display(" 1 : a : %0d,  b : %0d ",rnd.a, rnd.b);
    rnd.ct_a.constraint_mode(0); //disable constraint ct_a
    $display(" 2 : a : %0d,  b : %0d ",rnd.a, rnd.b);
    rnd.ct_a.constraint_mode(1); //enable constraint ct_a
    $display(" 3 : a : %0d,  b : %0d ",rnd.a, rnd.b); 

on Facebook on Google+

About the author

Avatar photo

The Art of Verification

Hi, I’m Hardik, and welcome to The Art of Verification.

I’m a Verification Engineer who loves to crack complex designs and here to help others commit to mastering Verification Skills through self-learning, System Verilog, UVM, and most important to develop that thought process that every verification engineer should have.

I’ve made it my mission to give back and serve others beyond myself.

I will NEVER settle for less than I can be, do, give, or create.

View all posts