Difficulty: Medium · Puzzle 3 of 6 · Topic: Coverage Options Puzzles
Compute c0.get_inst_coverage(), c1.get_inst_coverage() and the type coverage cg::get_coverage() with type_option.merge_instances = 1. Then say what the type coverage would be with merge_instances = 0. Options set: option.per_instance = 1 and type_option.merge_instances = 1 on the covergroup (at_least = 1, weight = 1).
covergroup cg with function sample(bit mode);
option.per_instance = 1;
type_option.merge_instances = 1;
cp_mode: coverpoint mode {
bins off = {0};
bins on = {1};
}
endgroup
initial begin
cg c0 = new();
cg c1 = new();
c0.sample(0);
c0.sample(1);
c1.sample(0);
endmerge_instances = 1 merges the bins of all instances (union of hits). merge_instances = 0 averages the instance coverages.
1) c0 hits off and on -> 2/2 = 100% instance coverage.
2) c1 hits only off -> 1/2 = 50% instance coverage.
3) With type_option.merge_instances = 1 the type coverage merges the instances: off is hit (by c0 and c1), on is hit (by c0) -> 2/2 = 100%.
4) With merge_instances = 0 (the LRM default) type coverage is the weighted average of the instances: (100 + 50) / 2 = 75%.Answer: c0 = 100%, c1 = 50%, type coverage with merge_instances = 1 is 100% (with merge_instances = 0 it would be 75%).
Checked by running a model of the rule in a Python model. A model of the LRM rule: merging pools the hits of both instances (100%), while averaging them gives 75%.
The merged type number says 100% while c1 never saw mode = 1. per_instance only makes instance data available for reporting; it is merge_instances that selects union versus average, so state it explicitly because tools do not all default alike.
How would results appear if option.per_instance were left at 0? Model answer: Instance coverage is not kept or reported per instance, so only the type-level number is visible (100% here with merge_instances = 1) and c1's hole is invisible. per_instance does not change the type number itself.
I would read the two instances separately: c0 is 100 percent and c1 is 50 percent. With merge_instances set to one, the type coverage is the union of both, so it is 100 percent, and with it set to zero it would be 75 percent, the average. The trap is that the merged 100 percent hides that c1 never saw mode 1. I would state merge_instances explicitly because tools differ in default.