Home > Community > Forums > Functional Verification > Overriding constraints

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 Overriding constraints 

Last post Thu, May 11 2006 5:21 AM by archive. 5 replies.
Started by archive 11 May 2006 05:21 AM. Topic has 5 replies and 1755 views
Page 1 of 1 (6 items)
Sort Posts:
  • Thu, May 11 2006 5:21 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    Overriding constraints Reply

    Using the example below, how can I override the constraints of classes A and B on an instance by instance basis?

    For instance, let's say I wanted a1's constraint of VarA0 to be VarA0 > 3 and b1's constraint of  VarB1 to be VarB1 < 5.  The point being that in general I want to use the default constraints provided by the class, but for some instances I want to override them.

    Thanks!


    module test();
      class A;
        rand bit [3:0] varA0;
        rand bit [3:0] varA1;

        constraint c0 { varA0 > 1; }
        constraint c1 { varA1 > 2; }
      endclass

      class B;
       rand bit [3:0] varB0;
       rand bit [3:0] varB1;

       constraint c0 { varB0 > 1; }
       constraint c1 { varB1 > 2; }
     endclass

      A a0=new;
      A a1=new;
      B b0=new;
      B b1=new;

    initial begin
      if (a0.randomize()==0) begin
        $display("error!");
      end
      if (a1.randomize()==0) begin
        $display("error!");
      end
      if (b0.randomize()==0) begin
        $display("error!");
      end
      if (b1.randomize()==0) begin
        $display("error!");
      end
      $display("a0.varA0=%d",a0.varA0);
      $display("a0.varA1=%d",a0.varA1);
      $display("a1.varA0=%d",a1.varA0);
      $display("a1.varA1=%d",a1.varA1);
      $display("b0.varB0=%d",b0.varB0);
      $display("b0.varB1=%d",b0.varB1);
      $display("b1.varB0=%d",b1.varB0);
      $display("b1.varB1=%d",b1.varB1);
    end   
     
    endmodule




    Originally posted in cdnusers.org by weberrm
    • Post Points: 0
  • Thu, May 11 2006 10:30 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: Overriding constraints Reply

    Hello!

    There are quite a few different ways to change constraints for a specific instance of the class. The easiest way to do it is to use the b1.randomize() with {constraint} notation.

    if (a1.randomize() with { varA0 > 3;})
    $display("a1.varA0=%d a1.varA1=%d", a1.varA0, a1.varA1)
    else $display("a1.randomize error");

    if (b1.randomize() with {varB1 <5;})
    $display("b1.varB0=%d b1.varB1=%d", b1.varB0, b1.varB1);
    else $display("b1.randomize error");

    The with {...} would have to be used each time you invoke randomize for that instance though. Other options are to use external constraint blocks - but those are class-specific. Or you can extend a class and only modify the constraints (overwrite a constraint or add an additional constraint). You also have the option to enable and disable constraints using the constraint_mode() methods.

    I hope that helps a little....

    Kathleen Meade
    (meade@cadence.com)


    Originally posted in cdnusers.org by kameade
    • Post Points: 0
  • Wed, Sep 20 2006 10:07 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: Overriding constraints Reply

    Attached is a presentation I created for random data generation which includes slides on overriding constraints.

    Tim


    Originally posted in cdnusers.org by tpylant
    • Post Points: 0
  • Tue, Apr 3 2007 9:39 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: Overriding constraints Reply

    Hello Tim, I am a new user for SV & while going thru the forum I found that u have attached a pdf, but that seems to be encrypted and I am unable to open it. Same is the case with "itp_pylant_generation.pdf" posted onto the forum. Is there any special way to open it. Could u plz help me out. Parag parag@txc.stpn.soft.net


    Originally posted in cdnusers.org by parag123
    • Post Points: 0
  • Wed, Apr 2 2008 6:30 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: Overriding constraints Reply

    Hi,
    I have written a brief article on soft constraints:
    http://www.aceverification.com/Soft%20Constraints%20for%20SystemVerilog.pdf
    Also, you can download Ace Verification's soft constraints for SV at the following link: http://www.aceverification.com/softconstraints_pkg.htm

    Akiva


    Originally posted in cdnusers.org by Akiva
    • Post Points: 0
  • Wed, Apr 2 2008 6:30 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: Overriding constraints Reply

    Hi,
    I have written a brief article on soft constraints:
    http://www.aceverification.com/Soft%20Constraints%20for%20SystemVerilog.pdf
    Also, you can download Ace Verification's soft constraints for SV at the following link: http://www.aceverification.com/softconstraints_pkg.htm

    Akiva


    Originally posted in cdnusers.org by Akiva
    • Post Points: 0
Page 1 of 1 (6 items)
Sort Posts:
Started by archive at 11 May 2006 05:21 AM. Topic has 5 replies.