C12.2 Bins from a Table

MediumImplementVerilator coverage build · serverReview the topic

Build bins from the opcode tables of a wider bus specification, for a block that decodes only three bits.

Hardware context: A block that decodes only the low three bits of a 4-bit opcode from a wider bus specification. Build bins from the specification tables and know which codes the block can never see.

The bus specification lists its opcodes in two tables, one for reads and one for writes. Some codes belong to a later 4-bit version of the bus. This block decodes only the low three bits of raw.

The plan asks for one bin per read code and one bin for all write codes, built from the tables. In the standard you would write bins reads[] = READ_CODES;. The coverage build rejects set expressions (lesson C12), so write the same values as a list.

Write the covergroup op_cov.

Signals in the Timeline

SignalWidthRole
samples8input of each check
Full specification
The tables (from the specification) and what you write
localparam int READ_CODES[4]  = '{0, 2, 4, 10};
localparam int WRITE_CODES[3] = '{1, 3, 9};

covergroup op_cov with function sample(bit [3:0] raw);
  op: coverpoint raw[2:0] { ... }   // reads[]: one bin per read code; writes: one bin
endgroup

The opcode is raw[2:0]. Each case samples a fresh instance and reads get_inst_coverage() times 100, rounded. The full check samples more lists than the examples show.

Examples

Example 1

A Read and a Write
Input
raw values: 0 1
Output
coverage_percent_x100 = 5000

reads[0] and writes: 2 of 4 bins, 50.00%.

Example 2

Code 10 Is Opcode 2
Input
raw values: 10 2
Output
coverage_percent_x100 = 2500

Both samples are opcode 2 and cover reads[2]: 1 of 4.

Example 3

Upper Bit Set
Input
raw values: 9 8 5
Output
coverage_percent_x100 = 5000

9 is opcode 1 (writes), 8 is opcode 0 (reads[0]), and 5 is in no bin: 2 of 4.

Constraints and Contract

  • Keep the covergroup name, the sample argument, the coverpoint op on raw[2:0] and the bin names.
  • Take the bin values from the tables, as value lists.

Hints

Hint 1

How many bins does reads[] make once you ask which of 0, 2, 4 and 10 fit in three bits?

Hint 2

IEEE 1800-2023 19.5.7: a bin value the coverpoint type cannot hold takes no part. What happens to a sample of raw = 10?

Hint 3

The table is the specification. Copy it exactly, even the codes this block can never see.

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

17 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

A Read and a Write

Input
raw values: 0 1
Expected output
coverage_percent_x100 = 5000

reads[0] and writes: 2 of 4 bins, 50.00%.

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

Verilator coverage build · server