What is virtual function?
In SystemVerilog, a virtual function is a type of function that allows a base class to define a function signature which can be overwritten in a derived class. This means that a virtual function can be customized by a subclass to perform a different function than the base class.
Virtual functions are an important aspect of object-oriented programming (OOP) and are used heavily in verification methodologies such as the Universal Verification Methodology (UVM). In UVM, virtual functions are used to customize the behavior of verification components and facilitate the reuse of code across different testbenches.
What is the difference between a deep copy and a shallow copy ?
A deep copy is one where nested class object contents are also entirely copied over into the new class object. A shallow copy is one where nested class objects are not copied but instead handles are simply assigned. So, if the original class object changes its contents, then the copied class also see the same contents.
Read more on SystemVerilog Copying Objects.
How will you test the functionality of interrupts using functional coverage?
Testing the functionality of interrupts using functional coverage involves the following steps:
- Define functional coverage goals: First, you need to define your functional coverage goals. These goals should be specific to the interrupts you want to test. For example, you might define goals for interrupt latency, interrupt frequency, or interrupt priority handling.
- Create a testbench for interrupts: Next, you need to create a testbench that generates interrupts with different characteristics. This testbench should also monitor the behavior of the design under test (DUT) in response to the interrupts.
- Implement functional coverage: You can then implement functional coverage in your testbench to track how often each of the defined functional goals is achieved. You can use standard SystemVerilog constructs like covergroups, coverpoints, and bins to define and track the functional coverage.
- Analyze the functional coverage results: Finally, you can analyze the functional coverage results to determine how well your testbench tests the desired interrupt functionality. Based on the results, you can make adjustments to your testbench to improve the tests.
The examples in SystemVerilog Concurrent Assertions checked simple boolean expressions on every single clock edge. But sequential checks take several clock cycles to complete, and the time delay between two parts of a sequence is specified with the ## operator.
12 min read | Intermediate Level
What You'll Learn
- What the
##operator means inside a sequence, and how it differs from a plain boolean check - Why a fresh attempt at the sequence starts on every clock edge, resulting in several overlapping instances tracked in parallel
- How to read a "started at Xns, failed/passed at Yns" log message for one specific pipelined instance
- Why a sequence's outcome for a given attempt is only known some cycles after it starts, not immediately
The ## Operator
If a is not high on a given clock cycle, that attempt at the sequence starts and fails on the very same cycle. But if a is high, the attempt starts and succeeds if b is high exactly 2 clocks later — it fails if b is low 2 clocks later instead:
module tb;
bit a, b;
bit clk;
// This is a sequence that says 'b' should be high 2 clocks after
// 'a' is found high. The sequence is checked on every positive
// edge of the clock which ultimately ends up having multiple
// assertions running in parallel since they all span for more
// than a single clock cycle.
sequence s_ab;
@(posedge clk) a ##2 b;
endsequence
// Print a display statement if the assertion passed
assert property(s_ab)
$display ("[%0t] Assertion passed !", $time);
always #10 clk = ~clk;
initial begin
for (int i = 0; i < 10; i++) begin
@(posedge clk);
a <= $random;
b <= $random;
$display("[%0t] a=%b b=%b", $time, a, b);
end
#20 $finish;
end
endmodule
Multiple Instances Run in Parallel
Since the assertion is checked on every clock edge, a brand-new attempt at s_ab begins each time — and since each attempt takes 2 full cycles to resolve, several attempts end up "in flight" at once, each independently tracked from its own starting point:
| Time (ns) | a | b | Sequence Start | Result |
|---|---|---|---|---|
| 10 | 0 | 0 | No | FAIL (Start@10, Fail@10) |
| 30 | 0 | 1 | No | FAIL (Start@30, Fail@30) |
| 50 | 1 | 1 | Yes | |
| 70 | 1 | 1 | Yes | |
| 90 | 1 | 0 | Yes | FAIL (Start@50, Fail@90) |
| 110 | 1 | 1 | Yes | PASS (Start@70, Pass@110) |
| 130 | 0 | 1 | No | PASS (Start@90, Pass@130) |
| 150 | 1 | 0 | Yes | FAIL (Start@110, Fail@150) |
| 170 | 1 | 0 | Yes | |
| 190 | 1 | 0 | Yes | FAIL (Start@150, Fail@190) |
Walking through two specific instances end to end makes the pattern concrete:
- At 50ns,
a=1, so an attempt starts there. It needsb=1two edges later, at 90ns — butb=0at 90ns, so this specific attempt fails, reported on the 90ns row asFAIL (Start@50, Fail@90). - At 70ns, a separate attempt starts (
a=1again). It needsb=1at 110ns — andb=1there, so this attempt passes, reported on the 110ns row asPASS (Start@70, Pass@110).
Notice these two attempts overlap in time — the one started at 50ns is still unresolved when the one at 70ns begins, and both are being tracked simultaneously. Each row in the table can carry two separate pieces of information: whether a new attempt starts on that exact edge, and whether some earlier attempt happens to resolve on that same edge.
Output
Compiler version P-2019.06-1; Runtime version P-2019.06-1; Jan 16 06:49 2020
[10] a=0 b=0
"testbench.sv", 14: tb.unnamed$$_0: started at 10ns failed at 10ns
Offending 'a'
[30] a=0 b=1
"testbench.sv", 14: tb.unnamed$$_0: started at 30ns failed at 30ns
Offending 'a'
[50] a=1 b=1
[70] a=1 b=1
[90] a=1 b=0
"testbench.sv", 14: tb.unnamed$$_0: started at 50ns failed at 90ns
Offending 'b'
[110] a=1 b=1
[110] Assertion passed !
[130] a=0 b=1
"testbench.sv", 14: tb.unnamed$$_0: started at 130ns failed at 130ns
Offending 'a'
[130] Assertion passed !
[150] a=1 b=0
"testbench.sv", 14: tb.unnamed$$_0: started at 110ns failed at 150ns
Offending 'b'
[170] a=1 b=0
[190] a=1 b=0
"testbench.sv", 14: tb.unnamed$$_0: started at 150ns failed at 190ns
Offending 'b'
$finish called from file "testbench.sv", line 27.
$finish at simulation time 210
V C S S i m u l a t i o n R e p o r t
Time: 210 ns
Each log line names exactly which attempt it's reporting on, by its own start time — "started at 50ns failed at 90ns" is the same attempt traced above, and "started at 130ns failed at 130ns" is a brand-new attempt failing immediately because a=0 right at its own start.
Quick Check
Q: At 130ns, two separate things are reported: a new attempt's start status ("No"), and an older attempt's outcome ("PASS"). Which earlier attempt is that PASS actually reporting on?
Show Answer
The attempt that started at 90ns. It needed b=1 two edges later, at 130ns — and b=1 there, so it passes. This is completely independent of the fact that a different, brand-new attempt also happens to fail immediately at that same 130ns edge, since a=0 there.
Quick Check
Q: With a fresh attempt starting on every edge and each one taking exactly 2 edges to resolve, how many unresolved attempts can be "in flight" at any given moment (not counting the one resolving on that exact edge)?
Show Answer
Up to 2 — the attempt that started 1 edge ago (needing 1 more edge to resolve) and the attempt that just started this edge (needing 2 more). Since resolution always takes exactly 2 edges, no more than 2 unresolved attempts ever need to be tracked simultaneously for a ##2 delay.
Where Is This Used?
Modern pipelined bus protocols routinely have several transactions in flight at once — a second request can be issued before the first one's response has arrived. Checking a protocol like this with assertions requires exactly this overlapping-instance behavior: each request needs its own independently-tracked check for its corresponding response, without interfering with checks already in progress for earlier requests.
Common Beginner Mistakes
Mistake #1: Assuming only one sequence attempt runs at a time
As this article shows, a concurrent assertion starts a fresh attempt on every clock edge by default. Why? Several attempts can be genuinely in flight simultaneously, each tracked from its own independent starting point — a summary table or log needs to be read with that in mind, not as if only one check were ever active.
Mistake #2: Assuming a ##2 sequence's outcome is known immediately
An attempt that starts because a is high doesn't resolve until 2 full cycles later, when b is finally checked. Why? There's a real gap between when a sequence begins and when its outcome is known — assuming an assertion has already "passed" the moment its first condition is met is premature.
Mistake #3: Misreading a summary table's row-to-outcome mapping
A row showing values for a given edge doesn't necessarily report the outcome of an attempt that started on that same row. Why? As the Quick Check above shows, the outcome shown on a given row can belong to an attempt that started several rows earlier — always check the "Start@" annotation to know which attempt an outcome actually belongs to.
Mistake #4: Assuming one attempt's immediate failure affects other attempts
A new attempt failing right at its own start (because a=0 there) has no effect on any other attempt still in flight from an earlier edge. Why? Every attempt is tracked completely independently — one failing doesn't cancel, pause, or otherwise interfere with any of the others.
Practice Exercise
Challenge: Trace a ##1 Sequence
Given the sequence a ##1 b (a 1-cycle delay instead of 2), and a/b sampled at six consecutive edges as (1,0), (0,1), (1,1), (0,0), (1,1), (1,0), identify every attempt that starts, and report each one's outcome.
Hint
With a 1-cycle delay, each attempt resolves on the very next edge after it starts — there's never more than one unresolved attempt in flight at a time.
Solution
- Edge 1 (a=1): starts. Resolves at Edge 2 (b=1) → PASS
- Edge 2 (a=0): its own new attempt fails immediately
- Edge 3 (a=1): starts. Resolves at Edge 4 (b=0) → FAIL
- Edge 4 (a=0): its own new attempt fails immediately
- Edge 5 (a=1): starts. Resolves at Edge 6 (b=0) → FAIL
- Edge 6 (a=1): starts, but its resolution would need a 7th edge, beyond this trace — left unresolved
With only a 1-cycle delay, each attempt is fully resolved before the next one even has a chance to overlap with it — a simpler case than the article's own ##2 example, but built on exactly the same "fresh attempt every edge" principle.
Summary
In this tutorial, you learned:
- The
##operator specifies a delay between two parts of a sequence, measured in clock cycles - A concurrent assertion starts a fresh attempt on every single clock edge, not just when its first condition happens to be true
- Because each attempt takes multiple cycles to resolve, several attempts can be genuinely in flight and independently tracked at the same time
- A log message's "started at Xns" annotation identifies exactly which attempt an outcome belongs to — which may not be the attempt that started on the same row where the outcome is reported
- One attempt failing has no effect on any other attempt still in flight from a different starting edge
A sequence is a simple building block in SystemVerilog assertions that can represent certain expressions to aid in creating more complex properties. Even a single signal name, on its own, is already a complete (if very simple) sequence.
11 min read | Intermediate Level
What You'll Learn
- How a single signal name can itself be a complete sequence
- How
$roseand$felldetect edges specifically, comparing against a default value when there's no earlier real sample yet - How
$stablediffers from both, checking for the absence of any transition at all - Why all three functions, applied to the exact same signal trace, classify each cycle differently
A Simple Sequence
module tb;
bit a;
bit clk;
// This sequence states that a should be high on every posedge clk
sequence s_a;
@(posedge clk) a;
endsequence
// When the above sequence is asserted, the assertion fails if 'a'
// is found to be not high on any posedge clk
assert property(s_a);
always #10 clk = ~clk;
initial begin
for (int i = 0; i < 10; i++) begin
a = $random;
@(posedge clk);
// Assertion is evaluated in the preponed region and
// use $display to see the value of 'a' in that region
$display("[%0t] a=%0d", $time, a);
end
#20 $finish;
end
endmodule

| Time (ns) | a | Result |
|---|---|---|
| 10 | 0 | FAIL |
| 30 | 1 | PASS |
| 50 | 1 | PASS |
| 70 | 1 | PASS |
| 90 | 1 | PASS |
| 110 | 1 | PASS |
| 130 | 1 | PASS |
| 150 | 0 | FAIL |
| 170 | 1 | PASS |
| 190 | 1 | PASS |
Output
Compiler version P-2019.06-1; Runtime version P-2019.06-1; Jan 14 06:32 2020 [10] a=0 "testbench.sv", 12: tb.unnamed$$_0: started at 10ns failed at 10ns Offending 'a' [30] a=1 [50] a=1 [70] a=1 [90] a=1 [110] a=1 [130] a=1 [150] a=0 "testbench.sv", 12: tb.unnamed$$_0: started at 150ns failed at 150ns Offending 'a' [170] a=1 [190] a=1 $finish called from file "testbench.sv", line 27. $finish at simulation time 210
This same a trace — 0, 1, 1, 1, 1, 1, 1, 0, 1, 1 across the ten sampled edges — is reused in every example below, so you can directly compare how each system function classifies the exact same signal differently.
$rose
The system function $rose detects a positive edge of the given signal. Because SystemVerilog assertions evaluate in the preponed region, $rose compares the signal's value across two samples — when the value is 0 on one and 1 on the next, a positive edge is assumed to have happened. Before the very first real sample, the "previous" value used for that comparison is the signal's default (0 for a 2-state bit), so a rise can in principle register immediately; in this particular trace, though, it genuinely takes until the second clock to see one:
module tb;
bit a;
bit clk;
// This sequence states that 'a' should rise on every posedge clk
sequence s_a;
@(posedge clk) $rose(a);
endsequence
// When the above sequence is asserted, the assertion fails if
// posedge 'a' is not found on every posedge clk
assert property(s_a);
// Rest of the testbench stimulus
endmodule

| Time (ns) | a | Transition | Result |
|---|---|---|---|
| 10 | 0 | FAIL | |
| 30 | 1 | 0->1 | PASS |
| 50 | 1 | FAIL | |
| 70 | 1 | FAIL | |
| 90 | 1 | FAIL | |
| 110 | 1 | FAIL | |
| 130 | 1 | FAIL | |
| 150 | 0 | 1->0 | FAIL |
| 170 | 1 | 0->1 | PASS |
| 190 | 1 | FAIL |
A positive edge is detected and the assertion passes at 30ns — a is 0 at 10ns and 1 at 30ns, so the rise completes right there. The same happens again at 170ns.
Compiler version P-2019.06-1; Runtime version P-2019.06-1; Jan 14 06:58 2020 [10] a=0 "testbench.sv", 12: tb.unnamed$$_0: started at 10ns failed at 10ns Offending '$rose(a)' [30] a=1 [50] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 50ns failed at 50ns Offending '$rose(a)' [70] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 70ns failed at 70ns Offending '$rose(a)' [90] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 90ns failed at 90ns Offending '$rose(a)' [110] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 110ns failed at 110ns Offending '$rose(a)' [130] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 130ns failed at 130ns Offending '$rose(a)' [150] a=0 "testbench.sv", 12: tb.unnamed$$_0: started at 150ns failed at 150ns Offending '$rose(a)' [170] a=1 [190] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 190ns failed at 190ns Offending '$rose(a)' $finish called from file "testbench.sv", line 27. $finish at simulation time 210
$fell
$fell works the same way as $rose, but detects the opposite transition — when the value is 1 on one edge and 0 on the next, a negative edge is assumed to have happened:
module tb;
bit a;
bit clk;
// This sequence states that 'a' should fall on every posedge clk
sequence s_a;
@(posedge clk) $fell(a);
endsequence
// When the above sequence is asserted, the assertion fails if
// negedge 'a' is not found on every posedge clk
assert property(s_a);
// Rest of the testbench stimulus
endmodule

| Time (ns) | a | Transition | Result |
|---|---|---|---|
| 10 | 0 | FAIL | |
| 30 | 1 | 0->1 | FAIL |
| 50 | 1 | FAIL | |
| 70 | 1 | FAIL | |
| 90 | 1 | FAIL | |
| 110 | 1 | FAIL | |
| 130 | 1 | FAIL | |
| 150 | 0 | 1->0 | PASS |
| 170 | 1 | 0->1 | FAIL |
| 190 | 1 | FAIL |
Notice 30ns and 170ns both show a marked transition (0->1), yet both still FAIL — a transition genuinely happened, just the wrong kind of transition for what $fell is checking. A negative edge is only actually detected, and the assertion passes, at 150ns.
Compiler version P-2019.06-1; Runtime version P-2019.06-1; Jan 14 07:09 2020 [10] a=0 "testbench.sv", 12: tb.unnamed$$_0: started at 10ns failed at 10ns Offending '$fell(a)' [30] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 30ns failed at 30ns Offending '$fell(a)' [50] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 50ns failed at 50ns Offending '$fell(a)' [70] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 70ns failed at 70ns Offending '$fell(a)' [90] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 90ns failed at 90ns Offending '$fell(a)' [110] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 110ns failed at 110ns Offending '$fell(a)' [130] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 130ns failed at 130ns Offending '$fell(a)' [150] a=0 [170] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 170ns failed at 170ns Offending '$fell(a)' [190] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 190ns failed at 190ns Offending '$fell(a)' $finish called from file "testbench.sv", line 27. $finish at simulation time 210
$stable
$stable checks something different from either edge-detection function: that the value hasn't changed at all between the current and previous sample, regardless of which direction a change would have gone:
module tb;
bit a;
bit clk;
// This sequence states that 'a' should be stable on every clock
// and should not have posedge/negedge at any posedge clk
sequence s_a;
@(posedge clk) $stable(a);
endsequence
// When the above sequence is asserted, the assertion fails if
// 'a' toggles at any posedge clk
assert property(s_a);
// Rest of the testbench stimulus
endmodule

| Time (ns) | a | Transition | Result |
|---|---|---|---|
| 10 | 0 | PASS | |
| 30 | 1 | 0->1 | FAIL |
| 50 | 1 | PASS | |
| 70 | 1 | PASS | |
| 90 | 1 | PASS | |
| 110 | 1 | PASS | |
| 130 | 1 | PASS | |
| 150 | 0 | 1->0 | FAIL |
| 170 | 1 | 0->1 | FAIL |
| 190 | 1 | PASS |
Compiler version P-2019.06-1; Runtime version P-2019.06-1; Jan 14 07:12 2020 [10] a=0 [30] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 30ns failed at 30ns Offending '$stable(a)' [50] a=1 [70] a=1 [90] a=1 [110] a=1 [130] a=1 [150] a=0 "testbench.sv", 12: tb.unnamed$$_0: started at 150ns failed at 150ns Offending '$stable(a)' [170] a=1 "testbench.sv", 12: tb.unnamed$$_0: started at 170ns failed at 170ns Offending '$stable(a)' [190] a=1 $finish called from file "testbench.sv", line 27. $finish at simulation time 210
Comparing All Four on the Same Trace
Since every example in this article uses the exact same a trace, here's all four side by side:
| Time (ns) | a | Plain a | $rose(a) | $fell(a) | $stable(a) |
|---|---|---|---|---|---|
| 10 | 0 | FAIL | FAIL | FAIL | PASS |
| 30 | 1 | PASS | PASS | FAIL | FAIL |
| 50 | 1 | PASS | FAIL | FAIL | PASS |
| 70 | 1 | PASS | FAIL | FAIL | PASS |
| 90 | 1 | PASS | FAIL | FAIL | PASS |
| 110 | 1 | PASS | FAIL | FAIL | PASS |
| 130 | 1 | PASS | FAIL | FAIL | PASS |
| 150 | 0 | FAIL | FAIL | PASS | FAIL |
| 170 | 1 | PASS | PASS | FAIL | FAIL |
| 190 | 1 | PASS | FAIL | FAIL | PASS |
Quick Check
Q: At 10ns — the very first sampled edge, with no earlier posedge to compare against — $stable still reports a clean PASS. How can that be?
Show Answer
Before the first real clock tick, these functions compare against the expression's default sampled value rather than against nothing at all — for a 2-state bit, that default is 0. Since a's actual value at 10ns (0) matches that default, correctly sees no change. and both fail there for the same reason: compared against that same default of 0, neither a rise to 1 nor a fall to 0 actually happened.
Where Are These Used?
$rose and $fell are the standard way to detect an edge-triggered event — a handshake pulse, a mode-change strobe — without manually tracking a "previous value" register yourself. $stable is commonly used to check that a data or address bus doesn't glitch while a corresponding valid signal is asserted, since unexpected changes mid-transfer usually indicate a real bug.
Common Beginner Mistakes
Mistake #1: Assuming $rose or $fell can never register anything on the very first sampled edge
Before the first real clock tick, both functions compare against the signal's default sampled value instead of against nothing at all. Why? For a 2-state bit, that default is 0 — so if the signal's actual value at the very first sample is already 1, genuinely does report true right there, exactly like any later rise. It only looks like the first sample can never register anything because, in most of this article's own examples, that first value happens to match the default.
Mistake #2: Confusing "a transition happened" with "the right kind of transition happened"
As the $fell table shows, 30ns and 170ns both display a marked transition, yet both still fail. Why? The transition column just reports what actually happened to the signal — it doesn't mean that transition satisfies whichever specific function is being checked.
Mistake #3: Assuming the very first sampled edge is a special exception
As the corrected comparison table above shows, it isn't — and ! && ! agree at every single sample, including the very first one. Why? Before any real clock tick has occurred, these functions compare against the signal's default sampled value instead of simply failing outright, so a 2-state signal never actually produces this kind of edge case.
Mistake #4: Assuming a sequence has to combine multiple signals to be useful
The very first example in this article is a complete, legitimate sequence built from nothing but a single signal name. Why? A sequence can be as simple as one boolean expression — there's no minimum complexity required before it becomes a usable building block for a property.
Practice Exercise
Challenge: Classify a New Trace
Given the signal a sampled at six consecutive edges as 1, 1, 0, 0, 1, 0, fill in the result (PASS/FAIL) for plain a, $rose(a), $fell(a), and $stable(a) at each of the six samples.
Hint
Before the first real clock tick, $rose/$fell/$stable compare against a's default sampled value (0 for a 2-state bit) rather than against nothing at all — work out what that comparison gives when the very first sampled value is 1.
Solution
| Sample | a | Plain a | $rose(a) | $fell(a) | $stable(a) |
|---|---|---|---|---|---|
| 1 | 1 | PASS | PASS | FAIL | FAIL |
| 2 | 1 | PASS | FAIL | FAIL | PASS |
| 3 | 0 | FAIL | FAIL | PASS | FAIL |
| 4 | 0 | FAIL | FAIL | FAIL | PASS |
| 5 | 1 | PASS | PASS | FAIL | FAIL |
| 6 | 0 | FAIL | FAIL | PASS | FAIL |
Even at sample 1, with no earlier posedge yet, $rose can still register a genuine rise: compared against a's default sampled value (0 for a 2-state bit), the actual value of 1 here counts as a rise, so $rose correctly passes alongside plain a. $fell and $stable both fail for the same reason — exactly one of the three still passes, the same pattern as every other sample in this article.
Summary
In this tutorial, you learned:
- A sequence can be as simple as a single signal name, checked directly against a clocking event
$roseand$fellcompare against a default sampled value when there's no earlier real sample yet, rather than simply failing outright on the very first checked edge$stablechecks for the absence of any change at all, regardless of direction- For a single-bit signal, exactly one of
$rose,$fell, or$stablepasses at any given sample, including the very first one, since these functions compare against a well-defined default value rather than against nothing at all
Quiz
No quiz questions available for this article.