You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SystemVerilog中->与=非连续重复操作符的差异咨询(基于Ashok Mehta教材)

Difference Between [=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 see a (cycle 2), then one or more non-a cycles, then a again (cycle 4).
  • Even if a appears again later (e.g., cycle 6), the assertion still passes as long as b is 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 see a (cycle 2), one or more non-a cycles, then a again (cycle 4).
  • From cycle 4 onwards, a does NOT appear again until b is seen. If a pops up in cycle 6 before b, the assertion fails.

Key Side-by-Side Comparison

Feature[=N] Non-Consecutive[->N] Goto Non-Consecutive
Post-Nth match occurrencesAllowed (ignored)Prohibited until sequence ends
Use caseEnsure N non-consecutive matches exist before the next eventEnsure the Nth match is the final occurrence before the next event
FlexibilityMore 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 11:17:38