C11.2 The Right Coverpoint Type

MediumFixVerilator coverage build · serverReview the topic

Fix a credit coverpoint that never sees credit returned, because it reads a two's complement value as unsigned.

Hardware context: A credit receiver whose change register holds a two's complement value. Read a signed register through a hierarchical name so that every credit change lands in its bin.

This is a Fix problem: the covergroup in the editor has one realistic defect. Find it and fix it.

A receiver keeps a credit count. Each cycle its register delta holds the change applied. It is negative when credit goes back, zero, or positive when credit is taken. delta is 4 bits of two's complement, -8 to 7.

The testbench covers the receiver from outside, through the hierarchical names u_rx.delta and u_rx.level. A test that returns credit many times still shows give_back as missing. A test that never returns credit reads 100% on delta.

Signals in the Timeline

SignalWidthRole
samples8input of each check
Full specification
The receiver (given)
module rx_ctrl;
  logic [3:0] delta;   // change applied this cycle, two's complement: -8 to 7
  logic [2:0] level;   // credits held, 0 to 7
endmodule
// In tb: rx_ctrl u_rx();
CoverpointBins
deltagive_back = -8 to -1, none = 0, take = 1 to 7
levelempty = 0, some = 1 to 6, full = 7

Each case sets u_rx.delta and u_rx.level before every sample of a fresh instance, and reads get_inst_coverage() times 100, rounded. In the case lists, delta is written as a signed number.

The full check samples more lists than the examples show.

Examples

Example 1

One Return, One Idle Cycle
Input
receiver states (delta, level): (-1, 3) (0, 0)
Output
coverage_percent_x100 = 6667

-1 lands in give_back and 0 in none: 2 of 3. Levels 3 and 0 are some and empty: 2 of 3. The average is 66.67%.

Example 2

Taken at Full, Then Returned
Input
receiver states (delta, level): (2, 7) (-1, 7)
Output
coverage_percent_x100 = 5000

take and give_back: 2 of 3. Only full is seen: 1 of 3. The average is 50.00%.

Example 3

Everything
Input
receiver states (delta, level): (0, 1) (4, 2) (-1, 0) (3, 7)
Output
coverage_percent_x100 = 10000

All three changes and all three levels: 100.00%.

Constraints and Contract

  • Keep the covergroup name, the coverpoint names and the bin names and ranges.
  • Keep reading the receiver through u_rx.
  • The coverage build ignores a declared coverpoint type (lesson C11): convert the value in the expression.

Hints

Hint 1

What values does a logic [3:0] hold? Which of them can land in a bin declared as -8 to -1?

Hint 2

IEEE 1800-2023 19.5.7: a bin value that cannot be represented in the coverpoint's type does not take part in the bin. What is left in give_back?

Hint 3

A cast such as signed'(...) changes how the same four bits are read. Keep the label delta unique and the path u_rx: a clash or an old instance name does not compile.

What the grader checks: Your covergroup is sampled with 18 lists of receiver states. Its instance coverage is compared with the value IEEE 1800-2023 clause 19 gives for the specified bins. Three lists are shown.

18 checks on Verilator coverage build · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

One Return, One Idle Cycle

Input
receiver states (delta, level): (-1, 3) (0, 0)
Expected output
coverage_percent_x100 = 6667

-1 lands in give_back and 0 in none: 2 of 3. Levels 3 and 0 are some and empty: 2 of 3. The average is 66.67%.

Run samples executes all 3 public checks. Check all tests runs 18 checks on the server.

Verilator coverage build · server