<- Click here to Toggle
Chapter 1-5
Chapter 5-10
Chapter 10-15
Chapter 15-20
Chapter 20-25
Chapter 25-30
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:
- » A typedef that creates an equivalent type is resolved back to built-in or user defined types.
- » The default signing is removed, even if present explicitly in the source
- » System generated names are created for anonymous structs, unions and enums.
- » A ‘$’ is used as the placeholder for the name of an anonymous unpacked array.
- » Actual encoded values are appended with numeration named constants.
- » User defined type names are prefixed with their defining package or scope namespace.
- » Array ranges are represented as unsized decimal numbers.
- » Whitespace in the source is removed and a single space is added to separate identifiers and keywords from each other.
$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.
- » $left shall return the left bound (msb) of the dimension
- » $right shall return the right bound (lsb) of the dimension
- » $low shall return the minimum of $left and $right of the dimension
- » $high shall return the maximum of $left and $right of the dimension
- » $increment shall return 1 if $left is greater than or equal to $right, and -1 if $left is less than $right.
- » $size shall return the number of elements in the dimension, which is equivalent to $high - $low + 1
- » $dimensions shall return the number of dimensions in the array, or 0 for a singular object
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.
