virtual class packed_array #( type T = bit, int WIDTH = 1 )
A parameterized class that manages a packed array.
| T | optional The type of a packed array. The type T must be the single bit data types (bit, logic, or reg), enumerated types, or other packed arrays or packed structures. The default type is bit. |
| WIDTH | optional The width of a packed array. The default is 1. |
| packed_array | A parameterized class that manages a packed array. |
| Types | |
| pa_type | The shorthand of the packed array type of type T. |
| ua_type | The shorthand of the unpacked array type of type T. |
| da_type | The shorthand of the dynamic array type of type T. |
| q_type | The shorthand of the queue type of type T. |
| Functions | |
| from_unpacked_array | static Converts an unpacked array of type T to a packed array of the same type. |
| to_unpacked_array | static Converts a packed array of type T to an unpacked array of the same type. |
| from_dynamic_array | static Converts a dynamic array of type T to a packed array of the same type. |
| to_dynamic_array | static Converts a packed array of type T to a dynamic array of the same type. |
| from_queue | static Converts a queue of type T to a packed array of the same type. |
| to_queue | static Converts a packed array of type T to a queue of the same type. |
| ua_to_pa | static Converts an unpacked array of type T to a packed array of the same type. |
| pa_to_ua | static Converts a packed array of type T to an unpacked array of the same type. |
| da_to_pa | static Converts a dynamic array of type T to a packed array of the same type. |
| pa_to_da | static Converts a packed array of type T to a dynamic array of the same type. |
| q_to_pa | static Converts a queue of type T to a packed array of the same type. |
| pa_to_q | static Converts a packed array of type T to a queue of the same type. |
| init | static Initializes the each element of the given packed array to the specified value. |
| reverse | static Reverses the order of the elements of the given packed array. |
| count_ones | static Counts the number of bits having value 1. |
| count_zeros | static Counts the number of bits having value 0. |
| count_unknowns | static Counts the number of bits having value X. |
| count_hizs | static Counts the number of bits having value Z. |
static function pa_type from_unpacked_array( const ref ua_type ua, input bit reverse = 0 )
static Converts an unpacked array of type T to a packed array of the same type.
| ua | An unpacked array to be converted. |
| reverse | optional If 0, the element at the index 0 of ua is positioned to the index 0 of the packed array. If 1, the elements are positioned in the reverse order. The default is 0. |
A packed array converted from ua.
bit ua[8] = '{ 0, 0, 0, 1, 1, 0, 1, 1 }; // assigned to ua[0:7]
assert( packed_array#(bit,8)::from_unpacked_array( ua ) == 8'hD8 ); // bit[7:0]
assert( packed_array#(bit,8)::from_unpacked_array( ua, .reverse( 1 ) ) == 8'h1B );
static function ua_type to_unpacked_array( const ref pa_type pa, input bit reverse = 0 )
static Converts a packed array of type T to an unpacked array of the same type.
| pa | A packed array to be converted. |
| reverse | optional If 0, the element at the index 0 of pa is positioned to the index 0 of the unpacked array. If 1, the elements are positioned in the reverse order. The default is 0. |
An unpacked array converted from pa.
bit[7:0] pa = 8'hD8;
bit ua0[8] = '{ 0, 0, 0, 1, 1, 0, 1, 1 };
bit ua1[8] = '{ 1, 1, 0, 1, 1, 0, 0, 0 };
assert( packed_array#(bit,8)::to_unpacked_array( pa ) == ua0 );
assert( packed_array#(bit,8)::to_unpacked_array( pa, .reverse( 1 ) ) == ua1 );
static function pa_type from_dynamic_array( const ref da_type da, input bit reverse = 0 )
static Converts a dynamic array of type T to a packed array of the same type. If the size of the dynamic array is larger than WIDTH, the excess elements are ignored. If the size of the dynamic array is smaller than WIDTH, the default value of type T is used for the missing elements.
| da | A dynamic array to be converted. |
| reverse | optional If 0, the element at the index 0 of da is positioned to the index 0 of the packed array. If 1, the elements are positioned in the reverse order. The default is 0. |
A packed array converted from da.
bit da[] = new[8]( '{ 0, 0, 0, 1, 1, 0, 1, 1 } ); // da[0] to da[7]
assert( packed_array#(bit,8)::from_dynamic_array( da ) == 8'hD8 ); // bit[7:0]
assert( packed_array#(bit,8)::from_dynamic_array( da, .reverse( 1 ) ) == 8'h1B );
static function da_type to_dynamic_array( const ref pa_type pa, input bit reverse = 0 )
static Converts a packed array of type T to a dynamic array of the same type.
| pa | A packed array to be converted. |
| reverse | optional If 0, the element at the index 0 of pa is positioned to the index 0 of the dynamic array. If 1, the elements are positioned in the reverse order. The default is 0. |
A dynamic array converted from pa.
bit[7:0] pa = 8'hD8;
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( packed_array#(bit,8)::to_dynamic_array( pa ) == da0 );
assert( packed_array#(bit,8)::to_dynamic_array( pa, .reverse( 1 ) ) == da1 );
static function pa_type from_queue( const ref q_type q, input bit reverse = 0 )
static Converts a queue of type T to a packed array of the same type. If the size of the queue is larger than WIDTH, the excess elements are ignored. If the size of the queue is smaller than WIDTH, the default valus of type T is used for the missing elements.
| q | A queue to be converted. |
| reverse | optional If 0, the element at the index 0 of q is positioned to the index 0 of the packed array. If 1, the elements are positioned in the reverse order. The default is 0. |
A packed array converted from q.
bit q[$] = { 0, 0, 0, 1, 1, 0, 1, 1 }; // q[0] to q[7]
assert( packed_array#(bit,8)::from_queue( q ) == 8'hD8 ); // bit[7:0]
assert( packed_array#(bit,8)::from_queue( q, .reverse( 1 ) ) == 8'h1B );
static function q_type to_queue( const ref pa_type pa, input bit reverse = 0 )
static Converts a packed array of type T to a queue of the same type.
| pa | A packed array to be converted. |
| reverse | optional If 0, the element at the index 0 of pa is positioned to the index 0 of the queue. If 1, the elements are positioned in the reverse order. The default is 0. |
A queue converted from pa.
bit[7:0] pa = 8'hD8;
bit q0[$] = { 0, 0, 0, 1, 1, 0, 1, 1 };
bit q1[$] = { 1, 1, 0, 1, 1, 0, 0, 0 };
assert( packed_array#(bit,8)::to_queue( pa ) == q0 );
assert( packed_array#(bit,8)::to_queue( pa, .reverse( 1 ) ) == q1 );
static function void ua_to_pa( const ref ua_type ua, ref pa_type pa, input bit reverse = 0 )
static Converts an unpacked array of type T to a packed array of the same type. Unlike from_unpacked_array, this function populates the packed array passed by reference, instead of returning a new packed array.
| ua | An unpacked array to be converted. |
| pa | A packed array reference to be populated. |
| reverse | optional If 0, the element at the index 0 of ua is positioned to the index 0 of pa. If 1, the elements are positioned in the reverse order. The default is 0. |
None.
bit ua[8] = '{ 0, 0, 0, 1, 1, 0, 1, 1 }; // assigned to ua[0:7]
bit[7:0] pa;
packed_array#(bit,8)::ua_to_pa( ua, pa );
assert( pa == 8'hD8 ); // bit[7:0]
packed_array#(bit,8)::ua_to_pa( ua, pa, .reverse( 1 ) );
assert( pa == 8'h1B );
static function void pa_to_ua( const ref pa_type pa, ref ua_type ua, input bit reverse = 0 )
static Converts a packed array of type T to an unpacked array of the same type. Unlike to_unpacked_array, this function populates the unpacked array passed by reference, instead of returning a new unpacked array.
| pa | A packed array to be converted. |
| ua | An unpacked array reference to be populated. |
| reverse | optional If 0, the element at the index 0 of pa is positioned to the index 0 of ua. If 1, the elements are positioned in the reverse order. The default is 0. |
None.
bit[7:0] pa = 8'hD8;
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 };
packed_array#(bit,8)::pa_to_ua( pa, ua );
assert( ua == ua0 );
packed_array#(bit,8)::pa_to_ua( pa, ua, .reverse( 1 ) );
assert( ua == ua1 );
static function void da_to_pa( const ref da_type da, ref pa_type pa, input bit reverse = 0 )
static Converts a dynamic array of type T to a packed array of the same type. Unlike from_dynamic_array, this function populates the packed array passed by reference, instead of returning a new packed array. If the size of the dynamic array is larger than WIDTH, the excess elements are ignored. If the size of the dynamic array is smaller than WIDTH, the default value of type T is used for the missing elements.
| da | A dynamic array to be converted. |
| pa | A packed array to be populated. |
| reverse | optional If 0, the element at the index 0 of da is positioned to the index 0 of pa. If 1, the elements are positioned in the reverse order. The default is 0. |
None.
bit da[] = new[8]( '{ 0, 0, 0, 1, 1, 0, 1, 1 } ); // da[0] to da[7]
bit[7:0] pa;
packed_array#(bit,8)::da_to_pa( da, pa );
assert( pa == 8'hD8 ); // bit[7:0]
packed_array#(bit,8)::da_to_pa( da, pa, .reverse( 1 ) );
assert( pa == 8'h1B );
static function void pa_to_da( const ref pa_type pa, ref da_type da, input bit reverse = 0 )
static Converts a packed 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.
| pa | A packed array to be converted. |
| da | A 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 pa before calling this function. |
| reverse | optional If 0, the element at the index 0 of pa is positioned to the index 0 of da. If 1, the elements are positioned in the reverse order. The default is 0. |
None.
bit[7:0] pa = 8'hD8;
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 } );
packed_array#(bit,8)::pa_to_da( pa, da );
assert( da == da0 );
packed_array#(bit,8)::pa_to_da( pa, da, .reverse( 1 ) );
assert( da == da1 );
static function void q_to_pa( const ref q_type q, ref pa_type pa, input bit reverse = 0 )
static Converts a queue of type T to a packed array of the same type. Unlike from_queue, this function populates the packed array passed by reference, instead of returning a new packed array. If the size of the queue is larger than WIDTH, the excess elements are ignored. If the size of the queue is smaller than WIDTH, the default valus of type T is used for the missing elements.
| q | A queue to be converted. |
| pa | A packed array to be populated. |
| reverse | optional If 0, the element at the index 0 of q is positioned to the index 0 of pa. If 1, the elements are positioned in the reverse order. The default is 0. |
None.
bit q[$] = { 0, 0, 0, 1, 1, 0, 1, 1 }; // q[0] to q[7]
bit[7:0] pa;
packed_array#(bit,8)::q_to_pa( q, pa );
assert( pa == 8'hD8 ); // bit[7:0]
packed_array#(bit,8)::q_to_pa( q, pa, .reverse( 1 ) );
assert( pa == 8'h1B );
static function void pa_to_q( const ref pa_type pa, ref q_type q, input bit reverse = 0 )
static Converts a packed 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.
| pa | A packed array to be converted. |
| q | A queue to be populated. |
| reverse | optional If 0, the element at the index 0 of pa is positioned to the index 0 of q. If 1, the elements are positioned in the reverse order. The default is 0. |
None.
bit[7:0] pa = 8'hD8;
bit q [$];
bit q0[$] = { 0, 0, 0, 1, 1, 0, 1, 1 };
bit q1[$] = { 1, 1, 0, 1, 1, 0, 0, 0 };
packed_array#(bit,8)::pa_to_q( pa, q );
assert( q == q0 );
q.delete();
packed_array#(bit,8)::pa_to_q( pa, q, .reverse( 1 ) );
assert( q == q1 );
static function void init( ref pa_type pa, input T val )
static Initializes the each element of the given packed array to the specified value.
| pa | A packed array to be initialized. |
| val | A value to initialize the elements of pa. |
None.
bit[7:0] pa; packed_array#(bit,8)::init( pa, 1'b1 ); assert( pa == 8'hFF );
static function int count_ones( pa_type pa )
static Counts the number of bits having value 1.
| pa | A packed array. |
The number of bits having value 1. If the type T is not a single-bit data type, -1 is returned.
bit[15:0] pa = 16'h1234; // 16'b0001_0010_0011_0100 assert( packed_array#(bit,16)::count_ones( pa ) == 5 );
static function int count_zeros( pa_type pa )
static Counts the number of bits having value 0.
| pa | A packed array. |
The number of bits having value 0. If the type T is not a single-bit data type, -1 is returned.
bit[15:0] pa = 16'h1234; // 16'b0001_0010_0011_0100 assert( packed_array#(bit,16)::count_zeros( pa ) == 11 );
static function int count_unknowns( pa_type pa )
static Counts the number of bits having value X.
| pa | A packed array. |
The number of bits having value X. If the type T is not a single-bit data type, -1 is returned.
logic[15:0] pa = 16'b0000_1111_xxxx_zzzz; assert( packed_array#(logic,16)::count_unknowns( pa ) == 4 );
static function int count_hizs( pa_type pa )
static Counts the number of bits having value Z.
| pa | A packed array. |
The number of bits having value Z. If the type T is not a single-bit data type, -1 is returned.
logic[15:0] pa = 16'b0000_1111_xxxx_zzzz; assert( packed_array#(logic,16)::count_hizs( pa ) == 4 );
A parameterized class that manages a packed array.
virtual class packed_array #( type T = bit, int WIDTH = 1 )
The shorthand of the packed array type of type T.
typedef T [WIDTH-1:0] pa_type
The shorthand of the unpacked array type of type T.
typedef T ua_type[WIDTH]
The shorthand of the dynamic array type of type T.
typedef T da_type[]
The shorthand of the queue type of type T.
typedef T q_type[$]
static Converts an unpacked array of type T to a packed array of the same type.
static function pa_type from_unpacked_array( const ref ua_type ua, input bit reverse = 0 )
static Converts a packed array of type T to an unpacked array of the same type.
static function ua_type to_unpacked_array( const ref pa_type pa, input bit reverse = 0 )
static Converts a dynamic array of type T to a packed array of the same type.
static function pa_type from_dynamic_array( const ref da_type da, input bit reverse = 0 )
static Converts a packed array of type T to a dynamic array of the same type.
static function da_type to_dynamic_array( const ref pa_type pa, input bit reverse = 0 )
static Converts a queue of type T to a packed array of the same type.
static function pa_type from_queue( const ref q_type q, input bit reverse = 0 )
static Converts a packed array of type T to a queue of the same type.
static function q_type to_queue( const ref pa_type pa, input bit reverse = 0 )
static Converts an unpacked array of type T to a packed array of the same type.
static function void ua_to_pa( const ref ua_type ua, ref pa_type pa, input bit reverse = 0 )
static Converts a packed array of type T to an unpacked array of the same type.
static function void pa_to_ua( const ref pa_type pa, ref ua_type ua, input bit reverse = 0 )
static Converts a dynamic array of type T to a packed array of the same type.
static function void da_to_pa( const ref da_type da, ref pa_type pa, input bit reverse = 0 )
static Converts a packed array of type T to a dynamic array of the same type.
static function void pa_to_da( const ref pa_type pa, ref da_type da, input bit reverse = 0 )
static Converts a queue of type T to a packed array of the same type.
static function void q_to_pa( const ref q_type q, ref pa_type pa, input bit reverse = 0 )
static Converts a packed array of type T to a queue of the same type.
static function void pa_to_q( const ref pa_type pa, ref q_type q, input bit reverse = 0 )
static Initializes the each element of the given packed array to the specified value.
static function void init( ref pa_type pa, input T val )
static Reverses the order of the elements of the given packed array.
static function void reverse( ref pa_type pa )
static Counts the number of bits having value 1.
static function int count_ones( pa_type pa )
static Counts the number of bits having value 0.
static function int count_zeros( pa_type pa )
static Counts the number of bits having value X.
static function int count_unknowns( pa_type pa )
static Counts the number of bits having value Z.
static function int count_hizs( pa_type pa )