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 implies and 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.

Where the Right Side StartsWith |->, the right side starts where the left sequence ends. With implies, both sides start at the same edge.
  • Clock / reset
  • Property
  • Control
Where the right side startsWith |->, the right side starts where the left sequence ends. With implies, both sides start at the same edge. clock reset Start edge k the attempt starts property ##1 x x at k+1 property |-> ##2 y y at k+3 property implies ##2 y y at k+2 left sidefrom its endfrom the same edge
  1. clock reset Start edge kthe attempt starts
    • left side → ##1 x
    • from the same edge → implies ##2 y
  2. property ##1 xx at k+1
    • from its end → |-> ##2 y
  3. property |-> ##2 yy at k+3
  4. property implies ##2 yy at k+2
  1. The left side

    ##1 x looks for x one edge after the start.

  2. Two meanings of the right side

    After |->, ##2 y counts from the edge of x. After implies, 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 && irqmaskedResult
00true
01true
10false: a failure
11true

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.

Req |-> ((##1 x) Implies (##2 y))Standard behaviour for the three requests of the trace. The other attempts succeed vacuously and are left out.req |-> ((##1 x) implies (##2 y))Standard behaviour, not run on this simulator
attempt startspassfailvacuous success: the antecedent did not match
req |-> ((##1 x) implies (##2 y))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).edgetime152153254355456557658759851095clkreqxyattemptsattempt @5attempt @5: passes at edge 3 (t=25)attempt @35attempt @35: succeeds vacuously at edge 5 (t=45)attempt @65attempt @65: fails at edge 9 (t=85)
Scroll horizontally ↔
  1. Edge 3 · t=25

    x at 15, so y is needed at 25: it is there. Pass.

  2. Edge 5 · t=45

    No x at 45: the left side is false, so the implies is true whatever y does. A vacuous success.

  3. 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.

Ruley is due atLeft side false
(##1 x) implies (##2 y)start + 2vacuous success
(##1 x) |-> (##2 y)start + 3vacuous success
(##1 x) |-> (##1 y)start + 2: the same as implies herevacuous 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.

RUNVerilator · simulator service
Edit the code, then run it
Expected: f_full=1 f_mask=1

Check Yourself

Predict the outputAn enable must be high exactly while a mode is active. Predict the exact output.
module tb;
  logic clk = 0;
  always #5 clk = ~clk;
  logic mode = 0, en = 0;
  int fails = 0;
  same: assert property (@(posedge clk) en iff mode) else fails++;
  initial begin
    @(negedge clk) mode = 1;                  // 15: mode on, en still off
    @(negedge clk) en = 1;                    // 25: both on
    @(negedge clk) mode = 0;                  // 35: mode off, en still on
    @(negedge clk) en = 0;                    // 45: both off
    @(negedge clk) $display("fails=%0d", fails);
    $finish;
  end
endmodule
ConceptWhen does p implies q fail, by the standard?
ConceptWhere does the right side of (##1 x) implies (##2 y) start?
ConceptWhich rule fails both when a flag is set with its condition false, and when it is clear with the condition true?

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.

Before
(##1 x) |-> (##2 y)   // y at start + 3
After
(##1 x) implies (##2 y)   // y at start + 2

Wrong 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 q fails 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 q holds when both sides agree.
  • Verilator 5.052 misses temporal implies failures; write the shared start out with |=>.

Practice

Report a problem with this page