Implies and iff
Join two properties with implies, which starts both at the same edge, and with iff, which needs both to agree.
You Will Be Able To
- Write a Boolean rule with
impliesand say when it fails. - Read a temporal
implies: both sides start together, unlike|->. - Write an equivalence with
iff.
- Lesson
- A3.6
- Time
- 20 min
- Runs on
- Verilator
- Check
- 4 questions
a |-> b and a implies b look like the same rule. On Booleans they are. Once the sides take time, they start at different edges.
- Clock / reset
- Property
- Control
- The left side
##1 xlooks for x one edge after the start. - Two meanings of the right side
After
|->,##2 ycounts from the edge of x. Afterimplies, it counts from the start edge.
Read the diagram as text
- Start edge k: the attempt starts
- ##1 x: x at k+1
- |-> ##2 y: y at k+3
- implies ##2 y: y at k+2
- Start edge k → ##1 x: left side
- ##1 x → |-> ##2 y: from its end
- Start edge k → implies ##2 y: from the same edge
Same text after the operator, one edge apart.
Implies on Booleans
p implies q is true when p is false or q is true (IEEE 1800-2023 16.12.8). On Booleans it is the familiar "if p then q" of the same edge.
| busy && irq | masked | Result |
|---|---|---|
| 0 | 0 | true |
| 0 | 1 | true |
| 1 | 0 | false: a failure |
| 1 | 1 | true |
Only a true left side with a false right side fails.
Implies over Time
When the sides take time, both still start at the same edge. (##1 x) implies (##2 y) says: if x comes one edge later, then y comes two edges after the start.
- Edge 3 · t=25
x at 15, so y is needed at 25: it is there. Pass.
- Edge 5 · t=45
No x at 45: the left side is false, so the implies is true whatever y does. A vacuous success.
- Edge 9 · t=85
x at 75 and no y at 85: fail.
Read the lanes as text
- attempt @5, from edge 1 (t=5): passes at edge 3 (t=25).
- attempt @35, from edge 4 (t=35): succeeds vacuously at edge 5 (t=45).
- attempt @65, from edge 7 (t=65): fails at edge 9 (t=85).
Sampled values, edge 1 to 10: req 1 0 0 1 0 0 1 0 0 0; x 0 1 0 0 0 0 0 1 0 0; y 0 0 1 0 0 0 0 0 0 0.
Standard behaviour, derived in docs/sva-standard-traces/A3.md (sva-081).
Verilator 5.052 compiles this property and does not report the failure at 85 (tools/probes/sva-w1a/temporal-implies.mjs). The runnable form writes the shared start out: req ##1 x |=> y.
Implies Against |->
Replacing implies by |-> moves the right side: it now starts where the left sequence ends. implies, like |->, does not fail when the left side is false. Some books say otherwise; the standard does not.
| Rule | y is due at | Left side false |
|---|---|---|
(##1 x) implies (##2 y) | start + 2 | vacuous success |
(##1 x) |-> (##2 y) | start + 3 | vacuous success |
(##1 x) |-> (##1 y) | start + 2: the same as implies here | vacuous success |
IEEE 1800-2023 16.12.8. An implies fails only when its left side holds and its right side does not.
iff: Both or Neither
p iff q is true when both are true or both are false (16.12.8). It suits flags that must match a condition exactly.
One way only
count == 2 |-> full
Misses a full flag set too early.
Both ways
full iff (count == 2)
full exactly when the buffer holds 2.
Try It
full_ok uses iff: the flag rises one edge late, at 35 instead of 25, so the edge at 25 disagrees.
mask_ok uses Boolean implies: at 45 an interrupt arrives while busy and unmasked.
Rewrite full_ok as count == 2 |-> full and predict its count.
f_full=1 f_mask=1Check Yourself
Common Mistakes
Wrong Treat implies as |->.
implies starts both sides at the same edge; |-> starts the right side where the left ends.
Fix Count delays on both sides of implies from the start edge.
(##1 x) |-> (##2 y) // y at start + 3(##1 x) implies (##2 y) // y at start + 2Wrong Expect p implies q to fail when p fails.
A false left side makes the implies true (16.12.8).
Fix Use and if both sides must hold.
Wrong Check a flag one way only with an implication.
A flag set at the wrong time passes cond |-> flag.
Fix Use flag iff cond.
Remember
p implies qfails only when p holds and q does not.- Both sides of implies start at the same edge; after
|->the right side starts where the left ends. p iff qholds when both sides agree.- Verilator 5.052 misses temporal implies failures; write the shared start out with
|=>.