Cross Bins and Select Expressions

Group cross products into named bins with binsof, intersect, the logical operators and with, and count the bins that remain.

You Will Be Able To

  • Select cross products with binsof, intersect, !, && and ||.
  • Count the bins of a cross that has user bins: the user bins plus the automatic bins they do not touch.
  • Filter cross products with with, and use explicit coverpoints where a tool cannot cross variables.
  • Recognise cross set expressions and the 1800-2023 additions, and their runnable equivalents.
Lesson
C17
Time
35 min
Runs on
Coverage build
Check
4 questions

A cross of 4 kinds by 4 length classes had 16 bins, and the review only cared about three groups of them. Someone wrote three user bins and expected a cross of 3 bins. The report showed 8, and the team spent a day hunting for the extra five. They were the automatic bins for products no user bin had named, kept by the standard on purpose.

kind \ lenonefewmanyfull
rdshort_rd, edge_lenshort_rdautoedge_len
wrwrites, edge_lenwriteswriteswrites, edge_len
cfgedge_lenautoautoedge_len
dbgedge_lenautoautoedge_len

The example's cross: each cell is a product; it belongs to the user bins named, or stays an automatic bin. 3 user bins + 5 automatic = 8 bins.

Binsof Selects Bins

binsof(k) stands for all the bins of coverpoint k; binsof(k.wr) for one bin. In a cross bin, it selects every product that uses those bins (IEEE 1800-2023 19.6.1).

bins writes = binsof(k.wr); in a cross of k and l is one bin made of four products: wr with each length class. Any of the four covers it.

Intersect Narrows by Value

binsof(l) intersect {[1:4]} keeps the bins of l whose values meet the set 1 to 4: here one and few. A bin counts if any of its values is in the set. !binsof(l) intersect {...} keeps the others.

Select expressionBins of l selected
binsof(l) intersect {[1:4]}one, few
binsof(l) intersect {4, 5}few, many: each holds one of the values
!binsof(l) intersect {[1:4]}many, full

Selection is by bin: a bin is in or out as a whole.

!, && and || Combine Selections

Select expressions combine with !, && and ||, and parentheses. && keeps products in both selections; || products in either.

Three User Bins over a 4 x 4 CrossThe example below. Arrows show which products each select expression gathers into a user bin; the products no user bin names stay automatic bins.
  • Neutral
  • Data
Three user bins over a 4 x 4 crossThe example below. Arrows show which products each select expression gathers into a user bin; the products no user bin names stay automatic bins. neutral All products 4 kinds x 4 lengths =16 neutral writes binsof(k.wr): 4 neutral short_rd rd && len 1-4: 2 neutral edge_len one || full: 8 neutral automatic the 5 untouched not named
  1. neutral All products4 kinds x 4 lengths = 16
    • writes
    • short_rd
    • edge_len
    • not named → automatic
  2. neutral writesbinsof(k.wr): 4
  3. neutral short_rdrd && len 1-4: 2
  4. neutral edge_lenone || full: 8
  5. neutral automaticthe 5 untouched
  1. A single selection

    binsof(k.wr) takes the write row: four products in one bin.

  2. && narrows

    binsof(k.rd) && binsof(l) intersect {[1:4]} keeps reads that are also 1 to 4 beats: two products.

  3. || widens

    binsof(l.one) || binsof(l.full) takes both edge columns: eight products. Products may sit in several user bins.

  4. What is left

    11 products are named by some user bin. The other 5 keep their automatic bins: 8 bins in all.

Read the diagram as text
  • All products: 4 kinds x 4 lengths = 16
  • writes: binsof(k.wr): 4
  • short_rd: rd && len 1-4: 2
  • edge_len: one || full: 8
  • automatic: the 5 untouched
  • All products → writes
  • All products → short_rd
  • All products → edge_len
  • All products → automatic: not named

A user bin is covered when any of its products is hit.

User Bins and the Automatic Bins That Remain

User cross bins and automatic cross bins live side by side. An automatic bin is kept for every product that no user bin selects (19.6.1). An ignore_bins or illegal_bins also removes its products; lesson C18 covers those.

1800-2023 adds the option cross_retain_auto_bins, 1 by default. Set to 0, it removes every automatic bin as soon as the cross has any user bin (19.7).

Cross of two 2-bin coverpoints, user bin i_zero = binsof(i) intersect {0}, sample i = 1, j = 0StandardCoverage build (measured)
default (cross_retain_auto_bins = 1): i_zero + 2 automatic3 bins, 1 hit: 44.44% overall44.44%
option.cross_retain_auto_bins = 0;: i_zero only1 bin, 0 hit: 33.33% overall44.44%: the option is ignored

The second row is standard behaviour, not run on this build. Scenario cov-2023-retain in docs/sva-standard-traces/CE.md.

With Filters Products

bins eq = x with (a == b); selects the products for which the expression holds, where a and b stand for the values of the crossed coverpoints. Naming the cross itself, x, starts from every product (19.6.1.2).

A product is selected if at least one of its value pairs satisfies the expression. matches N requires N pairs, and matches $ all of them.

Coverpoints a, b with bins lo = {[0:1]}, hi = {[2:3]}; bins m = x with (a + b >= 3)Products selectedCoverage build
default (one pair is enough)<lo,hi>, <hi,lo>, <hi,hi>agrees
... matches $ (every pair)<hi,hi> onlycompile error: matches not supported

The matches row is standard behaviour, not run on this build. Scenario cov-matches in docs/sva-standard-traces/CE.md.

Cross Set Expressions

A cross bin can also list its products as a queue of value tuples (19.6.1.4). Each cross has two implicit types: CrossValType, a struct with one member per coverpoint, and CrossQueueType, a queue of them (19.6.1.3). A function declared in the cross can build the queue.

A literal list

x: cross a, b {
  bins d = '{ '{0,0}, '{1,1}, '{2,2}, '{3,3} };
}

Standard: one bin of four products.

A function

x: cross a, b {
  function CrossQueueType diag();
    for (int k = 0; k < 4; k++) diag.push_back('{k, k});
  endfunction
  bins d = diag();
}

Standard: the same bin, built in code.

Bin d (the diagonal), sample a = 2, b = 2Standard (19.6.1.4)Coverage build (measured)
literal list13 cross bins, d hit: 19.23% overallcompile error
function returning CrossQueueType19.23%18.75%: d is ignored, all 16 automatic bins stay

Standard behaviour, not run on this build. Scenario cov-047 in docs/sva-standard-traces/CE.md.

Crossing Variables Directly

A cross may name variables instead of coverpoints: x: cross a, b; with no coverpoint lines. The standard then creates a coverpoint for each variable, with automatic bins, as if coverpoint a; had been written (19.6).

bit [1:0] a, b; x: cross a, b; sample a = 1, b = 2Standard (19.6)Coverage build (measured)
no coverpoints declareda 1/4, b 1/4, cross 1/16: 18.75%0.00%
coverpoint a; coverpoint b; declared first18.75%18.75%

The first row is standard behaviour, not run correctly on this build. Scenario cov-041 in docs/sva-standard-traces/CE.md.

Try It

The cross has 8 bins: 3 user bins and 5 automatic ones. The three packets hit one of each kind: an automatic bin, edge_len and short_rd.

After three packets each coverpoint has 3 of 4 bins and the cross 3 of 8: (75 + 75 + 37.5) / 3. Predict the last line if edge_len were removed.

RUNVerilator (coverage build) · simulator service
Edit the code, then run it
Expected: kind=2 len=6: 20.83% kind=3 len=8: 41.67% kind=0 len=3: 62.50%

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 { bins both = binsof(ca) intersect {1} && binsof(cb) intersect {1}; }
  endgroup
  cg c = new;
  initial begin
    a = 1; b = 1; c.sample();
    $display("%0.2f%%", c.get_inst_coverage());
  end
endmodule
ConceptA cross of two 4-bin coverpoints has one user bin bins w = binsof(a.wr);. How many cross bins does it have by default?
ConceptWhich select expression gives every product whose length bin does not include 1 to 4?
ConceptWhy does the lesson declare coverpoint a; coverpoint b; before x: cross a, b;, when the standard creates them implicitly?

Common Mistakes

Wrong Expect user cross bins to replace the whole cross.

Automatic bins are kept for every product no user bin selects, so the cross has more bins than you wrote.

Fix Count user bins plus the untouched products, or remove the rest with ignore_bins.

Wrong Build a cross bin with a function returning CrossQueueType on the coverage build.

The build compiles it and silently ignores the bin.

Fix Select the same products with with or binsof.

Before
bins d = diag();
After
bins d = x with (a == b);

Wrong Read binsof(l) intersect {4, 5} as "the values 4 and 5".

It selects whole bins of l that hold 4 or 5, with every value in them.

Fix Think in bins: intersect picks the bins whose values meet the set.

Remember

  • binsof selects coverpoint bins; intersect keeps the bins whose values meet a set; !, &&, || combine selections.
  • A user cross bin is covered by any of its products; products no user bin names keep automatic bins.
  • with selects products by an expression over the crossed values; matches sets how many value pairs must pass.
  • Cross set expressions list products as a CrossQueueType; the coverage build rejects or ignores them, so use with.
  • Declare coverpoints before crossing: the coverage build reads 0% for a cross of bare variables.

Practice

Report a problem with this page