Tutorials
Protocols
Learn More
Operators in Assertions
Sequence operators describe when an event must occur and how many times it must repeat. Cycle-delay operators move a sequence forward in sampled clocks, while repetition operators describe consecutive or non-consecutive matches.
Operators at a Glance
Operator | Simple meaning |
##n | Wait exactly n sampled clock cycles |
##[m:n] | Wait from m to n sampled clock cycles |
[*n] or [*m:n] | Match on consecutive clock cycles |
[=n] or [=m:n] | Count matches; gaps are allowed |
These operators count sampling-clock edges, not simulation time. For example, ##3 means three clock edges, not three nanoseconds.
Clock delays
The ## operator places a delay between two sequence expressions. If req1 matches at cycle 0 in req1 ##3 req2, then req2 is checked at cycle 3.
1. ## : represents cycle delay
2. ##n – represents “n” clock cycles
3. ##0 – represents same clock cycle
4. ## [min:max] represents a range of clock cycles. Where min and max must be 0 or greater than 0.
Clock delay with a range
req2 may arrive on any clock from cycle 2 through cycle 6 after req1.
sequence seq;
@(posedge clk) req1 ## [2:6] req2;
endsequence If req1 is true at cycle 0, the sequence passes when req2 is true at cycle 2, 3, 4, 5, or 6. A response before cycle 2 is too early; a response after cycle 6 is too late.
Unbounded clock delay
$ represents an infinite number of clock cycles i.e. till the end of the simulation.
sequence seq;
@(posedge clk) req1 ## [2:$] req2;
endsequence After req1, req2 may match at cycle 2 or on any later sampled clock. Use this form only when the requirement truly has no maximum response time.
Repetition Operator
Consecutive repetition uses [*n] or [*m:n]. There cannot be a low cycle in the middle of the required run.
Fixed consecutive repetition
req2 must be true for three clock cycles in a row.
Example 1:
sequence seq;
@(posedge clk) req1 ##1 req2[*3];
endsequence
In this example, if req1 is true then after 1 clock cycle, req2 must be true for 3 consecutive clock cycles.
req1 ##1 req2[*3] is same as req1 ##1 req2 ##1 req2 ##1 req2. Consecutive repetition with a range
Example 2:
The repetition operator can also be used in a certain range using [*m:n] where both “m” and “n” > 0 and n can not be $.
sequence seq;
@(posedge clk) req1 ##1 req2[*2:4];
endsequence In this example, if req1 is true then after 1 clock cycle, req2 must be true for a minimum of 2 and a maximum of 4 consecutive clock cycles.
req1 ##1 req2[*2:4] is same as
req1 ##1 req2 ##1 req2 or
req1 ##1 req2 ##1 req2 ##1 req2 or
req1 ##1 req2 ##1 req2 ##1 req2 ##1 req2; Non-consecutive repetitive operator
If sequence event repetition has to be detected for n non-consecutive clock cycles then [=n] can be used where n > 0 and n can not be $.
Fixed non-consecutive repetition
req2 must be observed high four times, but the four highs do not need to be adjacent.
sequence seq;
@(posedge clk) req1 ##1 req2[=4];
endsequence In the above example, once req1 holds true after one clock cycle req2 must be true for 4 clock cycles but it is not mandatory to be consecutive clock cycles.
For example, sampled req2 values of 1, 0, 1, 0, 1, 1 contain four matches. This satisfies the count even though gaps appear between some matches.
The non-consecutive repetitive operator with a range
The non-consecutive repetition can be mentioned in a range as [=m:n] where minimum “m” and maximum “n” non-consecutive repetition.
sequence seq;
@(posedge clk) req1 ##1 req2[=2:4];
endsequence In the above example, once req1 holds true after one clock cycle, req2 must be true for a minimum of 2 and a maximum of 4 clock cycles but it is not mandatory to be consecutive clock cycles.
Remember the Difference
- Use ## to control when the next expression is checked.
- Use [*] when matches must be back-to-back.
- Use [=] when only the number of matches matters and gaps are allowed.
- For a range, both the minimum and maximum values are legal match possibilities.
SystemVerilog Assertions