Array Manipulation Methods in SystemVerilog With Example
Array Manipulation Methods in SystemVerilog With Example
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.
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.
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.