Using "with clause " for bins

Hi all ,

I am currently referring LRM Section 19.5.1.1 Coverpoint bin with covergroup expressions . I have a few questions related to it

(1) LRM has the following example ::


      coverpoint b
      { 
        bins func[] = b with ( myfunc(item) );  //  item  refers  to  each  possible  value  of  variable  b
      }
    

My understanding is myfunc would generally be complex code so instead of mentioning it in the with clause itself , it’s better to define it within a function

Section 19.5 further says :: Functions shall not contain output or non-const ref arguments (const ref is allowed)

This means that myfunc can’t return any value ? Will myfunc have to void type ?

[a] Can someone share a simple code on how I could define function myfunc ? Any basic logic within the function will be fine

Also  it  would  be  of  great  help  if  someone  could  explain  the  following  lines  from  LRM  19.5.1.1 ::

By default, the with_covergroup_expression is applied to the set of values in the covergroup_range_list prior to distribution of values to the bins. If the distribution of values is desired before with_covergroup_expression application, the distribute_first covergroup option (see 19.7.1 ) can be used to achieve this ordering. The result of applying a with_covergroup_expression shall preserve multiple, equivalent bin items as well as bin order. The intent of these rules is to allow the use of non-simulation analysis techniques to calculate the bin (for example, formal symbolic analysis) or for caching of previously calculated results.

In reply to Have_A_Doubt:

myfunc must return true or false, which means a 0 or non-zero integral value. The direction restriction (output) is on the function arguments, not the return value.

If you have a simple bin expression

bit [3:0] b;
coverpoint b
      { 
        bins func[4] = {[0:$]};
       }

That creates 4 bins with the first bin including the values 0-3, the next 4-7, 8-11, and 12-15
Now add the with expression
bins func[4] = b with (item < 12);

Does that just eliminate the last bin 12-15, or should the bins now be distributed in groups of 3 values 0-2, 3-5, 6-8, 9-11. The distribute_first options let you chose the method.

In reply to dave_59:

Dave ,

Have one more question .

We have 2 ways to generate bins based on a complex algorithm

(a) Defining an array of values with values as per complex algorithm via procedural code ( Reference ready-for-systemverilog-2012 )

(b) Defining the algorithm within the function called from with_covergroup_expression which returns true or false .

One key difference is for (a) the array is populated before instantiating covergroup .

[Q1] Given these 2 solutions are there any advantages of one over the other ? . When should a user prefer one over the other ?

( Function called from with_covergroup_expression can still access and assign non-local variables ( module variables , class properties ) , right ? )

In reply to Have_A_Doubt:

Use whatever method works best for your situation. And by best I mean the easiest for you and others to comprehend and maintain.