Options That Change the Number

Weight the parts of a covergroup, demand several hits per bin, set goals, and know what per_instance does and does not change.

You Will Be Able To

  • Predict a covergroup's number when its coverpoints and crosses have different weights, including weight 0.
  • Require several hits per bin with option.at_least, at the level where the tool honours it.
  • Say why option.goal never changes the number.
  • Explain what option.per_instance controls, and read per-instance numbers with the right method.
Lesson
C23
Time
30 min
Runs on
Coverage build
Check
4 questions

A FIFO plan said "fill the FIFO completely at least five times". The covergroup had a full bin that one fill covered. It read 100% after the first fill, and a bug that needed the third fill shipped. A single option.at_least = 5; would have kept that bin open.

One hit covers a bin, unless at_least asks for more
01234times full12345full covered (at_least 1)yesfull covered (at_least 5)noyes
Scroll horizontally ↔

One column per time the FIFO fills. With the default of 1, the first fill closes the bin.

option.weight

A covergroup's number is the weighted average of its coverpoints and crosses (IEEE 1800-2023 19.11). Each item's option.weight defaults to 1. An item with weight 0 drops out of both the top and the bottom of the average.

Items (coverage, weight)Covergroup
a (100%, 1), b (0%, 1)50%
a (100%, 3), b (0%, 1)(300 + 0) / 4 = 75%
a (100%, 1), b (0%, 0)100 / 1 = 100%
a, b, cross with weight 2: 100%, 50%, 50%(100 + 50 + 100) / 4 = 62.5%

A weight set on the covergroup itself weights whole instances in the type number instead (19.11.3).

Weights in the AverageThe example below: three coverpoints, each with its coverage and weight. Arrows show what each adds to the top and bottom of the average.
  • Model
  • Data
Weights in the averageThe example below: three coverpoints, each with its coverage and weight. Arrows show what each adds to the top and bottom of the average. model common 3 of 6, weight 1 model rare 1 of 2, weight 3 model dir weight 0 model Covergroup (50 x 1 + 50 x 3) / 4= 50% 50 x 150 x 3left out
  1. model common3 of 6, weight 1
    • 50 x 1 → Covergroup
  2. model rare1 of 2, weight 3
    • 50 x 3 → Covergroup
  3. model Covergroup(50 x 1 + 50 x 3) / 4 = 50%
  4. model dirweight 0
    • left out → Covergroup
  1. Weighted items

    Each item adds its coverage times its weight to the top, and its weight to the bottom.

  2. Weight 0

    dir adds nothing to either side, so it can never move the number.

Read the diagram as text
  • common: 3 of 6, weight 1
  • rare: 1 of 2, weight 3
  • dir: weight 0
  • Covergroup: (50 x 1 + 50 x 3) / 4 = 50%
  • common → Covergroup: 50 x 1
  • rare → Covergroup: 50 x 3
  • dir → Covergroup: left out

The weights decide how much each hole costs in the final number.

If every item has weight 0, the bottom of the average is 0. The method then returns 0.0, or 100.0 if the covergroup's own weight is also 0 (19.11).

option.goal

option.goal is the target percentage for an instance, a coverpoint or a cross, 100 by default (19.7). Report tools compare the number against it. It does not change the number itself.

option.at_least

option.at_least = N; means a bin needs N hits to count as covered (19.7). Set in a coverpoint or cross, it applies there. Set in the covergroup, it is the default for every coverpoint and cross (Table 19-2).

Where at_least = 2 is set; samples 1, 1, 2Standard (19.7)Coverage build (measured)
in the coverpointone covered, two not: 50.00%50.00%
in the covergroupthe same default: 50.00%100.00%: ignored
in the coverpoint, from a covergroup argument50.00%100.00%: ignored

The last two rows are standard behaviour, not run on this build (scenarios cov-074 in docs/sva-standard-traces/CG.md and cov-053 in CF.md).

option.per_instance

Every instance contributes to its covergroup type's number. option.per_instance = 1; also asks the tool to keep each instance's own data in the coverage database and report (19.7). It can only be set in the covergroup definition.

MethodReturnsChanged by per_instance?
inst.get_inst_coverage()that instance's numberno
inst.get_coverage() or type::get_coverage()the type number over all instancesno
the coverage reporttype, plus each instance when per_instance is 1yes

per_instance decides what is saved and printed. The methods compute the same numbers either way.

So a per-port report must call get_inst_coverage() on each port's instance. get_coverage() returns the type number, the same for every port.

auto_bin_max, Once More

option.auto_bin_max also changes the number, through the bin count of coverpoints with no bins of their own (lesson C13). Set in the covergroup, it is the default for every such coverpoint; it does not apply to crosses (Table 19-2).

Try It

common has 6 bins at weight 1, rare 2 bins at weight 3, and dir weight 0. The first overflow is one hit short of at_least 2, so it changes nothing. The second covers overflow: rare goes to 50%, which weighs 3.

The underflow is one hit short too. After six samples: (3/6 x 1 + 1/2 x 3) / 4 = 50%. Predict the last line with option.weight = 1 in rare.

RUNVerilator (coverage build) · simulator service
Edit the code, then run it
Expected: ev=1: 4.17% ev=2: 8.33% ev=7: 8.33% ev=3: 12.50% ev=7: 50.00% ev=0: 50.00%

Check Yourself

Predict the outputPredict the exact output.
module tb;
  bit a, b;
  covergroup cg;
    ca: coverpoint a; cb: coverpoint b;
    x: cross ca, cb { option.weight = 2; }
  endgroup
  cg c = new;
  initial begin
    a = 0; b = 0; c.sample();
    a = 1; b = 0; c.sample();
    $display("%0.2f%%", c.get_inst_coverage());
  end
endmodule
ConceptA coverpoint has option.goal = 80; and three of its four bins are covered. What does get_inst_coverage() return for a covergroup with only that coverpoint?
ConceptA coverpoint has option.weight = 0; and no hits. What does it do to its covergroup's number?
ConceptA per-port report prints port_cov[k].get_coverage() for each port and shows the same number for all four. What is wrong?

Common Mistakes

Wrong Set option.at_least once in the covergroup on the coverage build.

The standard makes it the default for every coverpoint, but the build ignores it there.

Fix Set it in each coverpoint or cross that needs it.

Before
covergroup cg;
  option.at_least = 4;
  cp: coverpoint ev;
endgroup
After
covergroup cg;
  cp: coverpoint ev {
    option.at_least = 4;
  }
endgroup

Wrong Lower option.goal to make a report show a smaller hole.

The goal does not change the number; it only moves the line the report compares against.

Fix Fix the bins or the stimulus, and keep goals for real sign-off targets.

Wrong Read per-port numbers with get_coverage().

It returns the type number, the same for every instance.

Fix Call get_inst_coverage() on each port's instance.

Remember

  • A covergroup is the weighted average of its items, and weight 0 removes an item. All-zero item weights give 0.0, or 100.0 when the covergroup weighs 0.
  • option.goal is a target for reports and never changes the number.
  • option.at_least sets the hits a bin needs; on the coverage build set it per coverpoint or cross, as a constant.
  • option.per_instance controls what is saved and reported, not what the methods return.
  • get_inst_coverage() is one instance; get_coverage() is the type.

Practice

Report a problem with this page