Always and s_always

Say that a property holds through a window or forever, and what the end of a test does to each form.

You Will Be Able To

  • Write always [m:n] p for a property that must hold through a window.
  • Read unbounded always p and always [m:$] p, and their weak end of test.
  • Tell s_always [m:n] from always [m:n] when a test stops inside the window.
  • Know which bounds are legal for each form.
Lesson
A3.9
Time
25 min
Runs on
Verilator
Check
4 questions

A link must report ok at every edge after it trains, for as long as the test runs. Writing that edge by edge is impossible. always says it in one word.

Where Each Form ChecksAn attempt at edge k. always [m:n] checks edges k+m to k+n; always [m:$] from k+m on; always from k on.
  • Step
  • Property
  • Control
Where each form checksAn attempt at edge k. always [m:n] checks edges k+m to k+n; always [m:$] from k+m on; always from k on. step Attempt at edge k req is 1 property always [1:2] p edges k+1, k+2 property always [2:$] p edges k+2, k+3, ... property always p edges k, k+1, ... boundedopen endfrom now on
  1. step Attempt at edge kreq is 1
    • bounded → always [1:2] p
    • open end → always [2:$] p
    • from now on → always p
  2. property always [1:2] pedges k+1, k+2
  3. property always [2:$] pedges k+2, k+3, ...
  4. property always pedges k, k+1, ...
  1. A bounded window

    The attempt passes when the last edge of the window has been checked.

  2. Open-ended

    An open window can only fail. At the end of a test, a weak always that never failed counts as holding.

Read the diagram as text
  • Attempt at edge k: req is 1
  • always [1:2] p: edges k+1, k+2
  • always [2:$] p: edges k+2, k+3, ...
  • always p: edges k, k+1, ...
  • Attempt at edge k → always [1:2] p: bounded
  • Attempt at edge k → always [2:$] p: open end
  • Attempt at edge k → always p: from now on

Every edge of the window must hold p. One bad edge fails the attempt.

Always p: From Now On

always p holds when p holds at the current edge and at every later one (IEEE 1800-2023 16.12.11). It is weak: an attempt still holding at the end of a test does not fail.

Req |-> Always OkStandard behaviour for the two requests of the trace. The other attempts succeed vacuously and are left out.req |-> always okStandard behaviour, not run on this simulator
attempt startsfailstill running at the end: weak, no failure
req |-> always okattempt @15, from edge 2 (t=15): fails at edge 7 (t=65). attempt @85, from edge 9 (t=85): is still running at the end of the run: weak, so no failure.edgetime152153254355456557658759851095end100clkreqokattemptsattempt @15attempt @15: fails at edge 7 (t=65)attempt @85attempt @85: is still running at the end of the run: weak, so no failure
Scroll horizontally ↔
  1. Edge 7 · t=65

    ok drops at 65: the attempt from 15 fails.

  2. Edge 10 · t=95

    The attempt from 85 still holds when the test ends. always is weak, so it does not fail.

Read the lanes as text
  • attempt @15, from edge 2 (t=15): fails at edge 7 (t=65).
  • attempt @85, from edge 9 (t=85): is still running at the end of the run: weak, so no failure.

Sampled values, edge 1 to 10: req 0 1 0 0 0 0 0 0 1 0; ok 1 1 1 1 1 1 0 1 1 1.

Standard behaviour, derived in docs/sva-standard-traces/A3.md (sva-089).

Verilator 5.052 compiles req |-> always ok and misses its failures (measured). The runnable form is a flag that stays set after the first request. It reports each bad edge once, however many requests are open, so it matches the verdict, not the count of failed attempts.

Always [m:n] p: A Bounded Window

always [m:n] p checks p at every edge from m to n edges after the attempt starts. It passes after the last edge of the window.

Two starts, a window of two edges each
0123456789startvwindow 1 donev drops
Scroll horizontally ↔

The start at edge 1 needs v at edges 2 and 3. The start at edge 6 needs it at 7 and 8.

Always [m:$] p: An Open Window

always [m:$] p starts checking m edges after the attempt and never stops. Like always p, it is weak at the end of a test.

Req |-> Always [2:$] OkStandard behaviour for the two requests of the trace.req |-> always [2:$] okStandard behaviour, not run on this simulator
attempt startsfailstill running at the end: weak, no failure
req |-> always [2:$] okattempt @15, from edge 2 (t=15): fails at edge 7 (t=65). attempt @75, from edge 8 (t=75): is still running at the end of the run: weak, so no failure.edgetime152153254355456557658759851095end100clkreqokattemptsattempt @15attempt @15: fails at edge 7 (t=65)attempt @75attempt @75: is still running at the end of the run: weak, so no failure
Scroll horizontally ↔
  1. Edge 4 · t=35

    The window of the attempt from 15 opens at 35. The low ok at 15 and 25 does not count.

  2. Edge 7 · t=65

    ok drops at 65: fail.

  3. Edge 10 · t=95

    The attempt from 75 opens its window at 95, sees ok, and is still open at the end: no failure.

Read the lanes as text
  • attempt @15, from edge 2 (t=15): fails at edge 7 (t=65).
  • attempt @75, from edge 8 (t=75): is still running at the end of the run: weak, so no failure.

Sampled values, edge 1 to 10: req 0 1 0 0 0 0 0 1 0 0; ok 0 0 0 1 1 1 0 1 0 1.

Standard behaviour, derived in docs/sva-standard-traces/A3.md (sva-091).

Verilator 5.052 misses this failure too (measured). The runnable form bounds the window past the end of the test: always [2:8] here.

s_always [m:n] p: The Window Must Also Exist

s_always [m:n] p is the strong form. Every edge of the window must hold p, and every edge must actually happen. If the test ends inside the window, the attempt fails.

Start |-> s_always [1:3] vStandard behaviour for the three starts of the trace. The other attempts succeed vacuously and are left out.start |-> s_always [1:3] vStandard behaviour, not run on this simulator
attempt startspassfailstill running at the end: strong, fails
start |-> s_always [1:3] vattempt @15, from edge 2 (t=15): passes at edge 5 (t=45). attempt @55, from edge 6 (t=55): fails at edge 8 (t=75). attempt @85, from edge 9 (t=85): is still running at the end of the run: strong, so it fails.edgetime152153254355456557658759851095end100clkstartvattemptsattempt @15attempt @15: passes at edge 5 (t=45)attempt @55attempt @55: fails at edge 8 (t=75)attempt @85attempt @85: is still running at the end of the run: strong, so it fails
Scroll horizontally ↔
  1. Edge 5 · t=45

    v at 25, 35 and 45: the window is complete, pass.

  2. Edge 8 · t=75

    v is 0 at 75, inside the window: fail.

  3. Edge 10 · t=95

    The window of the attempt from 85 needs 95, 105 and 115. The test ends first: strong, so false.

Read the lanes as text
  • attempt @15, from edge 2 (t=15): passes at edge 5 (t=45).
  • attempt @55, from edge 6 (t=55): fails at edge 8 (t=75).
  • attempt @85, from edge 9 (t=85): is still running at the end of the run: strong, so it fails.

Sampled values, edge 1 to 10: start 0 1 0 0 0 1 0 0 1 0; v 0 0 1 1 1 0 1 0 0 1.

Standard behaviour, derived in docs/sva-standard-traces/A3.md (sva-092).

A test stops inside the windowStandardVerilator 5.052 (measured)
always [1:3] p, p held so farno failure (weak)no failure
s_always [1:3] p, p held so farthe attempt is falsefalse, but it prints its own %Error, stops with $stop, and skips the else action

The verdict is right; the report is not. The practice problems refuse s_always for this reason.

Each form takes only some windows (16.12.11). A strong form must have a finite window, so it can end.

FormStandardVerilator 5.052 (measured)
always [2:1] p (m > n)illegalrejected (error)
always [$:2] pillegal: $ only as the upper boundrejected (error)
s_always [1:$] pillegal: a strong always needs a finite windowrejected (error)
always [2:$] plegal (weak, open)compiles; failures missed
s_eventually [1:$] plegalrejected ("Unsupported")

Measured by tools/probes/sva-w1a/always-family.mjs.

Try It

held needs valid at the three edges after start. It is gone at 45, the third edge: one failure.

quiet skips the first edge after done (busy at 65 is allowed) and checks 75 to 95. busy at 85 fails it.

Change quiet to always [1:4] and predict its count.

RUNVerilator · simulator service
Edit the code, then run it
Expected: f_valid=1 f_quiet=1

Check Yourself

Predict the outputThe window starts at the go edge itself. Predict the exact output.
module tb;
  logic clk = 0;
  always #5 clk = ~clk;
  logic go = 0, en = 0;
  int fails = 0;
  rule: assert property (@(posedge clk) go |-> always [0:2] en) else fails++;
  initial begin
    @(negedge clk) go = 1;                    // go at 15, en still 0
    @(negedge clk) begin go = 0; en = 1; end  // en at 25 and 35
    repeat (3) @(negedge clk);
    $display("fails=%0d", fails);
    $finish;
  end
endmodule
ConceptA test ends while an attempt of req |-> always ok has seen ok at every edge so far. What does the standard say?
ConceptWhich window does always [2:4] p check, for an attempt at edge k?
ConceptWhich of these is illegal?

Common Mistakes

Wrong Use ##[1:3] v for "v holds for three edges".

A ranged delay is satisfied by one edge.

Fix Use always [1:3] v, or ##1 v[*3].

Before
start |-> ##[1:3] v
After
start |-> always [1:3] v

Wrong Trust Verilator 5.052 with always p or always [m:$] p.

It compiles both and misses their failures.

Fix Bound the window past the end of the test, or use a flag that stays set.

Wrong Expect a weak always to fail when the test stops inside its window.

Weak forms forgive the missing edges.

Fix Use s_always [m:n] when the window must complete, and check how your tool reports it.

Remember

  • always [m:n] p needs p at every edge of the window; it passes after the last one.
  • always p and always [m:$] p are open and weak: they can fail but never pass, and a clean end of test does not fail them.
  • s_always [m:n] p also needs the window to complete; strong forms need a finite window.
  • Verilator 5.052 misses open always failures and reports a cut s_always with its own error.

Practice

Report a problem with this page