<- Click here to Toggle

Home » Resources » System Tasks & Functions » System Functions

System Functions

SystemVerilog adds several system tasks and system functions as described in the following sections.

Elaboration-time typeof function.

The $typeof system function returns a type derived from its argument. The data type returned by the $typeof system function may be used to assign or override a type parameter, or in a comparison with another $typeof, evaluated during elaboration.

Syntax:

$typeof ( expression )
$typeof ( data_type )

$typeof returns a type that represents the self-determined type result of the expression, when an expression is passed as an argument. The expression’s return type is determined during elaboration but never evaluated.

The actual value returned by $typeof is not visible to the user and is not defined.

typename function:

The $typename system function returns a string that represents the resolved type of its argument.

Syntax:

$typename ( expression )
Or $typename ( data_type )

The return string is constructed in the following steps:

$typename returns a string that represents the self-determined type result of the expression, when an expression is passed as an argument. The expression’s return type is determined during elaboration but never evaluated.

Expression Size system Function

The $bits system function returns the number of bits required to hold an expression as a bit stream.

Syntax:

$bits ( expression )
Or $bits ( type_identifier )

Take a struct example to illustrate the usage of $bits system function

typedef struct {
logic var1;
bit [16:1] var2;
} inst1;

The expression $bits(inst1) shall return 17, the number of data bits needed by a variable of type inst1.

The $bits system function returns 0 when called with a dynamically sized type that is currently empty. It is an error to use the $bits system function directly with a dynamically sized type identifier.

Range System Function

The $isunbounded system function returns true if the argument is $.

range_function ::=
$isunbounded ( constant_expression )

Shortreal conversions

$shortrealtobits and $bitstoshortreal are defined to permit exact bit transfers between a shortreal and a 32 bit vector.

[31:0] $shortrealtobits(shortreal_val) ;
shortreal $bitstoshortreal(bit_val) ;

Array Querying System Function

SystemVerilog provides system functions to return information about a particular dimension of an array variable or type. The return type is integer, and the default for the optional dimension expression is 1. An array can be a packed / unpacked /dynamic / associative / queue.

reg [3:0][2:1] n [1:5][2:8];
dimensions 3 4 1 2

For an integer N declared without a range specifier, its bounds are assumed to be [$bits(N)-1:0].

If an out-of-range dimension is specified, these functions shall return a ’x.

When used on a dynamic array or queue dimension, these functions return information about the current state of the array. If the dimension is currently empty, these functions shall return a ’x.

If the array identifier is a fixed sized array, these query functions can be used as a constant function and passed as a parameter before elaboration.