 # SystemVerilog Assertion

## Part 3: Sequence Match Operators

In Part 2 of this series, we looked into operators that work on sequences as operators. In particular, we looked into various sequence repetition operators that SystemVerilog defines. In this part, we will look into the so-called 'match' sequence operators. These operators take two sequences as operands and find a match between them based on a specific criterion. But before we go into the discussion of match operators, we need to know about few system functions that work on sampled value of an expression.

## Sampled Value System Functions

Figure 3 summarizes the sampled value functions. In all of them, the use of clocking_event is optional and if absent, the default clock is used.
 Function Meaning \$rose (expression, [, clocking_event] ) true, if the least significant bit of the expression changed to 1; false, otherwise \$fell (expression, [, clocking_event] ) true, if the least significant bit of the expression changed to 0; false, otherwise \$stable (expression, [, clocking_event] ) true, if the value of the expression did not change; false, otherwise \$past (expression, [, ticks] [, expr2] [, clocking_event] ) returns the sampled value ticks clock ticks earlier (default 1) when expr2 was true (default expr2 is true)

## Sequence Match Operators

The sequence match operators take sequences as operands and produces a new sequences as a result. Sometimes, these operators also take sampled values of expressions and produces true or false as a result. Once again, just as any other construct of concurrent assertion, all evaluations of expressions or sequence matching is done only at a clock edge. Evaluation or matching has no meaning in between two clock edges.

As shown in Figure 2, the match operators are and, intersect, or, throughout, and within. We discuss each of them below.

### The AND operator

The binary operator and works in two modes. In the first mode, it works with two sampled values. In the second mode, it works with two sequences.

In the mode where it works with two sampled values, the result of and is true when both the sampled values are true. For example,

```
1. (b1 and b2)
2. (\$rose(e3) and \$fell(e4))
```
will be true when (1) both the boolean expressions b1 and b2 are true (or 1'b1) and (2) both \$rose(e3) and \$fell(e4) are true for expressions e3 and e4.

In the mode where it works with two sequences as operands, the result of and operation is a match, if

1. Both sequences must start at the same time.
2. Sequences may end at different times.
3. The end time of the match (that is when the match is recognized) is the end time of the longer sequence.

The following figure illustrates this (Figure 4). Here, sequences s1 and s2 both start at time t1. Sequence s1 ends at time t2 and s2 ends at time t3. Since their starting time is the same, s1 and s2 is a match at time t2 (later of t2 and t3). As another example, since sequences s3 and s4 do not start at the same time, regardless of anything else, they do not match. ### The INTERSECT operator

The binary operator intersect is a modified form of and operator. In this case, two sequences match if

1. They satisfy all the criteria of a match with and operator.
2. Additionally, the sequences must have the same ending time.
As an example, in Figure 4 above, both sequences s1 and s3 start and end at the same times (t1 and t2). So, (s1 intersect s2) is a match at time t2.

### The OR operator

The or operator is a binary operator similar to the and operator. And similar to the and operator, the OR operator works in two different modes.

In the first mode, the operands are sampled values of two expressions. Whenever either of the sampled value is true, the result is true.

In the other mode, the operands of the or operator are two sequences and the resultant sequence is a match whenever at least one of the operand sequences matches. The sequences do not need to start together, nor do they need to end together.

In Figure 4 above, the sequence s1 matches (or, it ends) at time t2. The sequence s2 matches at time t3. So the sequence s1 or s2 has a match at times t2 and t3.    Join Verification Management Group

Shop Amazon - Contract Cell Phones & Service Plans Book of the Month    