Calculate onehot bins for coverpoint

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