SystemVerilog中->与=非连续重复操作符的差异咨询(基于Ashok Mehta教材)
[=N] (Non-Consecutive Repetition) and [->N] (Goto Non-Consecutive Repetition) in SystemVerilog Assertions Great question—these two operators are easy to mix up because they both handle non-consecutive matches, but their behavioral differences are critical for writing correct assertion logic. Let’s break down their core distinctions with clear examples.
Core Definitions
First, let’s clarify the formal SVA syntax (you referenced -> and =, but these are written as [->N] for goto repetition and [=N] for non-consecutive repetition):
1. Non-Consecutive Repetition ([=N])
This operator requires the target expression/sequence to match exactly N times, with at least one cycle between matches where the target does NOT match. Crucially, it doesn’t care if the target matches again after the Nth occurrence—those later matches are completely ignored.
Example:
// Assert that after start is asserted, a occurs non-consecutively twice before b is seen assert property (@(posedge clk) $rose(start) ##1 (a [=2]) ##[0:$] b );
This passes if:
- After
start, we seea(cycle 2), then one or more non-acycles, thenaagain (cycle 4). - Even if
aappears again later (e.g., cycle 6), the assertion still passes as long asbis seen at some point after cycle 4.
2. Goto Non-Consecutive Repetition ([->N])
This operator also requires exactly N non-consecutive matches, but with a strict rule: after the Nth match, the target cannot appear again until the enclosing sequence completes. The Nth match must be the final occurrence of the target before the next event in the sequence.
Example:
// Assert that after start is asserted, a occurs non-consecutively twice, and the second a is the last one before b assert property (@(posedge clk) $rose(start) ##1 (a [->2]) ##[0:$] b );
This only passes if:
- After
start, we seea(cycle 2), one or more non-acycles, thenaagain (cycle 4). - From cycle 4 onwards,
adoes NOT appear again untilbis seen. Ifapops up in cycle 6 beforeb, the assertion fails.
Key Side-by-Side Comparison
| Feature | [=N] Non-Consecutive | [->N] Goto Non-Consecutive |
|---|---|---|
| Post-Nth match occurrences | Allowed (ignored) | Prohibited until sequence ends |
| Use case | Ensure N non-consecutive matches exist before the next event | Ensure the Nth match is the final occurrence before the next event |
| Flexibility | More flexible (doesn’t restrict later matches) | More strict (enforces no further matches post-Nth) |
When to Use Which?
- Use
[=N]when you just need to verify that the target happened N times (non-consecutively) at some point—you don’t care if it happens again later. For example: "Ensure the reset signal was asserted twice before the module initialized." - Use
[->N]when you need the Nth occurrence to be the last one before a critical event. For example: "Ensure the third error pulse is the final one before the system triggers a reset."
Content of the question originates from Stack Exchange, asked by Prasanna Shanbhogue

