Coverpoint Expressions, Guards and References

Cover the value the design computes, not only a raw signal: expressions, functions, types, iff guards, labels and hierarchical references.

You Will Be Able To

  • Write a coverpoint on an expression or on a function that classifies a value.
  • Predict how a declared coverpoint type changes the values, and use a cast where a tool ignores the type.
  • Guard a coverpoint with iff so that samples which mean nothing are skipped.
  • Name coverpoints with labels and read a design signal through a hierarchical reference.
Lesson
C11
Time
30 min
Runs on
Coverage build
Check
5 questions

A DMA team covered its 32-bit start address with coverpoint addr;, which makes 64 automatic bins of 67,108,864 addresses each. Every test lived in the low megabyte, so every burst fell into bin 0. The number sat at 1.56% for months. The plan never asked about raw addresses: it asked which of four memory regions each burst started in.

Raw Address Bins Against the Question the Plan Asks
01234addr (hex)00000040000010000000F80000080000000C0010auto bin hitauto[0]raw coverpoint1.56region of addrCSRBUFFIFOROMregion coverpoint255075100every region seen; raw bins still 1.56%
Scroll horizontally ↔
  1. Cycle 0

    A 32-bit coverpoint with no bins gets 64 automatic bins. Each holds 2^32 / 64 addresses. Address 40 hex lands in the first.

  2. Cycle 3

    Four bursts reached all four regions, so a coverpoint on the region reads 100%. The raw coverpoint still shows one bin of 64.

  3. Cycle 4

    Nothing a test can do in the low megabyte moves the raw number. The fix is to cover the region, a value computed from the address.

One column per sampled burst. The regions are illustrative; the bin size is IEEE 1800-2023 19.5.3 with the default auto_bin_max of 64.

A Coverpoint Can Cover an Expression

A coverpoint is not limited to one variable. Its expression can be any integral expression: a part-select, a concatenation, arithmetic. The expression is evaluated each time the covergroup samples.

CoverpointValues it takesAutomatic bins
op: coverpoint {wr, rd};0 to 3: idle, read, write, both4
page: coverpoint addr[7:4];the upper four address bits16
odd: coverpoint len[0];0 or 12
dist: coverpoint (wptr - rptr) % 8;the FIFO fill levelfrom the expression's width

Each line samples an expression, not a signal. With no bins listed, the tool makes automatic bins from the expression's width (IEEE 1800-2023 19.5.3).

Use an expression when the plan asks about a value the signals only carry together. The pair {wr, rd} gives the operation in one value, so four bins answer "was each operation requested?".

A Coverpoint Can Cover a Function's Result

When the question is a classification, write the classification as a function and cover its result. A function that returns an enum gets one automatic bin per enum name.

From a Raw Length to a Size ClassThe example below. Arrows show data: at each sample the covergroup calls size_of(len), and the enum it returns picks one of three bins.
  • Step
  • Neutral
  • Data
CallValueReturnWaiting
From a raw length to a size classThe example below. Arrows show data: at each sample the covergroup calls `size_of(len)`, and the enum it returns picks one of three bins. step cg.sample() one burst step size_of(len) automatic, no sideeffects neutral auto[SINGLE] len == 1 neutral auto[SHORT] len 2 to 4 neutral auto[LONG] len 5 to 8 len
  1. step cg.sample()one burst
    • len → size_of(len)
  2. step size_of(len)automatic, no side effects
    • auto[SINGLE]
    • auto[SHORT]
    • auto[LONG]
  3. neutral auto[SHORT]len 2 to 4
  4. neutral auto[SINGLE]len == 1
  5. neutral auto[LONG]len 5 to 8
  1. Sample a burst of 4

    The covergroup passes len = 4 to the function.

    Follow the calls, values and waits
    1. data 4: cg.sample() → size_of(len)
  2. The function classifies it

    4 is a short burst, so the function returns SHORT and that bin is hit.

    Follow the calls, values and waits
    1. data SHORT: size_of(len) → auto[SHORT]
  3. Three bins, not sixteen

    The enum has three names, so the coverpoint has three bins. Lengths 2, 3 and 4 all count for the same bin.

Read the diagram as text
  • cg.sample(): one burst
  • size_of(len): automatic, no side effects
  • auto[SINGLE]: len == 1
  • auto[SHORT]: len 2 to 4
  • auto[LONG]: len 5 to 8
  • cg.sample() → size_of(len): len
  • size_of(len) → auto[SINGLE]
  • size_of(len) → auto[SHORT]
  • size_of(len) → auto[LONG]

The function turns the plan's question into code once. The bins then follow from the enum.

Keep the function automatic and free of side effects. It runs at every sample, so a function that counts or prints would do that work once per sample. The standard places the same limits on functions used inside bin definitions (IEEE 1800-2023 19.5).

A Coverpoint Can Have a Type

A coverpoint can declare a data type before its label: bit [1:0] lo: coverpoint addr;. Each value is then computed as if the expression were assigned to a variable of that type (IEEE 1800-2023 19.5). A type needs a label.

Without a type, the coverpoint takes the self-determined type of its expression. That is the detail behind most surprises.

CoverpointStandard (IEEE 1800-2023 19.5)Coverage build (measured)Equivalent that runs
bit [1:0] lo: coverpoint addr; (8-bit addr; 05, 16, 27 hex)4 bins, 3 hit: 75.00%4.69%: the type is ignored, so 64 bins of 4 valueslo: coverpoint 2'(addr); gives 75.00%
bit [3:0] ones: coverpoint $countones(w); (counts 0 to 8)16 bins, 9 hit: 56.25%1.56%: int, 64 binscoverpoint 4'($countones(w)) gives 56.25%
bit signed [3:0] sd: coverpoint d { bins neg = {[-8:-1]}; ... } (d = 4'b1111)-1 lands in neg: 50.00%0.00%: unsigned, neg is emptycoverpoint signed'(d) gives 50.00%
bit [8:0] last: coverpoint addr + len { bins in_page = {[0:255]}; bins over = {[256:511]}; } (FE + 4)102 hex lands in over: 50.00%100.00%: the sum wraps to 02 hex, so over is empty and drops outcoverpoint 9'(addr) + len gives 50.00%

Standard behaviour beside the coverage build. The build accepts a declared type and then ignores it (tools/probes/cov-w1/probes.mjs, 2026-11-12). Each row is one probe.

$countones is the classic trap. It returns an int, so an untyped coverpoint on it gets 64 bins over four billion values. Every count falls into the first. Give it a type wide enough for the counts, or cast it.

A second trap runs the other way. A book declares bit cp_parity: coverpoint $countones(word); on an 8-bit word and expects one bin per set bit. The type bit keeps one bit of the count, its parity: two automatic bins. An 8-bit word has nine counts, 0 to 8, so it needs at least four bits.

iff Skips Samples That Mean Nothing

A guard, coverpoint d iff (en), is evaluated at each sample with the expression. When it is false, the coverpoint ignores that sample: no bin counts it (IEEE 1800-2023 19.5).

A Retried Burst Is Not New Traffic
01234len1372retrycounted?yesnoyessize bins hit1/32/33/3retry: skipped
Scroll horizontally ↔
  1. Cycle 2

    A long burst that only repeats a failed one. With iff (!retry) it does not count as long traffic.

  2. Cycle 3

    The next long burst is new. Now the LONG bin is hit.

One column per sample of size: coverpoint size_of(len) iff (!retry).

Use iff for reset, for retries and for idle bus cycles. A coverpoint without the guard counts those samples and can report a case as covered when only a retry produced it.

Labels Name Coverpoints

The label before coverpoint is the coverpoint's name. Reports print it, and a cross refers to it. Choose names a reader of a coverage report understands without the code.

No labels

covergroup cg;
  coverpoint len;          // named len
  coverpoint {wr, rd};     // no usable name
endgroup

The second coverpoint cannot be crossed or named in code.

Labels

covergroup cg;
  len_cp: coverpoint len;
  op:     coverpoint {wr, rd};
  len_x_op: cross len_cp, op;
endgroup

Every coverpoint has a name a cross and a report can use.

The rules (IEEE 1800-2023 19.5): with no label, a coverpoint on a single variable takes the variable's name. An unlabeled expression gets a name only the tool's report sees. Two coverpoints in one covergroup may not share a label; the coverage build rejects that at compile time (measured). A typed coverpoint must have a label.

Hierarchical References Reach into the Design

A covergroup in the testbench can sample a signal inside the design by its hierarchical name, such as u_dut.st. Nothing in the design changes. This is handy for internal state that no port shows.

A Testbench Covergroup Reads a State Register Inside the DesignThe check item below. The covergroup lives in tb; its coverpoint names u_dut.st, a variable inside the design instance.
  • Environment
  • DUT
  • Storage
  • Model
  • Control
  • Data
CallValueReturnWaiting
A testbench covergroup reads a state register inside the designThe check item below. The covergroup lives in `tb`; its coverpoint names `u_dut.st`, a variable inside the design instance. env module tb clock and go dut u_dut instance of dut storage u_dut.st IDLE, RUN, DONE model cg in tb st: coverpointu_dut.st goupdatesread at each sample
  1. env module tbclock and go
    • go → u_dut
  2. dut u_dutinstance of dut
    • updates → u_dut.st
  3. storage u_dut.stIDLE, RUN, DONE
    • read at each sample → cg in tb
  4. model cg in tbst: coverpoint u_dut.st
  1. The bench drives the design

    The bench raises go. The design moves its state register from IDLE to RUN to DONE.

  2. The covergroup reads inside it

    At each falling edge the covergroup samples u_dut.st by name. No port carries the state out.

    Follow the calls, values and waits
    1. data RUN: u_dut.st → cg in tb
Read the diagram as text
  • module tb: clock and go
  • u_dut: instance of dut
  • u_dut.st: IDLE, RUN, DONE
  • cg in tb: st: coverpoint u_dut.st
  • module tb → u_dut: go
  • u_dut → u_dut.st: updates
  • u_dut.st → cg in tb: read at each sample

A hierarchical name ties the covergroup to one instance path. A rename of u_dut breaks the compile.

The cost is reuse. A covergroup with a hard-coded path fits one instance only. To cover two instances, pass the signal in as a ref argument instead; lesson C19 covers covergroup arguments.

Try It

The size coverpoint has three bins and the last-byte coverpoint two. After the first burst: size 1 of 3 and last 1 of 2, so (33.33 + 50) / 2 is 41.67%. The second burst adds SHORT: (66.67 + 50) / 2 is 58.33%.

The retry changes nothing, because both coverpoints are guarded. The last burst is LONG and ends at 103 hex, past the 256-byte window, so both coverpoints reach 100%.

The unsized literal 1 is 32 bits, so addr + len - 1 would keep the carry even without the cast; the cast states the width on purpose. Write addr + len alone and the sum is 8 bits: predict the last line for a coverpoint on it.

RUNVerilator (coverage build) · simulator service
Edit the code, then run it
Expected: addr=10 len=1 retry=0: 41.67% addr=20 len=4 retry=0: 58.33% addr=fc len=8 retry=1: 58.33% addr=fc len=8 retry=0: 100.00%

Check Yourself

Predict the outputPredict the exact output.
module tb;
  bit [7:0] addr;
  bit [3:0] len;
  covergroup cg;
    last: coverpoint 9'(addr) + len - 1 { bins in_window = {[0:255]}; bins past_end = {[256:270]}; }
  endgroup
  cg c = new;
  initial begin
    addr = 8'hF0; len = 8; c.sample();
    addr = 8'hF8; len = 8; c.sample();
    $display("last %0.2f%%", c.get_inst_coverage());
  end
endmodule
Spot the bugEach option is the coverpoint of a covergroup sampled with two bursts: a new short burst and a retried long burst. Retries must not count. Which option counts the retry?
ConceptA coverpoint is written bit [1:0] lo: coverpoint addr; with an 8-bit addr. What does the standard say it covers?
ConceptWhy does coverpoint $countones(w) with no bins and no type read 1.56% after every count from 0 to 8?
ConceptA covergroup in the testbench samples u_rx.state by hierarchical name. The team adds a second receiver, u_rx2. What is the cleanest way to cover both?

Common Mistakes

Wrong Cover a wide raw field, such as a 32-bit address, with automatic bins.

Automatic bins split the whole range evenly, so real traffic falls into one bin and the number never moves.

Fix Cover the value the plan asks about: a region, a class or a range, computed by a function or an expression.

Before
covergroup cg;
  coverpoint addr;
endgroup
After
covergroup cg;
  region: coverpoint region_of(addr);
endgroup

Wrong Trust a declared coverpoint type to narrow or sign a value on every tool.

The coverage build ignores the type, so the bins see the expression's own width and sign.

Fix Write the conversion in the expression with a cast, such as signed'(d) or 9'(addr) + len.

Wrong Leave reset cycles and retries in the samples of a coverpoint.

They hit bins without being the traffic the plan asks about, so holes look covered.

Fix Add iff (!reset) or iff (!retry) to the coverpoint.

Remember

  • A coverpoint can cover any integral expression or a function's result; a function that returns an enum gives one bin per name.
  • A declared coverpoint type converts each value as an assignment would; the coverage build ignores it, so cast in the expression.
  • An untyped coverpoint takes its expression's self-determined type, which makes $countones an int.
  • iff makes a coverpoint ignore a sample whose guard is false.
  • Labels name coverpoints for crosses and reports; a hierarchical reference reads a design signal but ties the covergroup to one path.

Practice

Report a problem with this page