Part 3: Sequence Match Operators
Prev: More Sequence Match Operators
Next: Property Layer
Local Variables in A Sequence
SystemVerilog sequences can have local variables. For each attempt
to match a sequence, a new copy of the local variable is created
and no hierarchical access to these local variables are allowed.
A local variable is assigned a value using a comma separated list
along with other expressions. In the example below, i is
local variable within the sequence seq1 which is assigned
a value of tag_in when data_valid is high. This
value is then checked with the value of tag_out 7 clock
(data_valid, (i = tag_in))
##7 (tag_out == i);
One important thing to note above is that inputs are often pipelined
in a design. For instance, by the time of the comparison of
tag_out with i, the value of tag_in that was
stored may have been lost. Thus, using a local variable is
very useful here.
A local variable is not accessible from outside of the sequence where
it is instantiated. This applies even to other sequences that will call
this sequence. The only way of accessing a local variable is to pass it
as an argument. Certain rules apply when a local variable is passed as
- A local variable can be passed only as an entire actual argument.
- Outside the sequence that instantiate a local variable, the
corresponding argument can not be reference before the local variable is
assigned in the sequence.
System Functions Helpful for Assertion
The following functions in Figure 6 help in assertion formation, but can be used
anywhere in SystemVerilog code.
| $onehot (expression)
|| true, if only one of the bits in the expression is high.
| $onehot0 (expression)
|| true, if at most one of the bit in the expression is high.
| $isunknown (expression)
|| true, if any bit of the expression is X or Z.
| $countones (expression)
|| returns the number of 1s in a bit vector expression.
Figure 6. Sampled Value System Functions
With this we conclude this part and our discussion on sequences.
Next time, we will look into the next layer of concurrent assertion
- the property layer.
Prev: More Sequence Match Operators |
Next: Property Layer