• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. Controlling generation

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 64
  • Views 13515
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Controlling generation

archive
archive over 18 years ago

Hello, I have a query in generation. Suppose if i need to generate a field based on other field, For example class gen; rand rw_wr; rand data; endclass in the above code i want to generate data only when rw_wr = 1 if rw_wr = '0' data should not be generated. For the above scenario how to write the generation constraint. Sundar


Originally posted in cdnusers.org by sundar_80
  • Cancel
Parents
  • archive
    archive over 18 years ago

    Sundar,

    See the example below.

    module randData;

    class inData;

    rand bit rw_wr;
    rand int data;

    constraint order_mode { solve rw_wr before data ;}

    constraint dataConstraint {
    rw_wr == 0 -> data == 0;
    rw_wr == 1 -> data inside {[0:100]};
    }
    endclass

    inData iData = new(); // Create an object iData of class inData with
    // seedequal to 100.

    task generateRandomvalues;
    int success;
    success = iData.randomize();

    if (success == 1)
    $display("Randomized the class members");
    else
    $display("Randomization failed");
    endtask

    task displayVal;
    $display("Rd_Wr is %b",iData.rw_wr);
    $display("Data is %d",iData.data);
    endtask

    initial begin
    #10;
    generateRandomvalues;
    displayVal;
    #10;
    generateRandomvalues;
    displayVal;
    #10;
    generateRandomvalues;
    displayVal;
    #10;
    generateRandomvalues;
    displayVal;
    #10;
    generateRandomvalues;
    displayVal;
    #10;
    generateRandomvalues;
    displayVal;
    end
    endmodule

    Here's how the output looks like

    ncsim> run
    SVSEED default: 1
    Randomized the class members
    Rd_Wr is 0
    Data is 0
    Randomized the class members
    Rd_Wr is 0
    Data is 0
    Randomized the class members
    Rd_Wr is 1
    Data is 91
    Randomized the class members
    Rd_Wr is 1
    Data is 37
    Randomized the class members
    Rd_Wr is 1
    Data is 54
    Randomized the class members
    Rd_Wr is 1
    Data is 14
    ncsim: *W,RNQUIE: Simulation is complete.


    -Vivek.


    Originally posted in cdnusers.org by prasad_vc
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • archive
    archive over 18 years ago

    Sundar,

    See the example below.

    module randData;

    class inData;

    rand bit rw_wr;
    rand int data;

    constraint order_mode { solve rw_wr before data ;}

    constraint dataConstraint {
    rw_wr == 0 -> data == 0;
    rw_wr == 1 -> data inside {[0:100]};
    }
    endclass

    inData iData = new(); // Create an object iData of class inData with
    // seedequal to 100.

    task generateRandomvalues;
    int success;
    success = iData.randomize();

    if (success == 1)
    $display("Randomized the class members");
    else
    $display("Randomization failed");
    endtask

    task displayVal;
    $display("Rd_Wr is %b",iData.rw_wr);
    $display("Data is %d",iData.data);
    endtask

    initial begin
    #10;
    generateRandomvalues;
    displayVal;
    #10;
    generateRandomvalues;
    displayVal;
    #10;
    generateRandomvalues;
    displayVal;
    #10;
    generateRandomvalues;
    displayVal;
    #10;
    generateRandomvalues;
    displayVal;
    #10;
    generateRandomvalues;
    displayVal;
    end
    endmodule

    Here's how the output looks like

    ncsim> run
    SVSEED default: 1
    Randomized the class members
    Rd_Wr is 0
    Data is 0
    Randomized the class members
    Rd_Wr is 0
    Data is 0
    Randomized the class members
    Rd_Wr is 1
    Data is 91
    Randomized the class members
    Rd_Wr is 1
    Data is 37
    Randomized the class members
    Rd_Wr is 1
    Data is 54
    Randomized the class members
    Rd_Wr is 1
    Data is 14
    ncsim: *W,RNQUIE: Simulation is complete.


    -Vivek.


    Originally posted in cdnusers.org by prasad_vc
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information