unpacked_array

virtual class unpacked_array #(type T =  bit,
int SIZE =  1)

A parameterized class that manages an unpacked array.

Parameters

Toptional The type of an unpacked array.  The default type is bit.
SIZEoptional The size of an unpacked array.  The default is 1.
Summary
unpacked_arrayA parameterized class that manages an unpacked array.
Common Arguments
Types
ua_typeThe shorthand of the unpacked array type of type T.
da_typeThe shorthand of the dynamic array type of type T.
q_typeThe shorthand of the queue type of type T.
Functions
from_dynamic_arraystatic Converts a dynamic array of type T to un unpacked array of the same type.
to_dynamic_arraystatic Converts an unpacked array of type T to a dynamic array of the same type.
from_queuestatic Converts a queue of type T to an unpacked array of the same type.
to_queuestatic Converts an unpacked array of type T to a queue of the same type.
da_to_uastatic Converts a dynamic array of type T to an unpacked array of the same type.
ua_to_dastatic Converts an unpacked array of type T to a dynamic array of the same type.
q_to_uastatic Converts a queue of type T to an unpacked array of the same type.
ua_to_qstatic Converts an unpacked array of type T to a queue of the same type.
initstatic Initializes the each element of the given unpacked array to the specified value.
reversestatic Reverses the order of the elements of the given unpacked array.
comparestatic Compares two unpacked arrays.
to_stringstatic Converts an unpacked array to the form of a string.

Common Arguments

from_indexThe index of the first element of an unpacked array to be processed.  If negative, the index counts from the last.  For example, if from_index is -9, a function starts at the ninth element (inclusive) from the last.  The default is 0 (starts at the first element).
to_indexThe index of the last element of an unpacked array to be processed.  If negative, the index counts from the last.  For example, if to_index is -3, a function ends at the third element (inclusive) from the last.  The default is -1 (ends at the last element).

Types

ua_type

typedef T ua_type[SIZE]

The shorthand of the unpacked array type of type T.

da_type

typedef T da_type[]

The shorthand of the dynamic array type of type T.

q_type

typedef T q_type[$]

The shorthand of the queue type of type T.

Functions

from_dynamic_array

static function ua_type from_dynamic_array(const ref da_type da,  
input bit reverse =  0)

static Converts a dynamic array of type T to un unpacked array of the same type.  If the size of the dynamic array is larger than SIZE, the excess elements are ignored.  If the size of the dynamic array is smaller than SIZE, the default value of type T is used for the missing elements.

Arguments

daA dynamic array to be converted.
reverseoptional If 0, the element at the index 0 of da is positioned to the index 0 of the unpacked array.  If 1, the elements are positioned in the reverse order.  The default is 0.

Returns

An unpacked array converted from da.

Example

bit da[] = new[8]( '{ 0, 0, 0, 1, 1, 0, 1, 1 } ); // da[0] to da[7]
bit ua0[8] =       '{ 0, 0, 0, 1, 1, 0, 1, 1 };
bit ua1[8] =       '{ 1, 1, 0, 1, 1, 0, 0, 0 };

assert( unpacked_array#(bit,8)::from_dynamic_array( da                ) == ua0 );
assert( unpacked_array#(bit,8)::from_dynamic_array( da, .reverse( 1 ) ) == ua1 );

See Also

da_to_ua

to_dynamic_array

static function da_type to_dynamic_array(const ref ua_type ua,  
input bit reverse =  0)

static Converts an unpacked array of type T to a dynamic array of the same type.

Arguments

uaA unpacked array to be converted.
reverseoptional If 0, the element at the index 0 of ua is positioned to the index 0 of the dynamic array.  If 1, the elements are positioned in the reverse order.  The default is 0.

Returns

A dynamic array converted from ua.

Example

bit ua[8] =         '{ 0, 0, 0, 1, 1, 0, 1, 1 }; // assigned to ua[0:7]
bit da0[] = new[8]( '{ 0, 0, 0, 1, 1, 0, 1, 1 } );
bit da1[] = new[8]( '{ 1, 1, 0, 1, 1, 0, 0, 0 } );

assert( unpacked_array#(bit,8)::to_dynamic_array( ua                ) == da0 );
assert( unpacked_array#(bit,8)::to_dynamic_array( ua, .reverse( 1 ) ) == da1 );

See Also

ua_to_da

from_queue

static function ua_type from_queue(const ref q_type q,  
input bit reverse =  0)

static Converts a queue of type T to an unpacked array of the same type.  If the size of the queue is larger than SIZE, the excess elements are ignored.  If the size of the queue is smaller than SIZE, the default valus of type T is used for the missing elements.

Arguments

qA queue to be converted.
reverseoptional If 0, the element at the index 0 of q is positioned to the index 0 of the unpacked array.  If 1, the elements are positioned in the reverse order.  The default is 0.

Returns

An unpacked array converted from q.

Example

bit q[$]   =  { 0, 0, 0, 1, 1, 0, 1, 1 }; // q[0] to q[7]
bit ua0[8] = '{ 0, 0, 0, 1, 1, 0, 1, 1 };
bit ua1[8] = '{ 1, 1, 0, 1, 1, 0, 0, 0 };

assert( unpacked_array#(bit,8)::from_queue( q                ) == ua0 );
assert( unpacked_array#(bit,8)::from_queue( q, .reverse( 1 ) ) == ua1 );

See Also

q_to_ua

to_queue

static function q_type to_queue(const ref ua_type ua,  
input bit reverse =  0)

static Converts an unpacked array of type T to a queue of the same type.

Arguments

uaAn unpacked array to be converted.
reverseoptional If 0, the element at the index 0 of ua is positioned to the index 0 of the queue.  If 1, the elements are positioned in the reverse order.  The default is 0.

Returns

A queue converted from ua.

Example

bit ua[8] = '{ 0, 0, 0, 1, 1, 0, 1, 1 }; // assigned to ua[0:7]
bit q0[$] =  { 0, 0, 0, 1, 1, 0, 1, 1 };
bit q1[$] =  { 1, 1, 0, 1, 1, 0, 0, 0 };

assert( unpacked_array#(bit,8)::to_queue( ua                ) == q0 );
assert( unpacked_array#(bit,8)::to_queue( ua, .reverse( 1 ) ) == q1 );

See Also

ua_to_q

da_to_ua

static function void da_to_ua(const ref da_type da,  
ref ua_type ua,  
input bit reverse =  0)

static Converts a dynamic array of type T to an unpacked array of the same type.  Unlike from_dynamic_array, this function populates the unpacked array passed by reference, instead of returning a new unpacked array.  If the size of the dynamic array is larger than SIZE, the excess elements are ignored.  If the size of the dynamic array is smaller than SIZE, the default value of type T is used for the missing elements.

Arguments

daA dynamic array to be converted.
uaAn unpacked array to be populated.
reverseoptional If 0, the element at the index 0 of da is positioned to the index 0 of ua.  If 1, the elements are positioned in the reverse order.  The default is 0.

Returns

None.

Example

bit da[] = new[8]( '{ 0, 0, 0, 1, 1, 0, 1, 1 } ); // da[0] to da[7]
bit ua[8];
bit ua0[8] = '{ 0, 0, 0, 1, 1, 0, 1, 1 };
bit ua1[8] = '{ 1, 1, 0, 1, 1, 0, 0, 0 };

unpacked_array#(bit,8)::da_to_ua( da, ua );
assert( ua == ua0 );

unpacked_array#(bit,8)::da_to_ua( da, ua, .reverse( 1 ) );
assert( ua == ua1 );

See Also

from_dynamic_array

ua_to_da

static function void ua_to_da(const ref ua_type ua,  
ref da_type da,  
input bit reverse =  0)

static Converts an unpacked array of type T to a dynamic array of the same type.  Unlike to_dynamic_array, this function populates the dynamic array passed by reference, instead of returning a new dynamic array.

Arguments

uaAn unpacked array to be converted.
daA dynamic array to be populated.  This function does not resize da.  Make sure to set the size of the dynamic array to accommodate the elements of ua before calling this function.
reverseoptional If 0, the element at the index 0 of ua is positioned to the index 0 of da.  If 1, the elements are positioned in the reverse order.  The default is 0.

Returns

None.

Example

bit ua[8] = '{ 0, 0, 0, 1, 1, 0, 1, 1 }; // assigned to ua[0:7]
bit da [] = new[8]; // set the size of da[]
bit da0[] = new[8]( '{ 0, 0, 0, 1, 1, 0, 1, 1 } );
bit da1[] = new[8]( '{ 1, 1, 0, 1, 1, 0, 0, 0 } );

unpacked_array#(bit,8)::ua_to_da( ua, da );
assert( da == da0 );

unpacked_array#(bit,8)::ua_to_da( ua, da, .reverse( 1 ) );
assert( da == da1 );

See Also

to_dynamic_array

q_to_ua

static function void q_to_ua(const ref q_type q,  
ref ua_type ua,  
input bit reverse =  0)

static Converts a queue of type T to an unpacked array of the same type.  Unlike from_queue, this function populates the unpacked array passed by reference, instead of returning a new unpacked array.  If the size of the queue is larger than SIZE, the excess elements are ignored.  If the size of the queue is smaller than SIZE, the default valus of type T is used for the missing elements.

Arguments

qA queue to be converted.
uaAn unpacked array to be populated.
reverseoptional If 0, the element at the index 0 of q is positioned to the index 0 of ua.  If 1, the elements are positioned in the reverse order.  The default is 0.

Returns

None.

Example

bit q[$] = { 0, 0, 0, 1, 1, 0, 1, 1 }; // q[0] to q[7]
bit ua [8];
bit ua0[8] = '{ 0, 0, 0, 1, 1, 0, 1, 1 };
bit ua1[8] = '{ 1, 1, 0, 1, 1, 0, 0, 0 };

unpacked_array#(bit,8)::q_to_ua( q, ua );
assert( ua == ua0 );

unpacked_array#(bit,8)::q_to_ua( q, ua, .reverse( 1 ) );
assert( ua == ua1 );

See Also

from_queue

ua_to_q

static function void ua_to_q(const ref ua_type ua,  
ref q_type q,  
input bit reverse =  0)

static Converts an unpacked array of type T to a queue of the same type.  Unlike to_queue, this function populates the queue passed by reference instead of returning a new queue.

Arguments

uaAn unpacked array to be converted.
qA queue to be populated.
reverseoptional If 0, the element at the index 0 of ua is positioned to the index 0 of q.  If 1, the elements are positioned in the reverse order.  The default is 0.

Returns

None.

Example

bit ua[8] = '{ 0, 0, 0, 1, 1, 0, 1, 1 }; // assigned to ua[0:7]
bit q [$];
bit q0[$] = { 0, 0, 0, 1, 1, 0, 1, 1 };
bit q1[$] = { 1, 1, 0, 1, 1, 0, 0, 0 };

unpacked_array#(bit,8)::ua_to_q( ua, q );
assert( q == q0 );

q.delete();
unpacked_array#(bit,8)::ua_to_q( ua, q, .reverse( 1 ) );
assert( q == q1 );

See Also

to_queue

init

static function void init(ref ua_type ua,
input val)

static Initializes the each element of the given unpacked array to the specified value.

Arguments

uaAn unpacked array to be initialized.
valA value to initialize the elements of ua.

Returns

None.

Example

bit ua[8];
bit expected[8] = '{ 1, 1, 1, 1, 1, 1, 1, 1 };

unpacked_array#(bit,8)::init( ua, 1'b1 );
assert( ua == expected );

reverse

static function void reverse(ref ua_type ua)

static Reverses the order of the elements of the given unpacked array.

Argument

uaAn unpacked array to be reversed.

Returns

None.

Example

bit ua[8] = '{ 0, 0, 0, 0, 1, 1, 1, 1 };
bit expected[8] = '{ 1, 1, 1, 1, 0, 0, 0, 0 };

unpacked_array#(bit,8)::reverse( ua );
assert( ua == expected );

compare

static function bit compare(const ref ua_type ua1,  
const ref ua_type ua2,  
input int from_index1 =  0,
int to_index1 =  -1,
int from_index2 =  0,
int to_index2 =  -1,
comparator#(T) cmp =  null)

static Compares two unpacked arrays.

Arguments

ua1An unpacked array.
ua2Another unpacked array to compare with ua1.
from_index1optional The index of the first element of ua1 to compare.  See Common Arguments.  The default is 0.
to_index1optional The index of the last element of ua1 to compare.  See Common Arguments.  The default is -1.
from_index2optional The index of the first element of ua2 to compare.  See Common Arguments.  The default is 0.
to_index2optional The index of the last element of ua2 to compare.  See Common Arguments.  The default is -1.
cmpoptional A strategy object used to compare two unpacked arrays.  If not specified or null, comparator #(T) is used.  The default is null.

Returns

If the numbers of elements to compare (to_index1-from_index1+1 and to_index2-from_index2+1) are different, 0 is returned.  If the two unpacked arrays contain the same data in the specified range, 1 is returned.  Otherwise, 0 is returned.

Example

bit ua1[8] = '{ 0, 0, 0, 1, 1, 0, 1, 1 };
bit ua2[8] = '{ 1, 1, 0, 1, 1, 0, 0, 0 };
//                    |<------>|
//                    2        5
assert( unpacked_array#(bit,8)::compare( ua1, ua2 ) == 0 );
assert( unpacked_array#(bit,8)::compare( ua1, ua2,
        .from_index1( 2 ), .to_index1( 5 ),
        .from_index2( 2 ), .to_index2( 5 ) ) == 1 );

to_string

static function string to_string(const ref ua_type ua,  
input string separator =  " ",
int from_index =  0,
int to_index =  -1,
formatter#(T) fmtr =  null)

static Converts an unpacked array to the form of a string.

Arguments

uaAn unpacked array to be converted.
separatoroptional A string to separate each element of ua.  The default is a space (“ “).
from_indexoptional The index of the first element of ua to convert.  See Common Arguments.  The default is 0.
to_indexoptional The index of the last element of ua to convert.  See Common Arguments.  The default is -1.
fmtroptional A strategy object used to format ua.  If not specified or null, hex_formatter #(T) is used.  The default is null.

Returns

A string to represent ua.

Example

bit ua[8] = '{ 0, 0, 0, 1, 1, 0, 1, 1 }; // assigned to ua[0:7]
assert( unpacked_array#(bit,8)::to_string( ua )                    == "0 0 0 1 1 0 1 1" );
assert( unpacked_array#(bit,8)::to_string( ua, .separator( "-" ) ) == "0-0-0-1-1-0-1-1" );
assert( unpacked_array#(bit,8)::to_string( ua, .from_index( 4 )  ) ==         "1 0 1 1" );
virtual class unpacked_array #(type T =  bit,
int SIZE =  1)
A parameterized class that manages an unpacked array.
typedef T ua_type[SIZE]
The shorthand of the unpacked array type of type T.
typedef T da_type[]
The shorthand of the dynamic array type of type T.
typedef T q_type[$]
The shorthand of the queue type of type T.
static function ua_type from_dynamic_array(const ref da_type da,  
input bit reverse =  0)
static Converts a dynamic array of type T to un unpacked array of the same type.
static function da_type to_dynamic_array(const ref ua_type ua,  
input bit reverse =  0)
static Converts an unpacked array of type T to a dynamic array of the same type.
static function ua_type from_queue(const ref q_type q,  
input bit reverse =  0)
static Converts a queue of type T to an unpacked array of the same type.
static function q_type to_queue(const ref ua_type ua,  
input bit reverse =  0)
static Converts an unpacked array of type T to a queue of the same type.
static function void da_to_ua(const ref da_type da,  
ref ua_type ua,  
input bit reverse =  0)
static Converts a dynamic array of type T to an unpacked array of the same type.
static function void ua_to_da(const ref ua_type ua,  
ref da_type da,  
input bit reverse =  0)
static Converts an unpacked array of type T to a dynamic array of the same type.
static function void q_to_ua(const ref q_type q,  
ref ua_type ua,  
input bit reverse =  0)
static Converts a queue of type T to an unpacked array of the same type.
static function void ua_to_q(const ref ua_type ua,  
ref q_type q,  
input bit reverse =  0)
static Converts an unpacked array of type T to a queue of the same type.
static function void init(ref ua_type ua,
input val)
static Initializes the each element of the given unpacked array to the specified value.
static function void reverse(ref ua_type ua)
static Reverses the order of the elements of the given unpacked array.
static function bit compare(const ref ua_type ua1,  
const ref ua_type ua2,  
input int from_index1 =  0,
int to_index1 =  -1,
int from_index2 =  0,
int to_index2 =  -1,
comparator#(T) cmp =  null)
static Compares two unpacked arrays.
static function string to_string(const ref ua_type ua,  
input string separator =  " ",
int from_index =  0,
int to_index =  -1,
formatter#(T) fmtr =  null)
static Converts an unpacked array to the form of a string.
class comparator#(type T =  int)
singleton Provides strategies to compare objects.
class hex_formatter #(type T =  int) extends formatter#( T )
singleton Provides a strategy to convert an object of type T to a string using a hexadecimal format.