Robert Schmidt
Robert Schmidt

Reputation: 33

Systemverilog: Bitwise cross of bitwise toggle coverage

Given two bit-vectors 'a' and 'b' I want to cover whether I have bitwise seen all all possible combinations of a and be. To be more precise, let us assume 'a' and 'b' are of length 2. Then, for i = 0, 1 I want to see the following combinations

a[i] == 0 && b[i] == 0,
a[i] == 0 && b[i] == 1,
a[i] == 1 && b[i] == 0,
a[i] == 1 && b[i] == 1.

Is there a concise way of doing this? Of course I could write

covergroup bitwise_toggle;
  a0: coverpoint a[0];
  a1: coverpoint a[1];
  b0: coverpoint b[0];
  b1: coverpoint b[1];

  aXb0: cross a0, b0;
  aXb1: cross a1, b1;
endgroup

But what if a and b are 32-bits long? Do I define 64 coverpoints and 32 covergroups? Since this is clearly undesirable and error-prone, I was wondering whether anybody has a better solution.

Upvotes: 2

Views: 3467

Answers (2)

Tiberius P.
Tiberius P.

Reputation: 74

Here's another solution if you want everything in a single covergroup:

covergroup bitwise_toggle with function sample(int bit_index, bit a_bit, bit b_bit);
    bit_index_cp : coverpoint bit_index {
      bins indexes[] = {[0:31]};
      option.weight = 0;
    };
    a_bit_cp : coverpoint a_bit { option.weight = 0; };
    b_bit_cp : coverpoint b_bit { option.weight = 0  };
    axb_cross : cross bit_index_cp, a_bit_cp, b_bit_cp;
endgroup

When the sampling event occurs, iterate over all the bits of a and b and call the covegroup's sample function:

bit[31:0] a;
bit[31:0] b;
for(int k = 0; k < 32; k++)
    bitwise_toggle.sample(i, a[i], b[i]);

axb_cross is the coverage metric you're interested in. The other coverpoints are auxiliary, that's why their weights are set to 0.

Upvotes: 0

dave_59
dave_59

Reputation: 42698

You could simplify the covergroup by writing

covergroup bitwise_toggle;
  aXb0: coverpoint {a[0],b[0]};
  aXb1: coverpoint {a[1],b[1]};
endgroup

Then you only need to define 32 coverpoints and no crosses for 32-bit variables. But you should explain further why this needs to be contained in a single covergroup. It would be much easier to write as multiple instances of a covergroup.

Update

To do this with multiple covergroup instances

covergroup bitwise_cg(string name) with function sample (bit [1:0] axb);
   option.per_instance = 1;
   option.name = name;
   coverpoint axb;
endgroup

bitwise_cg cg[32];
// construction of covergroups
foreach(cg[ii]) cg[ii] = new($sformatf("axb%0d",ii));
// sample of covergroups
foreach(cg[ii]) cg[ii].sample({a[ii],b[ii]});

Upvotes: 1

Related Questions