System Verilog : Array querying system functions

System Verilog provides some system functions to query about arrays. The return value of this system function is int and it can be applied to all arrays.

Different array querying functions are

$dimension :
Returns the number of dimensions in the array and 1 for strings and simple bit vectors and 0 for any other type.

Here there are two dimensions for mem i.e. one packed and one unpacked ( [15:0] and 1:63]).For myarr there are two packed and two unpacked dimensions. So total 4.

$unpacked_dimensions :
Returns the number of unpacked dimensions of an array and 0 for any other type.

Here, one unpacked dimension for mem (i.e. 1:63) and 2 unpacked dimensions for myarr (2:0,3:0).

$left :
Returns the left declared bound of the dimension.

Here first unpacked dimension will be used. For mem, 1:63 is the unpacked dimension and left bound is 1.
For myarr, 2:0 is the unpacked dimension and 2 will be the $left value.

$right :
Returns the right declared bound of the dimension.

Just like $left, $right will be the right bound. So for mem, 1:63 is the dimesion and $left value is 1 and $right value is 63.For myarr $left is 2 and $right is 0.

$low :
Returns the lowest declared bound of the dimension.

Lowest declared bound of the dimension for mem is 1 and for myarr is 0.

$high :
returns the highest declared bound of the dimension.

Highest declared bound of the dimension for mem is 63 and for myarr is 2.

$increment :
Returns 1 if the left bound is greater than or equal to the right bound and -1 otherwise.

For mem, left bound is less than right bound, so returned -1.
For myarr, left bound is greater than right bound, so returned 1.

$size :
Returns the number of elements in the dimension.

Here, number of elements in mem is 63 (1:63 dimension) and myarr has 3 elements.

Leave a Reply

Your email address will not be published. Required fields are marked *