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 sequence may contain and what only a property may 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.

A Property Built from Named PiecesA property instance at the top, two named sequences under it, and the Boolean expressions at the leaves.
  • Property
  • Structure
data: where the transaction goes
A property built from named piecesA property instance at the top, two named sequences under it, and the Boolean expressions at the leaves. property within4(trig,resp) named property property accepted(arvalid,arready) named sequence property beat named sequence property arvalid &&arready Boolean property rvalid && rready Boolean trigrespbodybody
  1. property within4(trig, resp)named property
    • trig → accepted(arvalid, arready)
    • resp → beat
  2. property accepted(arvalid, arready)named sequence
    • body → arvalid && arready
  3. property beatnamed sequence
    • body → rvalid && rready
  4. property arvalid && arreadyBoolean
  5. property rvalid && rreadyBoolean
  1. The property

    One named property holds the timing rule. Its arguments say what starts it and what answers it.

  2. Named sequences as arguments

    Each argument is itself a named piece, written once and reused.

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

sequenceproperty
Booleans, ##, repetitionsyesyes
sequence and, or, intersect, within, throughout, first_matchyesyes
|->, |=>, not, implies, iffnoyes
until, always, eventually, nexttime, if/casenoyes
disable iffnoyes, at the top
an instance of a named propertynoyes
used as an event: @(s), s.triggeredyesno
used in cover sequenceyesno

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.

modeas logic vas logic [1:0] v
101101
110010
011111

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

CaseStandard (IEEE 1800-2023 16.8)Verilator 5.052 (measured)
untyped formal of a property, 4-bit actualfull widthfull width
untyped formal of a sequence, 4-bit actualfull widthbit 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] toobit 0 only: b == 4'd10 fails when b is 10
untyped property formals declared after a typed sequence formallegalrejected ("untyped property port following a typed port"); writing untyped compiles
an untyped formal used as a cycle delay, with a constant actuallegalrejected

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.

resp_by(req, Ack) with the Default n = 2Standard behaviour of the property resp_by with its default actual, for the two requests of the trace. The other attempts succeed vacuously and are left out.resp_by(req, ack)Standard behaviour, not run on this simulator
attempt startspassfail
resp_by(req, ack) with the default n = 2attempt @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).edgetime152153254355456557658759851095clkreqackattemptsattempt @5attempt @5: passes at edge 3 (t=25)attempt @45attempt @45: fails at edge 7 (t=65)
Scroll horizontally ↔
  1. Edge 1 · t=5

    req is 1. With n = 2 the window is the edges at 15 and 25.

  2. Edge 3 · t=25

    ack is 1 at 25: the attempt from 5 passes.

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

then_done(two_beats, Done)Standard behaviour of a property with a sequence-typed formal, for three attempts. The antecedent is two edges of vld; done is checked one edge after its match.then_done(two_beats, done)Standard behaviour, not run on this simulator
attempt startspassfail
then_done(two_beats, done)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).edgetime152153254355456557658759851095clkvlddoneattemptsattempt @5attempt @5: passes at edge 3 (t=25)attempt @45attempt @45: fails at edge 7 (t=65)attempt @55attempt @55: passes at edge 8 (t=75)
Scroll horizontally ↔
  1. Edge 2 · t=15

    vld at 5 and 15: two_beats matches at 15 for the attempt from 5.

  2. Edge 3 · t=25

    done is 1 at 25: that attempt passes.

  3. Edge 7 · t=65

    The attempt from 45 matches at 55 and needs done at 65. done is 0: fail.

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

UseStandard (16.16)Verilator 5.052 (measured)
sequence s; a ##1 b; endsequence in @(posedge clk) sposedge clkposedge clk
sequence s; @(negedge clk) a ##1 b; endsequence in assert property (s)negedge clknegedge clk
the clocked s as the antecedent of a property with no clock: s |=> cnegedge clk, the clock flows onrejected ("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.

RUNVerilator · simulator service
Edit the code, then run it
Expected: f_quick=1 f_hold=1

Check Yourself

Predict the outputA typed sequence checks two lanes of a 4-bit vector. Predict the exact output.
module tb;
  logic clk = 0;
  always #5 clk = ~clk;
  logic [3:0] lanes = 4'b0011;
  int fails = 0;
  sequence two_lanes(logic [1:0] v);
    v == 2'b11;
  endsequence
  a1: assert property (@(posedge clk) two_lanes(lanes)) else fails++;
  initial begin
    @(negedge clk) lanes = 4'b0111;
    @(negedge clk) lanes = 4'b1011;
    @(negedge clk) lanes = 4'b0001;
    @(negedge clk) $display("fails=%0d", fails);
    $finish;
  end
endmodule
ConceptWhich of these may appear inside a sequence declaration?
Conceptproperty resp_by(start, done, int n = 2); start |-> ##[1:n] done; endproperty is used as resp_by(req, ack). What does the standard check?
ConceptA sequence formal has no type, and Verilator 5.052 is given an 8-bit actual. What happens?
Conceptsequence s; a ##1 b; endsequence is used in assert property (@(negedge clk) s). Which clock does s run on?

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.

Before
sequence ok; req |=> ack; endsequence
After
sequence handshake; req ##1 ack; endsequence
property ok; $rose(req) |-> handshake; endproperty

Wrong 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, until and always belong 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 sequence formal 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.

Practice

Report a problem with this page