Lesson 10: SVA Sequences, Properties and bind
A SystemVerilog sequence describes signal values over several clocks: a ##1 b means a, then b one clock later, and (a)[*3] means a on three clocks in a row. A property combines sequences with implication and adds a clock and a reset condition, and an assertion checks the property on every clock. Named sequences and properties make long rules readable and reusable, and a bind statement attaches the module that holds them to a design without editing it. Together they check whole transactions, such as "sixteen writes into an empty FIFO fill it", not just single clocks.
Learning objectives
- Write sequences with cycle delays, consecutive repetition [*n] and goto repetition [->n]
- Name sequences and properties, carry a value through a sequence with a local variable, and combine sequences with throughout
- Bind a checker module into every instance of a design, and read which multi-clock rule failed and when
- Recognize the simulator limits that make an assertion silently do nothing, and test for them
Prerequisites
- Lesson 9: immediate and concurrent assertions, implication and bind
- Lesson 2: the environment that drives the FIFO here
- The running example is the synchronous FIFO: 16 entries of 8 bits, one clock, flags full and empty and an occupancy count; writes when full are dropped, reads when empty are ignored, and read data appears one clock after the read. Its shared testbench code is in the site's repository under scripts/verification/fifo, and every example runs in AMD Vivado xsim 2025.2.
Sequences and repetition
A sequence is a list of boolean expressions separated by cycle delays. ##1 means the next clock, ##[1:3] any of the next one to three clocks. Consecutive repetition, b[*n], means b on n clocks in a row. Goto repetition, b[->n], means the n-th clock on which b is true, with any number of clocks in between; it ends exactly on that clock. Non-consecutive repetition, b[=n], is the same but may end later, on any clock before b is true again.
Named sequences and properties
A named sequence can be used inside several properties, and a named property can be asserted, assumed or covered. The FIFO's fill rule names the sixteen-write sequence and uses it as the antecedent: if the FIFO is empty and sixteen writes follow with no read, it must be full with count 16 on the next clock. The repetition count is a parameter, a constant.
// A named sequence: DEPTH writes in a row with no read. The count is a parameter, a constant: xsim 2025.2 did not
// evaluate a repetition count passed in as a sequence argument correctly in these runs.
localparam int DEPTH = 16;
sequence s_fill_writes;
(wr_en && !rd_en)[*DEPTH];
endsequence
// 1. Sixteen writes in a row into an empty FIFO fill it: full, and count shows 16.
property p_fill;
@(posedge clk) disable iff (rst) empty ##0 s_fill_writes |=> full && count == DEPTH;
endproperty
a_fill: assert property (p_fill) begin passes[0]++; end else if (++fails[0] <= 3) $error("16 writes from empty: full %0d, count %0d", $sampled(full), $sampled(count));
// 2. The read that takes the last entry empties the FIFO on the next clock.
a_last_read: assert property (@(posedge clk) disable iff (rst) count == 1 && rd_en && !wr_en |=> empty)
begin passes[1]++; end else if (++fails[1] <= 3) $error("empty is %0d after the last entry was read", $sampled(empty));
Local variables and throughout
A property can declare a local variable and assign it inside a sequence, so a value seen at one clock can be compared at a later one. The first-out rule stores the value written into an empty FIFO and checks it is the next value read. The throughout operator holds a condition for the whole length of a sequence: with no reads at any point, the FIFO is full right after its sixteenth accepted write.
// 3. A local variable carries a value through the sequence: a value written into an empty FIFO is the next one read.
property p_first_out;
logic [7:0] v;
@(posedge clk) disable iff (rst) (empty && wr_en && !rd_en, v = wr_data) ##1 (!wr_en)[*0:4] ##1 (rd_en && !wr_en) |=> rd_data == v;
endproperty
a_first_out: assert property (p_first_out) begin passes[2]++; end else if (++fails[2] <= 3) $error("first value out was %0d", $sampled(rd_data));
// 4. Goto repetition and throughout: with no reads, the FIFO is full right after the sixteenth accepted write.
a_full_after_16: assert property (@(posedge clk) disable iff (rst)
(empty && wr_en && !rd_en) ##0 ((!rd_en) throughout (wr_en && !full)[->16]) |=> full)
begin passes[3]++; end else if (++fails[3] <= 3) $error("not full after 16 writes");
Binding the checker
The four rules live in the module fifo_props, and a bind statement puts an instance of it, called props, inside every sync_fifo and every sync_fifo_planted. The design files are not edited, and any test that uses the FIFO gets the rules. A bind can also name one instance path instead of a module, to check only one copy of a design.
bind sync_fifo fifo_props props (.*);
bind sync_fifo_planted fifo_props props (.*);
Worked example: two new planted bugs
The test is Lesson 2's environment with a directed start (sixteen writes from empty, then sixteen reads) followed by Lesson 7's random traffic. Each rule counts its passes and failures. On the real FIFO every rule passes and none fails; the fill rule ran once, on the directed fill.
696 clocks checked, 312 writes, 309 reads, 0 errors: PASS
passes: fill 1, last_read 41, first_out 8, full_after_16 1
failures: fill 0, last_read 0, first_out 0, full_after_16 0
Planted bug 4 drops the top bit of count, so a full FIFO shows count 0. The fill rule catches it at the end of the directed fill: the attempt started at 35 ns, the first write, and failed at 195 ns, one clock after the sixteenth. The scoreboard sees it too, because it compares the count every clock.
Time: 195 ns Started: 35 ns Scope: /fifo_props_tb/dut/props File: fifo_props.sv Line:16
Error: 16 writes from empty: full 1, count 0
696 clocks checked, 312 writes, 309 reads, 44 errors: FAIL
failures: fill 1, last_read 0, first_out 0, full_after_16 0
Planted bug 6 raises empty one clock late after the read that takes the last entry. On that clock the FIFO accepts a read from an empty FIFO, and count wraps to 31. The last-read rule names the exact clock; the scoreboard reports hundreds of errors that all follow from it.
Time: 355 ns Started: 345 ns Scope: /fifo_props_tb/dut/props File: fifo_props.sv Line:19
Error: empty is 0 after the last entry was read
696 clocks checked, 315 writes, 402 reads, 516 errors: FAIL
failures: fill 0, last_read 10, first_out 0, full_after_16 0
Common mistakes
- Using [*n] when the events are not on consecutive clocks; goto repetition [->n] is the one that allows gaps.
- Writing ##1 between the antecedent's last term and the consequent and also using |=>, which adds a second clock of delay.
- Passing a repetition count into a sequence as an argument. In xsim 2025.2 a typed argument gave wrong results and an untyped one switched off the module's assertions; use a parameter or a constant.
- Declaring a property with untyped formal arguments in xsim 2025.2: in these runs every assertion declared after it in the module silently stopped counting. If a rule never passes or fails, check that it was really evaluated.
- Forgetting that a rule whose antecedent never matches passes vacuously: count passes as well as failures, as fifo_props does.
Quick check
1. What is the difference between b[*3] and b[->3]?
b[*3] needs b on three consecutive clocks. b[->3] ends on the third clock where b is true, with any number of clocks between them.
2. Why does the first-out rule need a local variable?
The value to check is written at the start of the sequence and read clocks later. The local variable stores the written value so the consequent can compare rd_data with it.
3. Why did the fill rule catch planted bug 4 only once in the run?
Its antecedent needs sixteen writes in a row into an empty FIFO with no read, which only the directed start provided. Random traffic almost never produces that sequence.
Exercises
Graded from easy to hard. Try each one before you open the solution; every solution was run in xsim 2025.2, and its output is shown.
E1 (easy). A read from a full FIFO with no write leaves it not full with 15 entries. Write it as a property.
An overlapping antecedent on one clock and a non-overlapping consequent on the next. It passed the one time the traffic did that.
// E1: a read from a full FIFO, with no write, leaves it not full with 15 entries.
a_read_from_full: assert property (@(posedge clk) disable iff (vif.rst)
vif.full && vif.rd_en && !vif.wr_en |=> !vif.full && vif.count == 15) p1++; else f1++;
E1: a_read_from_full passed 1, failed 0
E2 (easy). Use $rose and $past: full only ever rises on the clock after a write was requested.
$rose(full) is true on the clock full goes from 0 to 1; $past(wr_en) is the request one clock earlier.
// E2: full only ever rises on a clock after a write was requested.
a_full_rises_after_write: assert property (@(posedge clk) disable iff (vif.rst) $rose(vif.full) |-> $past(vif.wr_en)) p2++; else f2++;
E2: a_full_rises_after_write passed 1, failed 0
E3 (medium). Write plan row F8, reset clears rd_data, the count and the flags, and use it to catch planted bug 5.
The antecedent is reset high followed by reset low; no disable iff, because the rule is about reset itself. Planted bug 5 leaves rd_data holding: it is still unknown after the first reset and still 11 after the second.
// E3: reset clears rd_data, the count and the flags. No disable iff: the rule is about reset itself.
a_reset_clears: assert property (@(posedge clk) vif.rst ##1 !vif.rst |-> vif.rd_data == 0 && vif.empty && vif.count == 0) p3++;
else begin f3++; $display("E3: after reset rd_data is %0d", vif.rd_data); end
E3: rd_data is 11 before the reset
E3: a_reset_clears passed 2, failed 0
E3: after reset rd_data is x
E3: rd_data is 11 before the reset
E3: after reset rd_data is 11
E3: a_reset_clears passed 0, failed 2
E4 (hard). Catch planted bug 1 with one property: the ninth value written into an empty FIFO is the ninth value read.
Eight writes, a ninth whose value is stored, then throughout with goto repetition: no writes while nine reads are accepted. The ninth value lands in slot 8, which planted bug 1 reads from slot 0.
// E4: the ninth value written into an empty FIFO, with no reads in between, is the ninth value read.
property p_ninth_out;
logic [7:0] v;
@(posedge clk) disable iff (vif.rst)
(vif.empty && vif.wr_en && !vif.rd_en) ##1 (vif.wr_en && !vif.rd_en)[*7] ##1 (vif.wr_en && !vif.rd_en, v = vif.wr_data)
##1 ((!vif.wr_en) throughout (vif.rd_en && !vif.empty)[->9]) |=> vif.rd_data == v;
endproperty
a_ninth_out: assert property (p_ninth_out) p4++; else begin f4++; $display("E4: ninth value out was %0d", vif.rd_data); end
E4: a_ninth_out passed 1, failed 0
E4: ninth value out was 10
clock 20: read 10, expected 90
E4: a_ninth_out passed 0, failed 1
Interview questions
- Q1. When do you use [->n] instead of [*n]? Answer: when the n events need not be on consecutive clocks, such as "the third accepted read", with other clocks in between. [*n] demands n clocks in a row.
- Q2. How do you check that data written now comes out correctly several clocks later? Answer: store it in a property local variable when it is written, describe the clocks in between with a sequence, and compare in the consequent. Here the ninth value written was checked against the ninth value read, which catches a FIFO addressing bug.
- Q3. An assertion never fails. How do you know it is checking anything? Answer: count its passes and look at them, cover its antecedent, and plant a bug it should catch. A rule that passes zero times was never really evaluated, as happened here when one malformed property silently disabled the ones after it.
Summary
- Sequences describe values over clocks with ##n delays, [*n] consecutive and [->n] goto repetition.
- Named sequences and properties, local variables and throughout turn transaction rules into readable checks.
- bind attaches the checker to every copy of the design without editing it.
- The FIFO's multi-clock rules caught planted bugs 4 and 6 at the exact clock, and the exercises catch bugs 1 and 5.
Related
Last verified
Run in Vivado xsim 2025.2 on 27 November 2026: the properties on the real FIFO and on planted bugs 4 and 6, and all four exercise solutions, with bugs 5 and 1. Outputs are copied from those runs and kept in scripts/verification/results; lib/verificationCourse.test.js checks them against this page.