A3.4.2 No Else, No Check

EasyDebugVerilator · serverReview the topic

Count the failures of conditional properties with a missing else or default, on traces where the condition is often false.

Hardware context: Conditional checks of a bus whose condition is often false. Count only real failures when a branch or a case item is missing.

Each question is one assertion and one short trace, run in the program of the specification. Write answer(q) so it returns the number of failures the run reports.

Questions 0 to 2 are worked examples. Questions 3 to 6 use if without else, case without default, and a chained else if; they are graded only by the full check.

Signals in the Timeline

SignalWidthRole
question4input of each check
Full specification
The program around each question: <property> and the tables change
module tb;
  logic clk = 0;
  always #5 clk = ~clk;                      // rising edges at 5, 15, 25, ...
  logic sig = 0;
  int fails = 0;
  rule: assert property (@(posedge clk) <property>) else fails++;
  // Row k of each table is the value sampled at edge k + 1.
  logic sig_at [2] = '{0, 1};
  initial begin
    for (int k = 0; k < 2; k++) begin
      sig = sig_at[k];
      @(negedge clk);
    end
    $display("fails=%0d", fails);
    $finish;
  end
endmodule

q=0 (worked example): req |-> if (wr) ##1 ack else ##2 rdy

Signaledge 1edge 2edge 3edge 4edge 5edge 6
req101000
wr100000
ack000000
rdy000010

q=1 (worked example): v |-> case (sel) 2'd0: ##1 a; default: 1'b0; endcase

Signaledge 1edge 2edge 3edge 4edge 5edge 6
v110100
sel020300
a010000

q=2 (worked example): if (c) ##1 d else ##1 !d

Signaledge 1edge 2edge 3edge 4edge 5edge 6
c100100
d011000

q=3 (graded): if (wr) ##1 ack

Signaledge 1edge 2edge 3edge 4edge 5edge 6edge 7edge 8
wr10010010
ack01000000

q=4 (graded): v |-> case (sel) 2'd0: ##1 a; 2'd1: ##2 a; endcase

Signaledge 1edge 2edge 3edge 4edge 5edge 6edge 7edge 8
v11101100
sel20301200
a00100000

q=5 (graded): req |-> if (wr) ##1 ack

Signaledge 1edge 2edge 3edge 4edge 5edge 6edge 7edge 8
req11011000
wr01001000
ack00000100

q=6 (graded): if (a) ##1 b else if (c) ##1 d

Signaledge 1edge 2edge 3edge 4edge 5edge 6edge 7edge 8
a10001000
b01000000
c01011000
d00001000

Examples

Example 1

Both Branches Checked
Input
answer(0)
Output
fails = 1

The write at edge 1 has no ack at 2: a failure. The read at edge 3 gets rdy at 5. One failure.

Example 2

A Default That Fails
Input
answer(1)
Output
fails = 2

Edge 1 (sel 0) gets a at 2. Edges 2 and 4 pick the default, 1'b0, which fails at once. Two failures.

Example 3

An Else That Checks the Opposite
Input
answer(2)
Output
fails = 2

Edge 1 needs d at 2: yes. Edge 2 needs !d at 3: d is 1, a failure. Edge 3 needs !d at 4: yes. Edge 4 needs d at 5: no. Edges 5 and 6 need !d next: yes, and the last attempt is still open. Two failures.

Constraints and Contract

  • Return one failure count per question from answer(q).
  • Keep the function header.

Hints

Hint 1

An if without else checks nothing when its condition is false. Is that a failure?

Hint 2

A case without default checks nothing for a value with no item.

Hint 3

else if is checked only when the first condition is false.

What the grader checks: Seven constant answers, graded against failure counts measured on Verilator 5.052 (which runs if, else and case properties correctly).

7 checks on Verilator · 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

Both Branches Checked

Input
answer(0)
Expected output
fails = 1

The write at edge 1 has no ack at 2: a failure. The read at edge 3 gets rdy at 5. One failure.

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

Verilator · server