VLSI DV Interview Puzzles · All levels

Bin array math with mixed declarations

Compute total bin count and final percentage for this coverpoint with array bins and scalar bins.

Puzzle

Difficulty: Hard · Puzzle 3 of 6 · Topic: Covergroup and Coverpoint Puzzles

Compute total bin count and final percentage for this coverpoint with array bins and scalar bins.

Code

systemverilog
covergroup cg with function sample(bit [4:0] len);
  cp_len: coverpoint len {
    bins small[4] = {[0:15]};
    bins med      = {[16:23]};
    bins big[]    = {[24:31]};
  }
endgroup

initial begin
  cg c = new();
  c.sample(0);
  c.sample(7);
  c.sample(12);
  c.sample(18);
  c.sample(24);
  c.sample(26);
  c.sample(31);
end

Hint

small[4] gives 4 bins over 0..15, while big[] over 24..31 creates one bin per value.

Step-by-step solution

diagram
1) small[4] contributes 4 bins, med contributes 1, big[] contributes 8 -> total 13 bins.
2) Hits: small bins hit by 0,7,12 -> 3 of 4; med hit by 18 -> 1 of 1; big bins hit by 24,26,31 -> 3 of 8.
3) Total hit bins = 3 + 1 + 3 = 7.
4) Coverage = 7/13 = 53.85%.

Answer

Answer: Total bins = 13, hit bins = 7, so coverage is 53.85%.

Why candidates get it wrong

Many candidates treat big[] as one aggregated bin. Unsized array bins over a range create one bin per value.

Interviewer follow-up

If big[] were changed to bins big = {[24:31]}, what would the new percentage be with the same samples?

Related topics