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
ifwithoutelseandcasewithoutdefaultcheck 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.
- Step
- Control / FSM
- Property
- Control
- Sample the condition
The condition is read once, at the edge where the attempt starts.
- 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.
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.
| mode | Property checked | Meaning |
|---|---|---|
| 0 | ##1 ack | answer after one edge |
| 1 | ##2 ack | answer after two edges |
| 2 | ##3 ack | answer after three edges |
| 3 | 1'b1 (default) | not checked |
One property per mode. A default of 1'b1 says "no rule" out loud.
| Branch | Standard (16.12.6, 16.12.16) | Verilator 5.052 (measured) |
|---|---|---|
if (wr) ##1 ack else ##[1:2] rdy | legal | rejected ("ranged cycle delay in an operand of property and") |
case (mode) 2'd0: ##1 done; default: ##[1:3] done; endcase | legal | rejected, same message |
| fixed delays in every branch | legal | runs 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.
| Attempt | Branch taken | Verdict |
|---|---|---|
| c true, the branch passes | p | pass |
| c true, the branch fails | p | fail |
| c false, no else | none | vacuous success |
| c false, else q passes | q | pass |
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?
resp_kind=0 read_len=1Check Yourself
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.
req |-> if (wr) ##1 ackreq |-> if (wr) ##1 ack else ##2 rdyWrong 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 qpicks one property per attempt fromc, sampled at the attempt's start.ifwithoutelseisc |-> 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.