'WITH' Operator in SV Coverage

Hello guys,
Today we are going to see how we can use 'with' operator which is there in sv coverage. Many of us are writing coverage for our projects. I think most of us are under using the use of 'with' operator  in sv coverage. So lets explore one rarely explored feature which is already available for us in sv coverage.

SV LRM DESCRIPTION :

The with clause specifies that only those values in the covergroup_range_list that satisfy the given
expression (i.e., for which the expression evaluates to true, as described in 12.4) are included in the bin. In the expression, the name item shall be used to represent the candidate value. The candidate value is of the same type as the coverpoint.
The name of the coverpoint itself may be used in place of the covergroup_range_list to denote all values of the coverpoint. Only the name of the coverpoint containing the bin being defined shall be allowed; no other coverpoint names shall be permitted.

Consider the following examples:
 --------------------------------------------------------------------------------------------
Example 1 :
a: coverpoint x
{
bins mod3[] = {[0:255]} with (item % 3 == 0);
}
----------------------------------------------------------------------------------------------
This bin definition selects all values from 0 to 255 that are evenly divisible by 3.

 ---------------------------------------------------------------------------------------------
Example 2 :
my_b : coverpoint b
{
bins func[] = my_b with (myfunc(item));
}
----------------------------------------------------------------------------------------------
Note the use of the coverpoint name b to denote that the with_covergroup_expression will be applied to all values of the coverpoint.
Here all possible values of b will be apply to myfunc one by one and which ever are returning 1 will be created as  bin for coverpoint b. So basically one can put any logic inside this function and generates bins accordingly.

Let's see one example for creating one hot bins using user define function and with operator.
----------------------------------------------------------------------------------------------
Example 3 :

`define width 32 
bit [3:0] a;

cov_p : coverpoint a
  {
       bins walk_ones[] = cov_p with (onehot(item));
  }
function automatic onehot(bit [`width - 1:0] sgr);
  automatic int count;
   
  for(int i=0; i<`width; i++ ) begin
    if(sgr[i]==1) begin
      count++;
    end
  end

  if(count==1)
    return 1;
  else
    return 0;
endfunction : onehot
 ----------------------------------------------------------------------------------------------

Here we have used onehot function for creating one hot bins using with operator. We have designed logic inside onehot function which will return one if the value passed to it is onehot value otherwise it will return zero. In cover point bins will be created for only those values for which function is returning one. 

We can also use system task like $onehot and $countones instead of calling user define function.
  ----------------------------------------------------------------------------------------------
Example 4 :
 bit [3:0] a;

cov_p : coverpoint a
  {
       bins walk_ones[] = cov_p with ($onehot(item));
  }

 ----------------------------------------------------------------------------------------------

So basically we have developed one logic through user defined function or some system tasks you can have bins according to your logic.


Hope you guys enjoyed the article.
Thank You......

Comments

Popular posts from this blog

Difference Between m_sequencer and p_sequencer

Cross Auto Bin Max