0% found this document useful (0 votes)
275 views

Array Manipulation Methods in SystemVerilog With Example

SystemVerilog provides built-in methods for searching, ordering, and reducing arrays. These include locator methods like find() and find_index() that return elements or indices matching a condition, ordering methods like sort() and reverse() that rearrange elements, and reduction methods like sum() and product() that compute a single value from an array. Most methods accept an optional expression to evaluate on each element.

Uploaded by

Dan Kumar Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
275 views

Array Manipulation Methods in SystemVerilog With Example

SystemVerilog provides built-in methods for searching, ordering, and reducing arrays. These include locator methods like find() and find_index() that return elements or indices matching a condition, ordering methods like sort() and reverse() that rearrange elements, and reduction methods like sum() and product() that compute a single value from an array. Most methods accept an optional expression to evaluate on each element.

Uploaded by

Dan Kumar Yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Array Manipulation Methods in SystemVerilog with

example
SV provides build in methods to facilitate searching from array, array ordering and reduction.
Array locator methods:
Array locator methods operate on any unpacked array, including queues, but their return type is a
queue.

Element locator methods (with clause is mandatory):


find() returns all the elements satisfying the given expression.
find_first() returns the first element satisfying the given expression.
find_last() returns the last element satisfying the given expression.

Index locator methods (with clause is mandatory):


find_index() returns the indices of all the elements satisfying the given expression.
find_first_index() returns the index of the first element satisfying the given expression.
find_last_index() returns the index of the last element satisfying the given expression.

Index locator methods return a queue of int for all arrays except associative arrays, which return a
queue of the same type as the associative index type.
arrays that specify a wildcard index type shall not be allowed.

If no elements satisfy the given expression or the array is empty (in the case of a queue or dynamic
array), then an empty queue is returned.

Index locator methods return a queue with the indices of all items that satisfy the expression.

The optional expression specified by the with clause shall evaluate to a Boolean value.


Element locator methods (with clause is optional):
min() returns the element with the minimum value or whose expression evaluates to a minimum.
max() returns the element with the maximum value or whose expression evaluates to a maximum.
unique() returns all elements with unique values or whose expression evaluates to a unique value.
unique_index() returns the indices of all elements with unique values or whose expression evaluates
to a unique value
Array reduction methods:
Array reduction methods may be applied to any unpacked array of integral values to reduce the array
to a single value

sum() returns the sum of all the array elements or, if a with clause is specified, returns the sum of the
values yielded by evaluating the expression for each array element.

product() returns the product of all the array elements or, if a with clause is specified, returns the
product of the values yielded by evaluating the expression for each array element.

and() returns the bitwise AND ( & ) of all the array elements or, if a with clause is specified, returns
the bitwise AND of the values yielded by evaluating the expression for each array element.

or() returns the bitwise OR ( | ) of all the array elements or, if a with clause is specified, returns the
bitwise OR of the values yielded by evaluating the expression for each array element.

xor() returns the bitwise XOR ( ^ ) of all the array elements or, if a with clause is specified, returns the
bitwise XOR of the values yielded by evaluating the expression for each array element.
Array ordering methods:
Array ordering methods reorder the elements of any unpacked array (fixed or dynamically sized)
except for associative arrays.

reverse() reverses the order of the elements in the array. Specifying a with clause shall be a compiler
error.

sort() sorts the array in ascending order, optionally using the expression in the with clause.

rsort() sorts the array in descending order, optionally using the expression in the with clause.

shuffle() randomizes the order of the elements in the array. Specifying a with clause shall be a
compiler error.

You might also like