Cross coverage

Cross two coverpoints to cover combinations, remove the combinations that cannot happen, and predict how a cross changes the total.

Lesson
C5
Time
25 min
Runs on
Coverage build
Check
5 questions

The kind coverpoint was at 100% and the length coverpoint was at 100%, so the review signed off the packet link. Long writes had still never been sent: long packets were all reads, and writes were all short. Each coverpoint was complete on its own, and only their combination had a hole.

Every kind and every length, but not every combination
012345kindREADWRITECONFIGREADWRITEREADlength classlongshortoneshortcp_kind1/32/33/3cp_len1/32/33/3both coverpoints complete

One column per packet. Both coverpoints reach 100% by the third packet; WRITE/long never appears.

A cross covers combinations

A cross takes two or more coverpoints and makes one bin for every combination of their bins. cross cp_kind, cp_len with 3 kinds and 3 length classes gives 9 cross bins, and a cross bin is covered when both of its coverpoints hit their bins in the same sample.

cp_kind \ cp_lenoneshort_long_
READ53546
WRITE194247
CONFIG6ignore_binsignore_bins

The cross as a matrix, with the hits from the example's 200 packets. The two CONFIG cells can never be hit.

Combinations matter wherever the design handles them differently. A write of 8 beats fills the write buffer to its full depth, which neither a write of 2 beats nor a read of 8 beats does.

A cross can only combine coverpoints of the same covergroup, sampled together. That is one more reason to sample a whole transaction at once, through sample(packet p), rather than field by field.

Read the matrix in both directions. A row shows what one kind of packet exercised and a column what one length exercised. A hole at a particular row and column points to a constraint that couples them, like the leftover rule in lesson C1.

A cross needs much more stimulus than its coverpoints. Seven cells need at least seven packets, and in practice many more, because random stimulus repeats the common cells long before it reaches the rare ones.

The coverpoints in a cross can be expressions, such as coverpoint (len > 4), which is a quick way to keep a cross coarse.

Crosses grow fast. Two coverpoints of 3 bins make 9 cells; adding a third coverpoint of 4 bins makes 36. Cross only what the design treats as a combination, and keep the coverpoints in a cross coarse.

Removing impossible combinations

A CONFIG packet always has one beat, so CONFIG/short and CONFIG/long can never occur. Left in the cross, they cap its coverage at 7 of 9 cells, and the total never reaches 100% however good the stimulus is.

An ignore_bins inside the cross removes them. binsof selects cross cells by the bins of one coverpoint, intersect narrows to particular values, and &&, || and ! combine the selections.

Two impossible cells removed with one ignore_bins.
kind_x_len: cross cp_kind, cp_len {
  // CONFIG with anything but one beat cannot happen.
  ignore_bins config_multi = binsof(cp_kind) intersect {CONFIG}
                          && !binsof(cp_len.one);
}

Write the reason next to each ignore_bins, as the comment in the example does. A reviewer can then check it against the specification, and the next protocol change shows which exclusions to revisit.

Removing a cell is a decision about the specification. Never remove a cell only because the stimulus does not reach it, or a hole turns into a blind spot.

Use illegal_bins instead when a combination must never occur and you want a hit reported as an error. The cell is removed from the total either way.

How a cross changes the total

A cross counts as one more item in the covergroup's average, next to the coverpoints. With 100% on both coverpoints and 7 of 9 cross cells, the covergroup reports the average of 100, 100 and 77.78, which is 92.59%: the number the example prints for the cross without ignore_bins.

Because a cross has many more bins than its coverpoints, a few holes in it move the total only a little. A total of 95% can hide a cross that misses a whole kind of packet, so read the cross on its own when the total is below 100%.

The standard also allows user-defined cross bins, such as a single bin bins both = binsof(a) intersect {1} && binsof(b) intersect {1};. Every combination not claimed by a user bin or an ignore_bins still gets an automatic cell of its own.

When a cross gets too large, split it. Two crosses of two coverpoints each are easier to read and to close than one cross of four, and they usually ask the questions that matter.

The coverage build reports only whole covergroups, so the example prints totals and keeps its own hit matrix. A full coverage report also lists each cross cell, which is the view to use when closing holes.

Try it

The 200 random packets hit all 7 legal cells. With the impossible cells left in, the cross reaches 7 of 9 and the covergroup 92.59%; with them ignored, it reaches 100%.

Add with { kind == WRITE -> len <= 4; } to the randomize() call and predict both percentages.

RUNVerilator (coverage build) ยท simulator service
Edit the code, then run it
Expected: one short long READ 5 35 46 WRITE 19 42 47 CONFIG 6 0 0 all 9 cells: 92.59% impossible cells ignored: 100.00%

Check yourself

Predict the outputPredict the exact output.
module tb;
  bit wr;
  bit [2:0] len;
  covergroup cg;
    cp_wr:  coverpoint wr;
    cp_len: coverpoint len { bins one = {1}; bins short_ = {[2:3]}; bins long_ = {[4:7]}; }
    x: cross cp_wr, cp_len;
  endgroup
  cg c = new();
  initial begin
    wr = 0; len = 1; c.sample();
    wr = 1; len = 5; c.sample();
    wr = 0; len = 2; c.sample();
    $display("coverage=%0.2f", c.get_coverage());
  end
endmodule
Spot the bugEach option is the ignore_bins in the packet cross; the coverpoints have weight 0, so only the cross counts. The cross must reach 100% for stimulus with every legal combination, and stay below 100% when CONFIG packets are missing. Which option hides that hole?
ConceptHow many cross cells does cross a, b, c create when a, b and c have 2, 4 and 3 bins?
ConceptBoth coverpoints of a cross are at 100% and the covergroup total is 96%. What does that tell you?
ConceptA combination can never occur because of the protocol. Why remove it from the cross instead of leaving it?

Remember

  • A cross makes one cell per combination of its coverpoints' bins; the counts multiply.
  • Two complete coverpoints say nothing about their combinations; only a cross does.
  • Remove impossible cells with ignore_bins, selected with binsof, intersect, && and !.
  • A cross is one more item in the covergroup average, so read it on its own when the total is below 100%.