Calculate onehot bins for coverpoint

I have a 64bit register and I need to write coverage for all 64 onehot bins, so I thought that writing a with expression would have solved the issue, but it looks like this brute force approach is causing the tool to run for a long time (with no clear indication that it will finish!).

This is the code snippet:

bit [63:0] register;

covergroup mycg();
  my_cp: coverpoint register {
    bins onehot [] = register with ($onehot(item));
  }
endgroup

a 64bit register will have 2**64 combinations, which means the onehot function will need to run 2**64 times.

Is there any alternative way to achieve that?

Actually the answer was there already and it’s pretty straight forward:

bit [63:0] register;
typedef bit [63:0] reg_queue_t[$];

covergroup mycg();
  my_cp: coverpoint register {
    bins onehot [] = onehot();
  }
endgroup

function reg_queue_t onehot();
  reg_queue_t rq;
  for (int i=0; i<64; i++) begin
    rq.push_back(1'b1 << i);
  end
  return rq;
endfunction

The bins are created automatically when the covergroup gets created and a simple loop does the job.

I guess the use of with is more suited to filter/select elements rather than create them through brute force!

2 Likes