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

Arrays

document which is related to system verilog arrays

Uploaded by

leela130002
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Arrays

document which is related to system verilog arrays

Uploaded by

leela130002
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

ARRAY

Introduction

Array

unpacked array
packed array

• Fixed arrays • Dynamic arrays


• Associative arrays
• Fixed arrays
FIXED ARRAYS
❏ Array size will be constant throughout the simulation, Once the array is declared no need to create it.
By default, the array will be initialized with value ‘Zero’.
ARRAY
❏ An array is a collection of variables, all of the same type.

❏ Unpacked array : Each element of array is stored separately.Index is defined after the array identifier.

❏ Packed array : The element of the array are stored as one item. Index is defined before the array
identifier.
DYNAMIC ARRAY
❏ A dynamic array is an array whose size must change during simulation.​
❏ Memory location is created before use.​
❏ new[] method is used to create array or change the size of the array.​

Dynamic Array Methods:​


❏ size( ) –> returns the current size of a dynamic array.​
❏ delete( ) –> empties the array, resulting in a zero-sized array.​
Example code
?create an 100 elements array and modify it to store 200 elements preserving previous values in lower 100
address.
ASSOCIATIVE ARRAY

❏ When the size of the collection is unknown or the data space is sparse, an associative array is
used.
❏ In associative array, memory location is not created before use. ​

 data_type is the data type of the array elements.​


 array_id is the name of the array being declared.​
 key_type is the data-type to be used as an key.​
Examples of associative array declarations are:

int array_name[*]; //Wildcard index. can be indexed by any integral datatype.


int array_name [ string ]; // String index
int array_name [ some_Class ]; // Class index
int array_name [ integer ]; // Integer index

typedef bit signed [4:1] Nibble;


int array_name [ Nibble ]; // Signed packed array
Associative array methods
num()​ returns the number of entries in the associative array​

delete(index) method removes the entry at the specified index.

exists(index)​ returns 1 if an element exists at the specified index else returns 0​

first(var) assigns the value of first index to the variable var​

last(var)​ assigns the value of last index to the variable var​

next(var)​ assigns the value of next index to the variable var​

prev(var) assigns the value of previous index to the variable var​


Queue

 A queue is a ordered collection of homogeneous elements.​​


 Queues support insertion and deletion of elements from random locations using an index.
 In queue 0 represents the first, and $ representing the last entries.

 A queue can be bounded or unbounded.


bounded queue – queue with the number of entries limited or queue size specified
unbounded queue – queue with unlimited entries or queue size not specified
QUEUE METHODS
size() method returns the number of items in the queue. If the queue is​
empty, it returns 0.​

insert() methods inserts the given item at the specified position.

delete() methods delete the item at the specified index.

pop_front() method removes and returns the first element of queue.

pop_back method removes and returns the last element of queue.

push_front() method inserts the given element at the front of the queue.

push_back() method inserts the given element at the end of the queue.
Array querying functions

$left: return the left bound (MSB) of the dimension.


$right: return the right bound (LSB) of the dimension.
$low: return the minimum of $left and $right of the dimension.
$high: return the maximum of $left and $right of the dimension.
$increment: return 1 if $left is greater than or equal to $right and -1 if $left is less than $right.
$size: return the number of elements in the dimension.
$bits: gives the number of bits to completely represent the variable.
$dimensions: return the total number of dimensions in the array.
ARRAY MANIPULATION METHODS

 Array Locator Methods


 Array ordering methods
 Array reduction methods
 Iterator index querying
Array Locator Methods

 Array locator methods are useful for finding the index or elements of an array.
 Operate on any unpacked arrays and queues.
 Return type of these methods is a queue.
Array Locator Methods

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

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 is unique

unique_index() returns the indexes of all elements with unique values or whose expression is
unique
Array ordering methods
 Array ordering methods can reorder the elements of one-dimensional arrays or queues.

reverse() reverses all the elements of the packed or unpacked


arrays.
sort() sorts the unpacked array in ascending order, optionally
using the expression in the with clause.
rsort() sorts the unpacked array in descending order, optionally
using the with clause expression.
shuffle() randomizes the order of the elements in the array.
Array Reduction Methods

sum() - returns the sum of all the array elements.


product() - returns the product of all the array elements
and() -returns the bit-wise AND ( & ) of all the array elements.
or() -returns the bit-wise OR ( | ) of all the array elements

xor() -returns the logical XOR ( ^ ) of all the array elements.


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.

array_1.find(item) with ( item==item.index);

array_1 = '{10,20,2,40,67,5};
temp_qu = array_1.find with ( item == item.index );
THANK YOU

You might also like