Named Sequences, Arguments and Subsequences
Name a sequence or property once, pass it typed, untyped, default or sequence arguments, and know its clock.
You Will Be Able To
- Say what a
sequencemay contain and what only apropertymay contain. - Write named sequences and properties with typed and untyped formal arguments.
- Read default actuals and sequence-typed arguments the way the standard expands them.
- Tell where a named sequence gets its clock: its own, or the assertion's.
- Lesson
- A2.3
- Time
- 25 min
- Runs on
- Verilator
- Check
- 5 questions
A checker library has the rule "the beat is taken within N edges" written out nine times, once per interface. A bug fix reached seven of them.
- Property
- Structure
- The property
One named property holds the timing rule. Its arguments say what starts it and what answers it.
- Named sequences as arguments
Each argument is itself a named piece, written once and reused.
- Booleans at the leaves
Expanding every name gives one flat property. That expansion is what the tool checks.
Read the diagram as text
- within4(trig, resp): named property
- accepted(arvalid, arready): named sequence
- beat: named sequence
- arvalid && arready: Boolean
- rvalid && rready: Boolean
- within4(trig, resp) → accepted(arvalid, arready): trig
- within4(trig, resp) → beat: resp
- accepted(arvalid, arready) → arvalid && arready: body
- beat → rvalid && rready: body
Fix the rule in one place, and every interface that uses it gets the fix.
This lesson builds rules from named pieces like these, one construct per section.
Sequence or Property: What Each May Hold
A sequence describes a pattern over clock ticks. A property states a rule built from sequences. The difference decides where each can be used.
sequence | property | |
|---|---|---|
Booleans, ##, repetitions | yes | yes |
sequence and, or, intersect, within, throughout, first_match | yes | yes |
|->, |=>, not, implies, iff | no | yes |
until, always, eventually, nexttime, if/case | no | yes |
disable iff | no | yes, at the top |
| an instance of a named property | no | yes |
used as an event: @(s), s.triggered | yes | no |
used in cover sequence | yes | no |
A sequence can go anywhere a property can, because a sequence is also a property. The reverse is not true.
Named Sequence
Declare a sequence once with sequence name; ... endsequence, then use its name wherever a sequence fits. The name stands for its body.
Written out twice
start |-> ##[1:2] (rvalid && rready)
(rvalid && rready) |=> !rvalid
Two copies of one idea to keep in step.
Named once
sequence beat; rvalid && rready; endsequence
start |-> ##[1:2] beat
beat |=> !rvalid
One definition, used as consequent and antecedent.
Typed Formal Arguments
A formal argument with a type, such as logic [1:0] v, receives its actual cast to that type. A wider actual loses its upper bits before the body sees it.
mode | as logic v | as logic [1:0] v |
|---|---|---|
101 | 1 | 01 |
110 | 0 | 10 |
011 | 1 | 11 |
The cast keeps the lowest bits. Choose the type on purpose.
Untyped Formal Arguments
A formal with no type takes its actual as an expression, in parentheses, at its own width. One property then works for a bit and for a byte.
A type covers every formal after it, up to the next type. So in (int n, d) both are int. A formal is untyped only when no type comes before it in the list. After a typed formal, the keyword untyped starts untyped formals again (16.8.1).
| Case | Standard (IEEE 1800-2023 16.8) | Verilator 5.052 (measured) |
|---|---|---|
| untyped formal of a property, 4-bit actual | full width | full width |
| untyped formal of a sequence, 4-bit actual | full width | bit 0 only: v == 4'd5 fails when v is 5 |
a type carried to the next formal: sequence s(logic [3:0] a, b) | b is logic [3:0] too | bit 0 only: b == 4'd10 fails when b is 10 |
| untyped property formals declared after a typed sequence formal | legal | rejected ("untyped property port following a typed port"); writing untyped compiles |
| an untyped formal used as a cycle delay, with a constant actual | legal | rejected |
Measured by tools/probes/sva-w1a/sequence-arguments.mjs. The second and third rows are silent wrong results.
Default Actual Arguments
A formal may declare a default: int n = 2. An instance that leaves the argument out gets the default. The rule below is start |-> ##[1:n] done, instanced as resp_by(req, ack), so the window is one to two edges.
- Edge 1 · t=5
req is 1. With n = 2 the window is the edges at 15 and 25.
- Edge 3 · t=25
ack is 1 at 25: the attempt from 5 passes.
- Edge 7 · t=65
The request at 45 sees no ack at 55 or 65: it fails at 65. With n = 3 it would pass at 75.
Read the lanes as text
- attempt @5, from edge 1 (t=5): passes at edge 3 (t=25).
- attempt @45, from edge 5 (t=45): fails at edge 7 (t=65).
Sampled values, edge 1 to 10: req 1 0 0 0 1 0 0 0 0 0; ack 0 0 1 0 0 0 0 1 0 0.
Standard behaviour, derived in docs/sva-standard-traces/A2.md (sva-064-p1).
Verilator 5.052 rejects a default actual ("Unsupported: property variable default value"). The runnable equivalent writes the default out in the property.
A Sequence as an Argument
A formal of type sequence takes a whole sequence. The instance behaves as if that sequence were written in place of the formal.
As written
sequence two_beats; vld ##1 vld; endsequence
property then_done(sequence s, untyped d);
s |=> d;
endproperty
then_done(two_beats, done)
A reusable property with a sequence argument.
What it means
vld ##1 vld |=> done
The sequence put in place of s, and done in place of d.
- Edge 2 · t=15
vld at 5 and 15: two_beats matches at 15 for the attempt from 5.
- Edge 3 · t=25
done is 1 at 25: that attempt passes.
- Edge 7 · t=65
The attempt from 45 matches at 55 and needs done at 65. done is 0: fail.
- Edge 8 · t=75
The attempt from 55 matches at 65, and done is 1 at 75: pass.
Read the lanes as text
- attempt @5, from edge 1 (t=5): passes at edge 3 (t=25).
- attempt @45, from edge 5 (t=45): fails at edge 7 (t=65).
- attempt @55, from edge 6 (t=55): passes at edge 8 (t=75).
Sampled values, edge 1 to 10: vld 1 1 0 0 1 1 1 0 0 0; done 0 0 1 0 0 0 0 1 0 0.
Standard behaviour, derived in docs/sva-standard-traces/A2.md (sva-065).
Verilator 5.052 rejects a sequence-typed formal ("Unsupported: sequence argument data type"). The equivalent writes the sequence in by hand.
Subsequences and Their Clocks
A named sequence may start with its own clocking event, or have none. With none, it runs on the clock of the assertion that uses it. With its own, used as the whole property, it brings that clock.
| Use | Standard (16.16) | Verilator 5.052 (measured) |
|---|---|---|
sequence s; a ##1 b; endsequence in @(posedge clk) s | posedge clk | posedge clk |
sequence s; @(negedge clk) a ##1 b; endsequence in assert property (s) | negedge clk | negedge clk |
the clocked s as the antecedent of a property with no clock: s |=> c | negedge clk, the clock flows on | rejected ("clocking event inside sequence expression") |
A sequence with a different clock inside a property makes a multiclock property: lesson A6.5.
Try It
The timing rule lives in one property with untyped formals; the hold rule is built from two typed sequences. The data change at 45, while the beat waits, breaks held.
The request at 65 gets no beat at 75, 85 or 95, so quick fails at 95. The first request was answered at 35, inside its window.
Change same to take logic [3:0] d, and make the bug write 8'hda instead of 8'h5b. The low four bits do not change: predict the counts.
f_quick=1 f_hold=1Check Yourself
Common Mistakes
Wrong Put an implication inside a named sequence.
|-> is a property operator; a sequence cannot hold it.
Fix Name the pattern as a sequence, and write the implication in a property.
sequence ok; req |=> ack; endsequencesequence handshake; req ##1 ack; endsequence
property ok; $rose(req) |-> handshake; endpropertyWrong Give a formal a narrow type without thinking about the actual.
The actual is cast first: logic [1:0] keeps only the low two bits.
Fix Match the type to the widest actual, or leave a property formal untyped.
Wrong Leave the formals of a named sequence untyped on Verilator 5.052.
It silently narrows them to one bit, so wide checks go wrong.
Fix Type every sequence formal; untyped property formals are measured correct.
Wrong Assume the order of the actuals does not matter.
Actuals bind by position: waits(rvalid, rready) and waits(rready, rvalid) are different rules.
Fix Bind by name when in doubt: waits(.v(rvalid), .r(rready)).
Remember
- A sequence is a pattern; a property is a rule. Implication,
not,untilandalwaysbelong only in properties. - Typed formals cast the actual to their type; untyped formals keep it as written.
- A default actual fills a missing argument; a
sequenceformal takes a whole sequence. Verilator 5.052 rejects both: write them out. - A named sequence without a clock inherits the assertion's clock.
- On Verilator 5.052, type every sequence formal: untyped ones are cut to one bit.