Automatic Bins, Default, Wildcard and With

Know the automatic bins, catch leftovers with default, match bit patterns with wildcard, and filter values with with.

You Will Be Able To

  • Count the automatic bins of an enum or integral coverpoint, with and without auto_bin_max.
  • Say why a default bin never raises or lowers the coverage number.
  • Write wildcard bins for bit patterns.
  • Filter a bin's values with with (item ...), and say when the filter runs.
Lesson
C13
Time
30 min
Runs on
Coverage build
Check
5 questions

A response covergroup sat at 0% after a full regression. Every response had been sampled. The bins were fatal = {8'b11xx_xxxx} and warn = {8'b10xx_xxxx}, written without wildcard, so they waited for a status whose low bits were really x. A two-state bench never produces one.

x in a Bin Is a Value, Unless the Bin Is Wildcard
012status110000011011111111110000fatal = {8'b11xx_xxxx}nowildcard fatalyesnoyeswildcard warnnoyesnothree responses, still 0% without wildcard
Scroll horizontally ↔
  1. Cycle 0

    A fatal response. A plain bin with x in it matches only a status with x in those bits (IEEE 1800-2023 19.5.4). Nothing counts.

  2. Cycle 2

    The same bins marked wildcard treat x, z and ? as "either bit". Now each response lands where the plan meant.

One column per sampled response. A 4-state x in a bin definition is compared exactly unless the bin is wildcard.

Automatic Bins

A coverpoint with no bins of its own gets automatic bins (IEEE 1800-2023 19.5.3). An enum gets one bin per name. Any other integral coverpoint of M bits gets the smaller of 2^M and auto_bin_max, which defaults to 64.

CoverpointAutomatic binsValues in each
enum with 3 names3one name each
bit [1:0]4one value each
bit [7:0]644 values each: auto[0:3], auto[4:7], ...
int642^26 values each
bit [2:0] with auto_bin_max = 33<0,1> <2,3> <4,5,6,7>: the last bin takes the rest

Automatic bins only count two-state values; a sample with x or z in it is not counted.

Automatic bins are fine for an enum or a narrow field. On a wide field they hide the question, as lesson C11 showed for a 32-bit address.

auto_bin_max

option.auto_bin_max = N; caps the number of automatic bins. Set it in the coverpoint, or in the covergroup as a default for every coverpoint (IEEE 1800-2023 19.7). It does nothing when the coverpoint lists its own bins.

When the cap is smaller than the number of values, the values are split in order. The last bin takes the rest, as for bins b[N].

Default Catches the Leftovers

bins rest = default; collects every value that no other bin holds. bins rest[] = default; makes one bin per such value. Neither counts toward coverage, and default bins are left out of crosses (IEEE 1800-2023 19.5).

A Default Bin Sits Outside the TotalA coverpoint with bins one = {1}, two = {2} and rest = default. Arrows show where samples go and what the total counts.
  • Step
  • Neutral
  • Result
  • Data
CallValueReturnWaiting
A default bin sits outside the totalA coverpoint with bins `one = {1}`, `two = {2}` and `rest = default`. Arrows show where samples go and what the total counts. step sample one value neutral bins one {1} neutral bins two {2} neutral bins rest default result Coverage covered of 2
  1. step sampleone value
    • bins one
    • bins two
    • bins rest
  2. neutral bins one{1}
    • Coverage
  3. result Coveragecovered of 2
  4. neutral bins restdefault
  5. neutral bins two{2}
    • Coverage
  1. A planned value

    A 1 lands in one, which counts toward the total: 1 of 2.

    Follow the calls, values and waits
    1. data 1: sample → bins one
  2. An unplanned value

    A 9 matches no bin, so it lands in rest. The total does not change.

    Follow the calls, values and waits
    1. data 9: sample → bins rest
Read the diagram as text
  • sample: one value
  • bins one: {1}
  • bins two: {2}
  • bins rest: default
  • Coverage: covered of 2
  • sample → bins one
  • sample → bins two
  • sample → bins rest
  • bins one → Coverage
  • bins two → Coverage

A default bin shows that unplanned values occurred, in the report. It never moves the number.

Use a default bin to see unplanned values in a report. It is not a way to raise coverage, and it cannot be ignored with ignore_bins.

Wildcard Bins Match Bit Patterns

A wildcard bin treats every x, z or ? in its values as "0 or 1" (IEEE 1800-2023 19.5.4). wildcard bins hi = {4'b11??}; is covered by 12, 13, 14 or 15. wildcard bins hi[] = {4'b11??}; makes four bins, one per match.

x without wildcard

bins hi = {4'b11xx};

Matches only a sample whose low bits are really x. A two-state bench never makes one.

wildcard

wildcard bins hi = {4'b11??};

Matches 12 to 15. A sample with x or z in it is not counted.

Strictly, a bin value with x or z also draws a warning and takes no part in the bin (19.5.7). The bin is then empty and drops out. Either way, it never counts a two-state sample.

Wildcard bins suit flag and status fields, where only some bits matter. They also work in transition bins, as lesson C16 shows.

With Filters a Bin's Values

bins e[] = {[0:15]} with (item % 2 == 0); keeps only the values for which the expression is true. item stands for each candidate value. The coverpoint's own name can stand for all its values: bins m3[] = cp with (item % 3 == 0); (IEEE 1800-2023 19.5.1.1).

BinValues keptBins
e[] = {[0:15]} with (item % 2 == 0)0, 2, 4, ..., 148
m3[] = cp with (item % 3 == 0) on 4 bits0, 3, 6, 9, 12, 156
q[3] = {[0:8]} with (item % 2 == 0)0, 2, 4, 6, 8, then dealt into 3<0> <2> <4,6,8>

The filter runs once, when the instance is built, and before values are dealt into a fixed number of bins.

The order matters for [N] bins: the filter first, then the spread. type_option.distribute_first reverses it; lesson C25 shows that option.

Try It

Three coverpoints, averaged: err has 2 counted bins, even 8 and tags 4. The first response covers fatal (1 of 2), e[2] (1 of 8) and the tag bin 0-3 (1 of 4). That is (50 + 12.5 + 25) / 3 = 29.17%.

The second response adds nothing counted. Status 0 goes to other, length 3 is filtered out, and tag 1 shares tag 0's bin. The third covers warn, e[4] and the tag bin 8-11: (100 + 25 + 50) / 3 is 58.33%. Predict the last line with auto_bin_max removed from tags.

RUNVerilator (coverage build) · simulator service
Edit the code, then run it
Expected: status=11000001 len=2 tag=0: 29.17% status=00000000 len=3 tag=1: 29.17% status=10111111 len=4 tag=9: 58.33%

Check Yourself

Predict the outputPredict the exact output.
module tb;
  bit [2:0] v;
  covergroup cg;
    coverpoint v { option.auto_bin_max = 3; }
  endgroup
  cg c = new;
  initial begin
    v = 5; c.sample();
    v = 7; c.sample();
    $display("%0.2f%%", c.get_inst_coverage());
  end
endmodule
Spot the bugEach option is the bins line of a coverpoint on a 4-bit status. The test samples 12 and 14 and must reach exactly 50%. Which option misses?
ConceptA coverpoint has bins one = {1}; bins two = {2}; bins rest = default;. Every sample is 7. What is its coverage?
ConceptWhen is the expression in bins e[] = {[0:255]} with (item % 2 == 0); evaluated?
ConceptWhich coverpoint gets 64 automatic bins?

Common Mistakes

Wrong Write x or ? in a bin to mean "any bit" without the wildcard keyword.

A plain bin compares x and z exactly, so a two-state sample never matches it.

Fix Mark pattern bins wildcard.

Before
bins fatal = {8'b11xx_xxxx};
After
wildcard bins fatal = {8'b11??_????};

Wrong Add a default bin to "catch everything" and expect the number to rise.

Default bins never count toward coverage.

Fix Use a default bin to see unplanned values in the report, and plan real bins for what matters.

Wrong Assume an 8-bit coverpoint with no bins has one bin per value.

The default cap of 64 puts four values in each automatic bin.

Fix List bins, or set option.auto_bin_max to the number of values you want counted separately.

Remember

  • Automatic bins: one per enum name, otherwise min(2^M, auto_bin_max), with the last bin taking the remainder.
  • option.auto_bin_max defaults to 64 and only affects coverpoints with no bins of their own.
  • Default bins collect unplanned values and never count toward coverage.
  • wildcard turns x, z and ? into "either bit"; without it they are compared exactly.
  • with (item ...) filters a bin's values when the instance is built, before a fixed count is dealt.

Practice

Report a problem with this page