Home > Community > Forums > Functional Verification > Controlling generation

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: *

 Controlling generation  

Last post Tue, Aug 7 2007 5:17 AM by archive. 3 replies.
Started by archive 07 Aug 2007 05:17 AM. Topic has 3 replies and 1217 views
Page 1 of 1 (4 items)
Sort Posts:
  • Tue, Aug 7 2007 5:17 AM

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

    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
    • Post Points: 0
  • Tue, Aug 7 2007 6:26 AM

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

    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
    • Post Points: 0
  • Tue, Aug 7 2007 8:19 AM

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

    Hi Sundar.

    Bear in mind that if you declare a class item as being "rand", the simulator has to generate a value for it.
    Vivek's example shows one possible way to fix the data to a known value when you don't want a random value of data.
    However, this can impact performance.
    If you impose no constraints on the "data" item, the generator is free to just assign a totally random number to it, which is probably quite quick in terms of CPU cycles.
    Once you impose constraints on "data", that forces the simulator to so more work each time you call randomize: it has to check the order of generation, then check if the control field is set to 1 or 0, then find a value of "data" that fits the constraint.

    So before implementing this, ask yourself what's most important to you, and whether it's really necessary to "not generate" a value. After all, I assume you BFM (transactor) just ignores the data item if rw_wr == 0. In this case, you can safely let the generator pick any value for data, and you save some performance.

    It's also generally better to avoid any constraints that are not absolutely necessary, because this might limit future reuse of the class. Always try to leave scope for customisation in anything you do :-)


    Originally posted in cdnusers.org by stephenh
    • Post Points: 0
  • Wed, Aug 22 2007 4:28 PM

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

    The answer depends on your reason for asking this question. If your goal is to save generation effort by not randomizing "data", then perhaps the benefit gained by preventing the randomization of "data" is not worth the effort. If your goal is not to loose the value of "data" because of the randomization only when "rw_wr" is set to 0, then you can do this in multiple ways. If you want "rw_wr" to be generated first, then you can randomize "rw_wr" first, and depending on the result randomize the rest of the data object by explicitly using "randomize(data)". If you don't want to to impose an ordering because you feel such ordering may affect your randomization behavior, then you can save the content of "data" in a temporary variable by defining "pre_randomize()" and putting that value back into "data" by extending "post_randomize()". Sasan


    Originally posted in cdnusers.org by iman2418
    • Post Points: 0
Page 1 of 1 (4 items)
Sort Posts:
Started by archive at 07 Aug 2007 05:17 AM. Topic has 3 replies.