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] pfor a property that must hold through a window. - Read unbounded
always pandalways [m:$] p, and their weak end of test. - Tell
s_always [m:n]fromalways [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.
- Step
- Property
- Control
- A bounded window
The attempt passes when the last edge of the window has been checked.
- 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.
- Edge 7 · t=65
ok drops at 65: the attempt from 15 fails.
- 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.
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.
- Edge 4 · t=35
The window of the attempt from 15 opens at 35. The low ok at 15 and 25 does not count.
- Edge 7 · t=65
ok drops at 65: fail.
- 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.
- Edge 5 · t=45
v at 25, 35 and 45: the window is complete, pass.
- Edge 8 · t=75
v is 0 at 75, inside the window: fail.
- 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 window | Standard | Verilator 5.052 (measured) |
|---|---|---|
always [1:3] p, p held so far | no failure (weak) | no failure |
s_always [1:3] p, p held so far | the attempt is false | false, 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.
Legal Bounds
Each form takes only some windows (16.12.11). A strong form must have a finite window, so it can end.
| Form | Standard | Verilator 5.052 (measured) |
|---|---|---|
always [2:1] p (m > n) | illegal | rejected (error) |
always [$:2] p | illegal: $ only as the upper bound | rejected (error) |
s_always [1:$] p | illegal: a strong always needs a finite window | rejected (error) |
always [2:$] p | legal (weak, open) | compiles; failures missed |
s_eventually [1:$] p | legal | rejected ("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.
f_valid=1 f_quiet=1Check Yourself
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].
start |-> ##[1:3] vstart |-> always [1:3] vWrong 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] pneeds p at every edge of the window; it passes after the last one.always pandalways [m:$] pare open and weak: they can fail but never pass, and a clean end of test does not fail them.s_always [m:n] palso 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.