SV Verification Directory

Array Methods

Array methods are generic manipulation methods that apply to the entire array rather than iterating to every element in the array.

Basic Array Operations

  1. Copy: an array can be copied completely to another array without using a loop statement.
  2. Compare: two arrays can be compared for equality and inequality.

Keep in mind that two arrays that are being compared or copied must be of the same base type and size.

Array Reduction Methods

A basic array reduction method takes an array and reduces it to a single value. Some of the array reduction methods are as follows:

MethodDescription
sum()Calculates the sum of the array
product()returns the product of the array
and(), or(), xor()performs bitwise logical operation on the array elements

Array Locator Methods

Array locator methods provide easy and fast access to elements in an array. Some of the methods include a “with” clause, which tells SystemVerilog how to perform the search.

MethodDescprition
min()returns the minimum element in the array
max()returns the maximum element in the array
unique()returns a queue of unique values from the array, duplicates are not included
find()returns all the elements satisfying the expression, eg. find with (item >4)
find_index()returns all the index of the array that satisfies the expression
find_fisrt_index()returns the index of the first value that satisfies the expression
find_last()returns the last elements that satisfy the expression
find_last_index()returns the index of the last element that satisfies the expression

In a “with” clause, the name “item” is called the iterator argument that represents a single element of the array. You can combine an array reduction method using the with clause for some unique operations.

Array Sorting and Ordering

SystemVerilog provides a means to change the order of elements in an array with the following commands:

MethodDescription
reverse()returns an array with elements arranged from last to first
sort()returns an array in ascending order
rsort()returns an array in descending order
shuffle()randomizes the order of array

NOTE: The reverse and shuffle methods do not have a “with” clause. They work on the entire array.