A7.2.2 One Let, Three Uses

MediumImplementVerilator coverage build · serverReview the topic

Declare one let and use it in an immediate assertion, a concurrent assertion and a covergroup.

Hardware context: A FIFO fill-level monitor reused across FIFOs of different sizes. Keep the immediate check, the concurrent check and the coverage of one condition in step.

A FIFO level monitor needs three views of one condition, "the level is over the limit". An immediate assertion counts the edges where it holds. A concurrent assertion checks that en drops one edge later. A covergroup records whether it was ever seen, and whether a normal level was.

Write level_watch with one let, over(v), that compares with the parameter LIMIT, and use it in all three. The same module then serves FIFOs of other sizes.

Signals in the Timeline

SignalWidthRole
clk1stimulus, the same for every design
en1stimulus, the same for every design
lvl4stimulus, the same for every design
Full specification
The ports (keep them)
module level_watch #(parameter logic [3:0] LIMIT = 4'd12) (
  input  logic       clk,
  input  logic       en,         // the level is valid
  input  logic [3:0] lvl,        // a FIFO fill level
  output int         imm_bad,    // edges where en is high and the level is over the limit
  output int         conc_bad    // over-limit levels not followed by en low at the next edge
);
  // one let, two assertions, one covergroup named level_cg with instance cov_inst
endmodule
EdgeWhat the program shown here does (LIMIT = 12)
5en low, level 0
15en high, level 13: over
25en low, level 2
35en high, level 14: over
45level 15, en still high
55en low

Coverage is read with cov_inst.get_inst_coverage(), rounded to a whole percent. The full check also runs a second program with LIMIT = 9.

Simulator note: This problem runs on the coverage build of Verilator (master b8e7f1e), which samples covergroups.

Examples

Example 1

Three Edges over the Limit
Input
Program: LIMIT = 12, levels 13, 14 and 15 with en high
Output
imm_bad = 3

The level is over at 15, 35 and 45, with en high each time.

Example 2

One Late Drop of En
Input
Program: LIMIT = 12
Output
conc_bad = 1

After 15, en is low at 25 as required. After 35, it is still high at 45.

Example 3

Half the Bins
Input
Program: LIMIT = 12
Output
cov = 50

Every low level comes while en is low, so the guard keeps the ok bin empty.

Constraints and Contract

  • Declare let over(v) once, in the module, comparing v with LIMIT.
  • Use it in the immediate assertion imm, the concurrent assertion conc and the coverpoint.
  • Name the covergroup level_cg and its instance cov_inst. Do not change the ports.

Hints

Hint 1

A let declared inside the always block is not visible to the concurrent assertion or the covergroup.

Hint 2

A name in the body that is not an argument, such as LIMIT, binds where the let is declared.

Hint 3

A coverpoint expression may call a let, and so may its iff guard.

What the grader checks: Two copies of your module each watch a fixed program: LIMIT = 12 (shown) and LIMIT = 9 (hidden). Graded on each: both failure counts and the coverage percent. Both assertions must call over.

6 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

Three Edges over the Limit

Input
Program: LIMIT = 12, levels 13, 14 and 15 with en high
Expected output
imm_bad = 3

The level is over at 15, 35 and 45, with en high each time.

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

Verilator coverage build · server