Difficulty: Medium · Puzzle 4 of 6 · Topic: Coverage Options Puzzles
Compute each instance coverage and the type coverage. Options set: option.per_instance = 1, option.at_least = 2 (covergroup level, inherited by cp_err), type_option.merge_instances = 0 (type coverage is the weighted average of the instances; instance weights are 1). There is no type_option.at_least: at_least is an instance option.
covergroup cg with function sample(bit err);
option.per_instance = 1;
option.at_least = 2;
type_option.merge_instances = 0;
cp_err: coverpoint err {
bins zero = {0};
bins one = {1};
}
endgroup
initial begin
cg c0 = new();
cg c1 = new();
c0.sample(0);
c0.sample(1);
c1.sample(1);
c1.sample(1);
endEach bin of each instance needs 2 hits on its own. Then average the two instance numbers.
1) c0: zero has 1 hit, one has 1 hit, neither reaches 2 -> 0/2 = 0%.
2) c1: one has 2 hits and is covered, zero has 0 -> 1/2 = 50%.
3) With merge_instances = 0 the type coverage is the weighted average of the instances: (0 + 50) / 2 = 25%.Answer: c0 = 0%, c1 = 50%, type coverage = 25%.
Checked by running a model of the rule in a Python model. A model of the at_least rule: c0 never reaches 2 hits on a bin, c1 does on one bin, and the type average is 25%.
c0 touched both bins yet covers none of them, because one hit is below at_least = 2. The hits of c0 and c1 are not added up when merge_instances = 0, and writing type_option.at_least is not legal.
What is the minimum number of extra samples that makes every instance 100%? Model answer: Four: c0 needs one more 0 and one more 1 (2 samples), c1 needs two more 0 hits (2 samples). Both instances and the type are then 100%.
I would apply at_least to each instance separately. Instance c0 touched both bins but only once each, below the threshold of two, so it is 0 percent, and c1 is 50 percent. With merge_instances zero the type coverage is the average, 25 percent. The trap is adding the hits of both instances together, and writing type_option.at_least, which is not legal.