Two bench assumptions use dist with weights. Say which values fail them in simulation.
Hardware context: A bench whose input promises are written with weighted dist lists. Read what a simulator checks in a weighted assumption: the set, not the weights.
A bench writes its input promises with dist, so the same lines can steer random generation. A simulator checks them as assumptions.
Write answer(q). Questions 3 to 8 ask about the main program; a third assumption there uses inside. Questions 0 to 2 are worked examples on a smaller program and are not graded by the full check.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 4 | input of each check |
Full specification
module tb;
logic clk = 0;
always #5 clk = ~clk; // rising edges at 5, 15, ..., 65 (the run ends at 74)
logic [1:0] mode = 2'd1;
logic [3:0] len = 4'd1;
logic [1:0] kind = 2'd0;
int mode_f = 0, len_f = 0, mode_first = 0, kind_f = 0;
// The bench should almost never use mode 0, and never mode 3.
mode_mix: assume property (@(posedge clk) mode dist {2'd0 := 1, [2'd1:2'd2] := 50})
else begin mode_f++; if (mode_first == 0) mode_first = $time; end
// Burst lengths 1 to 4, or 8; short bursts much more often.
len_mix: assume property (@(posedge clk) len dist {[4'd1:4'd4] :/ 9, 4'd8 :/ 1}) else len_f++;
// Kinds 0, 1 and 3 are legal; 2 is reserved.
kind_ok: assume property (@(posedge clk) kind inside {[2'd0:2'd1], 2'd3}) else kind_f++;
initial begin
#12 mode = 2'd0; len = 4'd8; kind = 2'd2; // edge 15
#10 mode = 2'd2; len = 4'd5; kind = 2'd3; // edge 25
#10 mode = 2'd3; len = 4'd4; kind = 2'd2; // edge 35
#10 mode = 2'd1; len = 4'd0; kind = 2'd1; // edge 45
#10 mode = 2'd3; len = 4'd8; // edge 55
#10 mode = 2'd0; len = 4'd9; // edge 65
#12 $display("mode_f=%0d len_f=%0d mode_first=%0d kind_f=%0d", mode_f, len_f, mode_first, kind_f);
$finish;
end
endmodule
| q | Return | Program |
|---|---|---|
| 0 | the value of f | worked example |
| 1 | the time of the edge that failed k_set | worked example |
| 2 | 1 if k = 5 fails k_set, else 0 | worked example |
| 3 | the value of mode_f | main, graded |
| 4 | the value of mode_first | main, graded |
| 5 | the value of len_f | main, graded |
| 6 | 1 if the weight :/ 1 on 8 makes len = 8 fail, else 0 | main, graded |
| 7 | 1 if mode = 0 (the rare weight) fails mode_mix, else 0 | main, graded |
| 8 | the value of kind_f | main, graded |
module tb;
logic clk = 0;
always #4 clk = ~clk; // rising edges at 4, 12, 20, 28
logic [2:0] k = 3'd1;
int f = 0;
k_set: assume property (@(posedge clk) k inside {3'd1, [3'd4:3'd5]}) else f++;
initial begin
#10 k = 3'd4; // edge 12
#8 k = 3'd2; // edge 20
#8 k = 3'd5; // edge 28
#4 $display("f=%0d", f);
$finish;
end
endmodule
Simulator note: The key was measured on Verilator 5.052 and agrees with IEEE 1800-2023 16.14.2. Your answer function is checked by a small bench on Icarus 12.
Examples
Example 1
Count the Misses- Input
answer(0)
- Output
answer = 1
Of 1, 4, 2 and 5, only 2 is outside {1, 4, 5}.
Example 2
When It Fails- Input
answer(1)
- Output
answer = 20
k becomes 2 at 18, so the edge at 20 samples it.
Example 3
A Range Includes Its Ends- Input
answer(2)
- Output
answer = 0
[4:5] includes 5, so 5 passes.
Constraints and Contract
- Return one value per question from answer(q).
- Keep the function header.
Hints
Hint 1
In a check, a dist list is a set. Write the set first and forget the weights.
Hint 2
A rare weight is still a member of the set.
Hint 3
List the sampled value of each signal at each edge from 5 to 65. The run ends at 74, before an edge at 75.
What the grader checks: Nine constant answers: three worked examples and six graded questions, measured on Verilator 5.052.
9 checks on Icarus · browser samples / server checks. 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 3 steps and the final capstone