Difficulty: Medium · Puzzle 4 of 6 · Topic: Coverage Closure and Sampling Timing Puzzles
During reset the state bus carries junk values. Compute cp_state coverage as written, and what it would be if the iff guard were missing. Options: none set (defaults); the only filter is the coverpoint iff (rst_n).
covergroup cg with function sample(bit rst_n, bit [1:0] state);
cp_state: coverpoint state iff (rst_n) {
bins s0 = {0};
bins s1 = {1};
bins s2 = {2};
bins s3 = {3};
}
endgroup
initial begin
cg c = new();
c.sample(0,3);
c.sample(1,0);
c.sample(1,1);
c.sample(0,2);
c.sample(1,1);
endA sample whose iff condition is false is ignored by that coverpoint entirely.
1) Samples with rst_n = 0 ((0,3) and (0,2)) are dropped by the iff guard.
2) Remaining samples are states 0, 1, 1 -> s0 and s1 hit.
3) Coverage = 2/4 = 50%.
4) Without the iff, 3 and 2 would also hit s3 and s2 -> 4/4 = 100%, a false closure.Answer: With the guard cp_state is 50% (s0, s1); without it 100%, because junk values seen in reset would fill s2 and s3.
Checked by running a model of the rule in a Python model. A model of the iff guard: samples taken during reset are dropped, so only s0 and s1 count.
iff is evaluated per coverpoint, so it filters only cp_state; other coverpoints in the same group would still sample during reset unless they carry their own guard. Reset-time junk is a classic source of fake 100% closure.
Besides iff on each coverpoint, how can you keep reset samples out of the whole covergroup? Model answer: Do not trigger the sample: put the condition in the covergroup event (covergroup cg @(posedge clk iff rst_n)) or call sample() from the monitor only when rst_n is high. Then every coverpoint and cross is protected without repeating the guard.
I would check what the guard filters. With the iff on reset, coverage is 50 percent, with only s0 and s1 hit. Without it, junk values on the bus during reset fill s2 and s3, and it would show a fake 100 percent. The trap is that iff is per coverpoint, so other coverpoints in the same group still sample during reset unless they have their own guard.