Value Bins
Declare value bins exactly: one bin for a set, one per value, a fixed count, open ranges and guarded bins.
You Will Be Able To
- Choose between
bins b,bins b[]andbins b[N]and count the bins each creates. - Work out which values land in each bin of a fixed-count array.
- Use
$ranges and a bin-leveliffguard. - Predict which bin values a coverpoint drops because its type cannot hold them.
- Lesson
- C12
- Time
- 30 min
- Runs on
- Coverage build
- Check
- 5 questions
An address coverpoint declared bins page[4] = {[0:255]}; was meant to catch the four pages of a 1 KB map. The address was 10 bits wide, so pages 1 to 3 lay above 255 and were never in any bin. The coverpoint read 100% after a few accesses to page 0, and three pages went untested.
- Cycle 0
page[4] = {[0:255]}spreads 256 values over 4 bins of 64. Address 10 hitspage[0]. - Cycle 3
Four accesses inside the first page fill all four bins. The coverpoint reads 100%.
- Cycle 4
Addresses 400 and 700 are in pages 1 and 2, but no bin holds them. The number cannot show the missing pages.
One column per sample. The bins split the wrong range: each should have held one 256-byte page.
A Scalar Bin Collects a Set
bins name = {set}; makes one bin. Any value in the set covers it. The set is a list of values and ranges, as in {0, [4:7], 12}.
Use a scalar bin when the design treats every value of the set the same way. One hit on any value is enough.
Array Bins Make One Bin per Value
bins name[] = {set}; makes one bin for each value in the set, named name[value]. A value listed twice still gets one bin (IEEE 1800-2023 19.5.1).
| Declaration | Bins created | Names |
|---|---|---|
bins b = {[2:5]}; | 1 | b |
bins b[] = {[2:5]}; | 4 | b[2], b[3], b[4], b[5] |
bins b[] = {[2:5], [4:6]}; | 5 | b[2] to b[6]: 4 and 5 once each |
bins b[2] = {[2:5]}; | 2 | b[0] holds 2, 3; b[1] holds 4, 5 |
The brackets after the name decide how many bins one line makes.
A Fixed Number of Bins, and How Values Are Spread
bins name[N] = {set}; makes N bins, name[0] to name[N-1]. The values are dealt out in the order written (IEEE 1800-2023 19.5.1).
List the values
Expand the set in order, keeping duplicates.
{[1:10], 1, 4, 7}is 13 values.Work out B
B is the number of values divided by N, rounded down, but at least 1. For 13 values in 4 bins, B is 3.
Deal B values to each bin
The first three go to
b[0], the next three tob[1], and so on.The last bin takes the rest
b[3]gets 10, 1, 4 and 7. Value 1 is now inb[0]andb[3].
bins b[4] = {[1:10], 1, 4, 7}. Arrows show values going to bins: B = 13 / 4 = 3 at a time, and the last bin takes the rest.- Neutral
- Data
- Three at a time
B is 3, so the first three values go to
b[0], the next three tob[1], thenb[2].Follow the calls, values and waits
- data 1 2 3: Value list → b[0]
- data 4 5 6: Value list → b[1]
- data 7 8 9: Value list → b[2]
- The rest to the last bin
Four values are left: 10 and the repeated 1, 4, 7. All go to
b[3].Follow the calls, values and waits
- data 10 1 4 7: Value list → b[3]
- One sample, two bins
Value 1 is now in
b[0]and inb[3]. A single sample of 1 covers both: 50%.
Read the diagram as text
- Value list: 1..10, then 1, 4, 7
- b[0]: 1, 2, 3
- b[1]: 4, 5, 6
- b[2]: 7, 8, 9
- b[3]: 10, 1, 4, 7
- Value list → b[0]
- Value list → b[1]
- Value list → b[2]
- Value list → b[3]
Duplicates are kept when values are dealt into a fixed number of bins (IEEE 1800-2023 19.5.1).
| Declaration | B | Bins |
|---|---|---|
b[4] = {[1:10], 1, 4, 7} | 3 | <1,2,3> <4,5,6> <7,8,9> <10,1,4,7> |
b[3] = {[0:7]} | 2 | <0,1> <2,3> <4,5,6,7> |
b[5] = {1, 4, 7} | 1 | <1> <4> <7> < > < >: two empty bins |
b[4] = {[4:127]} | 31 | <4..34> <35..65> <66..96> <97..127> |
The spread is not "even" in the everyday sense: the last bin takes whatever is left over.
An empty bin has no value, so it is left out of the coverage number altogether (IEEE 1800-2023 19.11.1). b[5] = {1, 4, 7} behaves as three bins.
Open Ranges with $
$ in a range stands for the smallest or largest value the coverpoint can hold. [128:$] on an 8-bit address means 128 to 255; [$:3] means 0 to 3.
Use $ for "everything above" or "everything below". The bin then follows the coverpoint if its width changes.
Set-Expression Bins
IEEE 1800-2023 19.5.1.2 lets a bin take its values from an array: bins op[] = OPCODES;. The array can be fixed, dynamic or a queue, of any integral element type; an associative array is not allowed. It is read when the covergroup instance is built.
| Program | Standard (19.5.1.2) | Coverage build (measured) |
|---|---|---|
int SETV[4] = '{1, 3, 5, 7}; with bins s[] = SETV;, samples 1, 3, 4 | 4 bins, 2 hit: 50.00% | compile error: "expecting with" |
the same with bins s = SETV; | one bin for all four values | compile error |
Standard behaviour, not run on this build. Scenario cov-018 in docs/sva-standard-traces/CC.md.
A Guard on One Bin
An iff at the end of a bin guards that bin only: bins wr_high = {[240:255]} iff (write);. When the guard is false at a sample, that bin's count does not change; the other bins still count (IEEE 1800-2023 19.5.1).
A read of 250 covers top but not wr_high. A coverpoint iff would have skipped the whole sample instead.
Values the Coverpoint Cannot Hold
Bin values are compared in the coverpoint's type (IEEE 1800-2023 19.5.7). A value that type cannot hold, such as -1 or 15 on a 3-bit unsigned coverpoint, takes no part in the bin. A range keeps only its values that fit.
| Coverpoint | Bin as written | Bin as it behaves |
|---|---|---|
bit [2:0] p (0 to 7) | b1 = {1, [2:5], [6:10]} | {1, [2:5], [6:7]} |
bit [2:0] p | b2 = {-1, [1:10], 15} | {[1:7]} |
bit signed [2:0] q (-4 to 3) | b3 = {1, [2:5], [6:10]} | {1, [2:3]} |
bit signed [2:0] q | b4 = {-1, [1:10], 15} | {-1, [1:3]} |
bit [2:0] p | big = {[8:15]} | empty: left out of the number |
The rules of 19.5.7 applied to the standard's own example, plus a bin that loses every value. A tool also issues a warning for each dropped value.
A bin can silently lose values, and an empty bin silently leaves the total. Check bin ranges against the coverpoint's width.
New in IEEE 1800-2023: Tolerance Ranges and Real Coverpoints
The 2023 standard adds two range forms, [c +/- d] (from c - d to c + d) and [c +%- p] (within p percent of c). It also allows a coverpoint on a real expression. Real bins split a range into intervals of type_option.real_interval, 1.0 by default (19.5.1, 19.7.1).
| Bin | Standard (IEEE 1800-2023 19.5.1) | Coverage build (measured) |
|---|---|---|
bins near = {[10 +/- 2]}; (integral, sample 12) | one bin for 8 to 12: 100.00% | compile error: "Unsupported: +/- range" |
real r; bins a = {[1.0:3.0]};, one bin (sample 1.5) | covered: 100.00% | 100.00% |
real r; bins a[] = {[1.0:3.0]};, an open array (sample 1.5) | two bins, [1.0:2.0) and [2.0:3.0]: 50.00% | 0.00%: the array gets no intervals |
the array with type_option.real_interval = 0.5; (sample 1.2) | four bins of 0.5: 25.00% | 0.00% |
Single real bins run correctly on this build. The tolerance range and the open real arrays are standard behaviour, not run correctly. Scenario cov-2023-real in docs/sva-standard-traces/CC.md.
Try It
The coverpoint has ten bins: zero, three low, four mid, top and wr_high. Each access covers one new bin, so the number climbs by 10% each time.
The first read of 250 covers top but not wr_high, because that bin's guard needs a write. Predict the output if mid[4] became mid[2].
addr=0 write=0: 10.00% addr=2 write=1: 20.00% addr=40 write=0: 30.00% addr=250 write=0: 40.00% addr=250 write=1: 50.00%Check Yourself
Common Mistakes
Wrong Expect bins b[N] to split the values into N equal parts.
Each bin gets the number of values divided by N, rounded down, and the last bin takes the rest.
Fix Work out B for the set, or write each range out when the boundaries matter.
Wrong Write bin ranges wider than the coverpoint can hold.
Values outside the type take no part. A bin left with no value drops out of the number, and no hole shows.
Fix Match bin ranges to the coverpoint's width, or use $ for the open end.
bit [7:0] addr; // 0 to 255
coverpoint addr {
bins page[4] = {[0:1023]};
}bit [9:0] addr; // 0 to 1023
coverpoint addr {
bins page[4] = {[0:$]};
}Wrong Write bins s[] = TABLE; on a tool that rejects set expressions and give up on the table.
The standard allows it, but the coverage build stops with a syntax error.
Fix Write the same values as a list, {...}, and keep the table as the comment that explains them.
Remember
bins b = {set}is one bin andbins b[] = {set}one per distinct value.bins b[N]deals values B at a time; the last bin takes the rest.- An empty bin has no value and leaves the coverage number.
$is the smallest or largest value of the coverpoint's type.- A bin
iffstops only that bin from counting a sample. - Bin values the coverpoint's type cannot hold take no part (19.5.7). Set expressions, tolerance ranges and open real arrays do not run on the coverage build.
Practice
Quick reference: Coverpoint bins