Difficulty: Medium · 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. Options: none set (all defaults: at_least = 1, weight = 1, auto_bin_max = 64).
covergroup cg with function sample(bit [4:0] len);
cp_len: coverpoint len {
bins lo[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);
endlo[4] gives 4 bins over 0..15, while big[] over 24..31 creates one bin per value.
1) lo[4] contributes 4 bins, med contributes 1, big[] contributes 8 -> total 13 bins.
2) Hits: lo bins hit by 0,7,12 (lo[0], lo[1], lo[3]) -> 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: Total bins = 13, hit bins = 7, so coverage is 53.85%.
Checked by running a model of the rule in a Python model. A model of the bin-array rule: lo[4] gives 4 bins, big[] gives 8, so 7 of 13 bins are hit.
big[] over [24:31] is eight bins (one per value), so three hits there are 3 of 8, not one aggregated bin. Counting big as a single bin would inflate the result to 5/6 = 83.33%.
If big[] were changed to bins big = {[24:31]}, what would the new percentage be with the same samples? Model answer: The coverpoint then has 4 + 1 + 1 = 6 bins and 5 are hit (lo[0], lo[1], lo[3], med, big), so 5/6 = 83.33%.
I would expand the array bins first: the total is 13 bins and 7 are hit, so coverage is 53.85 percent. The array over 24 to 31 gives eight bins, one per value, so three hits there are three of eight, not one bin. The trap is treating that array as a single bin, which would inflate the result to 83.33 percent. Next I would list which of the six uncovered bins are real holes.