If-Else and Case Properties

Pick the property to check from a condition with if-else or a mode with case, and know what happens when nothing matches.

You Will Be Able To

  • Write a property that checks one rule or another, chosen by a condition.
  • Say what if without else and case without default check when nothing matches.
  • Read the vacuity of a conditional property from its branches.
Lesson
A3.4
Time
20 min
Runs on
Verilator
Check
5 questions

A bus answers a write after one edge and a read after two. Two implications can say that. One property with if and else says it in a single rule.

A Condition Picks the PropertyAt the attempt's start edge, the condition is sampled. True picks the first property, false the second.
  • Step
  • Control / FSM
  • Property
  • Control
A condition picks the propertyAt the attempt's start edge, the condition is sampled. True picks the first property, false the second. step Attempt starts req is 1 control if (wr) sampled at the startedge property ##1 ack write: one edge property ##2 rdy read: two edges checktruefalse (else)
  1. step Attempt startsreq is 1
    • check → if (wr)
  2. control if (wr)sampled at the start edge
    • true → ##1 ack
    • false (else) → ##2 rdy
  3. property ##1 ackwrite: one edge
  4. property ##2 rdyread: two edges
  1. Sample the condition

    The condition is read once, at the edge where the attempt starts.

  2. One branch runs

    Only the chosen property is checked for this attempt. The other is ignored.

Read the diagram as text
  • Attempt starts: req is 1
  • if (wr): sampled at the start edge
  • ##1 ack: write: one edge
  • ##2 rdy: read: two edges
  • Attempt starts → if (wr): check
  • if (wr) → ##1 ack: true
  • if (wr) → ##2 rdy: false (else)

Without an else, a false condition checks nothing: the attempt succeeds vacuously.

If (c) p Else q

if (c) p else q checks p when c is true at the attempt's start, and q when it is false (IEEE 1800-2023 16.12.6). The condition is a Boolean; the branches are whole properties.

Writes and reads with one rule
01234567reqwrackrdywrite: no ackread: no rdy
Scroll horizontally ↔

Edges 1 to 8. The write at edge 3 needs ack at 4; the read at edge 4 needs rdy at 6.

If Without Else

if (c) p checks p when c is true. When c is false, nothing is checked: the attempt succeeds vacuously. That is the same as c |-> p.

if without else

req |-> if (wr) ##1 ack

Reads are not checked.

The same rule as an implication

req && wr |=> ack

Same verdicts on every trace.

Case Properties

case (e) v1: p1; v2: p2; default: pd; endcase checks the property of the first item that matches e at the attempt's start (16.12.16). Without default, a value that matches no item checks nothing.

modeProperty checkedMeaning
0##1 ackanswer after one edge
1##2 ackanswer after two edges
2##3 ackanswer after three edges
31'b1 (default)not checked

One property per mode. A default of 1'b1 says "no rule" out loud.

BranchStandard (16.12.6, 16.12.16)Verilator 5.052 (measured)
if (wr) ##1 ack else ##[1:2] rdylegalrejected ("ranged cycle delay in an operand of property and")
case (mode) 2'd0: ##1 done; default: ##[1:3] done; endcaselegalrejected, same message
fixed delays in every branchlegalruns correctly

Measured by tools/probes/sva-w1a/conditional-ranges.mjs. On 5.052, keep each branch to fixed delays, or split the rule.

Vacuity Comes from the Branches

An if or case property has no vacuity rule of its own. An attempt is nonvacuous only when the branch it picks is nonvacuous (16.14.8). A false condition with no else is vacuous.

AttemptBranch takenVerdict
c true, the branch passesppass
c true, the branch failspfail
c false, no elsenonevacuous success
c false, else q passesqpass

A vacuous success still runs the pass statement, unless vacuous passes are switched off.

Try It

resp_kind uses if-else: the write is answered at 25, and both reads get rvalid two edges after the request.

read_len uses case on the burst length. The four-beat read gives only three beats, so it fails at 125. Burst code 3 has no item, so it would not be checked.

Add default: 1'b0; to the case. Which bursts fail now, and is that what the spec wants?

RUNVerilator · simulator service
Edit the code, then run it
Expected: resp_kind=0 read_len=1

Check Yourself

Predict the outputOnly fast requests are checked. Predict the exact output.
module tb;
  logic clk = 0;
  always #5 clk = ~clk;
  logic go = 0, fast = 0, ack = 0;
  int fails = 0;
  rule: assert property (@(posedge clk) go |-> if (fast) ##1 ack) else fails++;
  initial begin
    @(negedge clk) begin go = 1; fast = 1; end   // seen at 15: ack due at 25
    @(negedge clk) begin go = 1; fast = 0; end   // seen at 25: slow, no check
    @(negedge clk) begin go = 0; ack = 0; end
    @(negedge clk) $display("fails=%0d", fails);
    $finish;
  end
endmodule
ConceptAn attempt of if (wr) ##1 ack starts with wr = 0. What is its result?
ConceptA case property has items for 0, 1 and 2 and no default. The selector is 3. What is checked?
ConceptWhen is the condition of req |-> if (wr) ##1 ack else ##2 rdy read?
ConceptWhich rule checks writes after one edge and reads after two, in one assertion?

Common Mistakes

Wrong Leave out the else when the other case also has a rule.

A false condition then checks nothing.

Fix Write the else branch, or a second assertion for the other case.

Before
req |-> if (wr) ##1 ack
After
req |-> if (wr) ##1 ack else ##2 rdy

Wrong Expect a case with no default to fail on an unknown selector.

An unmatched value picks no property, so the attempt succeeds vacuously.

Fix Add default: 1'b0 if an unknown value is an error, or default: 1'b1 to say "no rule" on purpose.

Wrong Count every pass statement as a real check.

Vacuous successes run the pass statement too.

Fix Count failures, and count the cases where the condition held, separately.

Remember

  • if (c) p else q picks one property per attempt from c, sampled at the attempt's start.
  • if without else is c |-> p: a false condition gives a vacuous success.
  • A case property checks the first matching item; with no default, an unmatched value checks nothing.
  • A conditional property is vacuous exactly when the branch it picks is vacuous, or when it picks none.

Practice

Report a problem with this page