Friday, March 02, 2012

Array Manipulation Method

Array Manipulation Methods

SystemVerilog provides several built-in methods to facilitate array searching, ordering, and reduction.

Array Locator Methods

Array locator methods operate on any unpacked array, including queues, but their return type is a queue. These locator methods allow searching an array for elements (or their indexes) that satisfies a given expression. Array locator methods traverse the array in an unspecified order. The optional with expression should not include any side effects; if it does, the results are unpredictable.

The prototype of these methods is:

function array_type [$] locator_method (array_type iterator = item);

The following locator methods are supported (the with clause is mandatory) :

find() returns all the elements satisfying the given expression
find_index() returns the indexes of all the elements satisfying the given expression
find_first() returns the first element satisfying the given expression
find_first_index() returns the index of the first element satisfying the given expression
find_last() returns the last element satisfying the given expression
find_last_index() returns the index of the last element satisfying the given expression.

Array Ordering Methods

Array ordering methods can reorder the elements of one-dimensional arrays or queues.

The general prototype for the ordering methods is:

function void ordering_method ( array_type iterator = item )

Array Reduction Methods

Array reduction methods can be applied to any unpacked array to reduce the array to a single value. The expression within the optional with clause can be used to specify the item to use in the reduction.

The prototype for these methods is:

function expression_or_array_type reduction_method (array_type iterator = item)

Iterator index querying

The expressions used by array manipulation methods sometimes need the actual array indexes at each iteration, not just the array element. The index method of an iterator returns the index value of the specified dimension.

function int_or_index_type index ( int dimension = 1 )

No comments:

Post a Comment

Popular Posts