One Hot encoding

Hi,

I want to write coverage on the basis of One Hot Encoding.

For example

ABC : coverpoint @ ( ADD) // ADD is [4:0]
{
bins a = {00001};
bins b = {00010};
bins c = {00100};
bins d = {01000};
bins e = {10000};
}

Value of ADD is depend on the no of slaves in our environment . If no of slave is 1 then its value is 1 .But if number of slave is 2 then we generate ADD either 00001 or 00010.In this case bins c,bins d,bins e is not hitted & my coverage is not covering 100%. How i control on bins on the basis of ADD value?

Is another way is possible to write coverage of one hot encoding? Please reply me
, if its is 2 then its value will be 00010 .But when its value will

This is very similar to the other issue just posted here. You need to model each slave as a separate covergroup instance.

covergroup onehot_cg(input bit  position, ref bit  vector);
  encoding: coverpoint ((1'b1<<position) & vector) != 0 {
    bins hit = { 1 };
  }
  option.per_instance = 1;
endgroup
 
onehot_cg cgi[NSLAVES];
 
foreach (cgi[i]) cgi[i] = new(i,ADD);

In reply to dave_59:

Hi Dave,
I didnt understand ,Please explain it .

In reply to Kuldeep:

Many people think they want to control the number of bins they have in a covergroup, but it’s much easier to control the number of covergroups that you have. If each covergroup has 1 bin, then you create as many covergroup instances as you have slaves.

BTW, there will be an enhancement to the 1800-2012 SV LRM that will make it easier to program bin construction, but it will be at least a year before you will see it implemented.

In reply to dave_59:

Had to make a couple small modifications to Dave’s example:

`define WIDTH 5

covergroup onehot_cg(input integer position, ref bit [`WIDTH-1:0] vector);
  encoding: coverpoint ((1'b1<<position) & vector) != 0 {
    bins hit = { 1 };
  }
  option.per_instance = 1;
endgroup

class my_coverage_class;

  // The bus that requires one hot encoding coverage
  bit [`WIDTH-1:0] my_bus;

  onehot_cg cgi[`WIDTH];

  function new;
    foreach (cgi[i]) cgi[i] = new(i,my_bus);
  endfunction
  
endclass: my_coverage_class

In reply to victorl:

Actually, it only took 6 months to see the new 1800-2012 covergroup syntax implemented. The example now can be written as:

class my_coverage_class #(int WIDTH);
 
  // The bus that requires one hot encoding coverage
  bit [WIDTH-1:0] my_bus;

  // array to hold one-hot encodings
  bit [WIDTH-1:0] onehots[WIDTH];
  covergroup onehot_cg;
    coverpoint my_bus {
       bins selected[WIDTH] = onehots;
    }
   endgroup
   function new;
     foreach(onehots[i]) onehots[i] = 1'b1 <<i;
     onehot_cg = new;
   endfunction
endclass

In reply to dave_59:

I know this is old, but I’m trying to get this to work. I’m checking my vendor for support also, but quick question:

I’ve modified the above so that ‘onehots’ holds the typical wildcard/walking 1’s pattern (e.g., ???1, ??1?, ?1??, 1???, which is so ugly for anything wide)

So the loop in new could become:

foreach (onehots[i]) begin
  onehots[i] = { WIDTH { 1'bx }};
  onehots[i][i] = 1'b1;
end

Then I made ‘bins’ be ‘wildcard bins’. It compiles, but no coverage is generated. Again, I’m checking vendor… but question is:

should this work with ‘wildcard bins’ and what I’ve shown?

Thanks!

In reply to jkam:

Yes, the BNF specifically mentions [wildcard] as optional in a set_covergroup_expression

BTW, you can write onehots[i] = 'x;