virtual class data_stream #( type T = bit, int WIDTH = 1, int DEGREE = 2 ) extends dynamic_array #( T[WIDTH-1:0] )
A parameterized class that manages a stream of packed arrays.
| T | optional The type of the packed array of a data stream. The T must be the single bit data types (bit, logic, or reg). The default type is bit. |
| WIDTH | optional The width of the packed array. The default is 1. |
| DEGREE | optional The degree of an LFSR polynomial. This parameter is used only if scramble function is used. The default is 2. |
| data_stream | A parameterized class that manages a stream of packed arrays. |
| Common Arguments | |
| Types | |
| pa_type | The shorthand of the packed array of type T. |
| ds_type | The data stream type. |
| bs_type | The bit stream type. |
| lfsr_type | The linear feedback shift register (LFSR) type. |
| Functions | |
| to_bit_stream | static Serializes a data stream of type T to a bit stream of the same type. |
| make_divisible | static Makes the data stream divisible by the specified number by padding data. |
| sequential | static Returns a new data stream with the elements whose values are initialized with sequential values. |
| constant | static Returns a new data stream with the elements whose values are initiazlized with the specified constant. |
| random | static Returns a new data stream with the elements whose values are randomized. |
| scramble | static Returns a scrambled data stream. |
| to_string | static Converts a data stream to the form of a string. |
| to_string_with_en | static Converts a data stream with corresponding data enables to the form of a string. |
| from_index | The index of the first element of a data stream 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_index | The index of the last element of a data stream 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). |
typedef pa_type ds_type[]
The data stream type. The shorthand of the dynamic array of pa_type.
typedef scrambler#( T, DEGREE )::lfsr_type lfsr_type
The linear feedback shift register (LFSR) type. The shorthand of the lfsr_type defined in the scrambler class.
static function bs_type to_bit_stream( ds_type ds, bit msb_first = 1, int from_index = 0, int to_index = -1 )
static Serializes a data stream of type T to a bit stream of the same type.
| ds | An input data stream. |
| msb_first | optional If 1, converts ds from the most significant bit to the least significant bit. If 0, converts ds from the least significant bit to the most signicant bit. The default is 1. |
| from_index | optional The index of the first element of ds to convert. See Common Arguments. The default is 0. |
| to_index | optional The index of the last element of ds to convert. See Common Arguments. The default is -1. |
A new bit stream serialized from ds.
bit[7:0] ds[] = new[2]( '{ 8'h0F, 8'hAA } );
bit bs0[] = new[16]( '{ 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0 } );
bit bs1[] = new[16]( '{ 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1 } );
assert( data_stream#(bit,8)::to_bit_stream( ds ) == bs0 );
assert( data_stream#(bit,8)::to_bit_stream( ds, .msb_first( 0 ) ) == bs1 );
static function ds_type make_divisible( ds_type ds, int divisible_by = 1, pa_type padding = 0 )
static Makes the data stream divisible by the specified number by padding data.
| ds | An input data stream. |
| divisible_by | optional The output data stream is divisible by this number. The default is 1. |
| padding | optional Padding data. The default is 0. |
A new data stream made divisible by divisible_by.
bit[7:0] ds[] = new[4]( '{ 8'h00, 8'h01, 8'h02, 8'h03 } );
bit[7:0] expected[] = new[6]( '{ 8'h00, 8'h01, 8'h02, 8'h03, 8'hFF, 8'hFF } );
assert( data_stream#(bit,8)::make_divisible( ds, .divisible_by( 3 ), .padding( 8'hFF ) ) == expected );
static function ds_type sequential( int unsigned length, pa_type init_value = 0, pa_type step = 1, bit randomize_init_value = 0 )
static Returns a new data stream with the elements whose values are initialized with sequential values.
| length | The length of the output data stream. |
| init_value | optional The value of the first element. The default is 0. |
| step | optional The value difference between two adjacent elements. The default is 1. |
| randomize_init_value | optional If 1, the value of the first element is randomized (the init_value argument is ignored). The default is 0. |
A new data stream with the elements whose values are initialized with sequential values.
bit[7:0] ds0[] = new[8]( '{ 8'hFE, 8'hFF, 8'h00, 8'h01, 8'h02, 8'h03, 8'h04, 8'h05 } );
bit[7:0] ds1[] = new[8]( '{ 8'hFE, 8'h00, 8'h02, 8'h04, 8'h06, 8'h08, 8'h0A, 8'h0C } );
bit[7:0] ds2[] = new[8]( '{ 8'hFE, 8'hFD, 8'hFC, 8'hFB, 8'hFA, 8'hF9, 8'hF8, 8'hF7 } );
assert( data_stream#(bit,8)::sequential( .length( 8 ), .init_value( 8'hFE ) ) == ds0 );
assert( data_stream#(bit,8)::sequential( .length( 8 ), .init_value( 8'hFE ), .step( 2 ) ) == ds1 );
assert( data_stream#(bit,8)::sequential( .length( 8 ), .init_value( 8'hFE ), .step( -1 ) ) == ds2 );
static function ds_type constant( int unsigned length, pa_type value = 0, bit randomize_value = 0 )
static Returns a new data stream with the elements whose values are initiazlized with the specified constant.
| length | The length of the output data stream. |
| value | optional The value of the elements. The default is 0. |
| randomize_value | optional If 1, the value of the elements is randomized (the value argument is ignored). The default is 0. |
A new data stream with the elements whose values are initialized with value.
bit[7:0] expected[] = new[8]( '{ 8'hAB, 8'hAB, 8'hAB, 8'hAB, 8'hAB, 8'hAB, 8'hAB, 8'hAB } );
assert( data_stream#(bit,8)::constant( .length( 8 ), .value( 8'hAB ) ) == expected );
static function ds_type random( int unsigned length )
static Returns a new data stream with the elements whose values are randomized.
| length | The length of the output data stream. |
A new data stream with the elements whose values are randomized.
bit[7:0] ds[]; ds = data_stream#(bit,8)::random( .length( 16 ) ); $display( data_stream#(bit,8)::to_string( ds, .group( 1 ) ) );
static function ds_type scramble( ds_type ds, scrambler#(T,DEGREE) scrblr, ref lfsr_type lfsr, input bit msb_first = 1 )
static Returns a scrambled data stream.
| ds | An input data stream. |
| scrblr | A scrambler to use. |
| lfsr | The value of a linear feedback shift register (LFSR), which can be used as the seed of the next call of this function. The initial value should be all ones. |
| msb_first | If 1, scrambles ds from the most significant bit. If 0, scrambles ds from the least significant bit to the most signicant bit. The default is 1. |
| little_endian | optional If 1, each data-stream item is scrambled from LSBs. If 0, each data stream item is scrambled from MSBs. The default is 0. |
A new data stream scrambled by scrblr.
bit[7:0] ds[] = new[8]( '{ 8'h00, 8'h01, 8'h02, 8'h03, 8'h04, 8'h05, 8'h06, 8'h07 } );
bit[7:0] scrambled[];
scrambler_16#(bit) scrblr = new;
bit[15:0] lfsr = '1;
scrambled = data_stream#(bit,8,16)::scramble( ds, scrblr, lfsr ); // DEGREE=16
$display( data_stream#(bit,8)::to_string( scrambled, .group( 1 ) ) );
static function string to_string( ds_type ds, bit left_to_right = 1, int unsigned group = 0, string group_separator = " ", int num_head = -1, int num_tail = -1, string abbrev = "... " )
static Converts a data stream to the form of a string.
| ds | An input data stream. |
| left_to_right | optional If 1, the item at index 0 of the data stream is placed on the left of the output string. If 0, the item at index 0 of the data stream is placed on the right of the output string. The default is 1. |
| group | optional The number of items put together in a group. If 0, no groups are created. The default is 0. |
| group_separator | optional A string to separate two groups if group is not 0. The default is a single space (“ “). |
| num_head | optional The number of first items in the data stream converted to a string. If specified, ds[0] to ds[num_head-1] are converted. If not specified (or -1), all items in the data stream are converted. |
| num_tail | optional The number of last items in the data stream converted to a string. If specified, ds[ds.size()-num_tail] to ds[ds.size()-1] are converted. If not specified (or -1), all items in the data stream are converted. |
| abbrev | optional A string to indicate the abbreviation of the items in the data stream. The abbrev is used only if all items are not converted to a string. The default is three periods followed by a space (“... “). |
A string representing ds.
bit[15:0] ds16[] = new[7]( '{ 16'h0123, 16'h4567, 16'h89ab, 16'hcdef, 16'h0000, 16'h0001, 16'h1000 } );
assert( data_stream#(bit,16)::to_string( ds16 )
== "0123456789abcdef000000011000" );
assert( data_stream#(bit,16)::to_string( ds16, .left_to_right( 0 ) )
== "100000010000cdef89ab45670123" );
assert( data_stream#(bit,16)::to_string( ds16, .group( 1 ) )
== "0123 4567 89ab cdef 0000 0001 1000" );
assert( data_stream#(bit,16)::to_string( ds16, .group( 2 ) )
== "01234567 89abcdef 00000001 1000" );
assert( data_stream#(bit,16)::to_string( ds16, .group( 1 ), .left_to_right( 0 ) )
== "1000 0001 0000 cdef 89ab 4567 0123" );
assert( data_stream#(bit,16)::to_string( ds16, .group( 2 ), .left_to_right( 0 ) )
== "10000001 0000cdef 89ab4567 0123" );
assert( data_stream#(bit,16)::to_string( ds16, .group( 1 ), .num_head( 2 ), .num_tail( 0 ) )
== "0123 4567 ... " );
assert( data_stream#(bit,16)::to_string( ds16, .group( 1 ), .num_head( 0 ), .num_tail( 2 ) )
== "... 0001 1000" );
assert( data_stream#(bit,16)::to_string( ds16, .group( 1 ), .num_head( 2 ), .num_tail( 2 ) )
== "0123 4567 ... 0001 1000" );
static function string to_string_with_en( ds_type ds, bit enables[], byte disabled_char = "-", bit left_to_right = 1, int unsigned group = 0, string group_separator = " ", int num_head = -1, int num_tail = -1, string abbrev = "..." )
static Converts a data stream with corresponding data enables to the form of a string.
| ds | An input data stream. |
| enables | The dynamic array of data enables corresponding to the data in ds. The size of enables should be the same as the size of ds. If the size of enables is larger than the size of ds, the excess data enables are ignored. If the size of enables is smaller than the size of ds, the data without enables are treated as disabled. |
| disabled_char | optional The character representing disabled data. The default character is a dash (“-”). |
| left_to_right | optional If 1, the item at index 0 of the dynamic array is placed on the left of the output string. If 0, the item at index 0 of the data stream is placed on the right of the output string. The default is 1. |
| group | optional The number of items put together in a group. If 0, no groups are created. The default is 0. |
| group_separator | optional A string to separate two groups if group is not 0. The default is a single space (“ “). |
| num_head | optional The number of first items in the data stream converted to a string. If specified, ds[0] to ds[num_head-1] are converted. If not specified (or -1), all items in the data stream are converted. |
| num_tail | optional The number of last items in the data stream converted to a string. If specified, ds[ds.size()-num_tail] to ds[ds.size()-1] are converted. If not specified (or -1), all items in the data stream are converted. |
| abbrev | optional A string to indicate the abbreviation of the items in the data stream. The abbrev is used only if all items are not converted to a string. The default is three periods followed by a space (“... “). |
A string representing ds qualified with enables.
bit[7:0] ds8[] = new[10]( '{ 8'h10, 8'h11, 8'h12, 8'h13, 8'h14, 8'h15, 8'h16, 8'h17, 8'h18, 8'h19 } );
bit en[] = new[10]( '{ 1'b1, 1'b0, 1'b1, 1'b0, 1'b1, 1'b0, 1'b1, 1'b0, 1'b1, 1'b0 } );
assert( data_stream#(bit,8)::to_string_with_en( ds8, en )
== "10--12--14--16--18--" );
assert( data_stream#(bit,8)::to_string_with_en( ds8, en, .group(1) )
== "10 -- 12 -- 14 -- 16 -- 18 --" );
assert( data_stream#(bit,8)::to_string_with_en( ds8, en, .group(2) )
== "10-- 12-- 14-- 16-- 18--" );
assert( data_stream#(bit,8)::to_string_with_en( ds8, en, .group(8) )
== "10--12--14--16-- 18--" );
assert( data_stream#(bit,8)::to_string_with_en( ds8, en, .group(1), .group_separator("|") )
== "10|--|12|--|14|--|16|--|18|--" );
assert( data_stream#(bit,8)::to_string_with_en( ds8, en, .group(1), .num_head(2), .num_tail(2) )
== "10 -- ...18 --" );
assert( data_stream#(bit,8)::to_string_with_en( ds8, en, .group(1), .disabled_char("*") )
== "10 ** 12 ** 14 ** 16 ** 18 **" );A parameterized class that manages a stream of packed arrays.
virtual class data_stream #( type T = bit, int WIDTH = 1, int DEGREE = 2 ) extends dynamic_array #( T[WIDTH-1:0] )
The shorthand of the packed array of type T.
typedef T [WIDTH-1:0] pa_type
The data stream type.
typedef pa_type ds_type[]
The bit stream type.
typedef T bs_type[]
The linear feedback shift register (LFSR) type.
typedef scrambler#( T, DEGREE )::lfsr_type lfsr_type
static Serializes a data stream of type T to a bit stream of the same type.
static function bs_type to_bit_stream( ds_type ds, bit msb_first = 1, int from_index = 0, int to_index = -1 )
static Makes the data stream divisible by the specified number by padding data.
static function ds_type make_divisible( ds_type ds, int divisible_by = 1, pa_type padding = 0 )
static Returns a new data stream with the elements whose values are initialized with sequential values.
static function ds_type sequential( int unsigned length, pa_type init_value = 0, pa_type step = 1, bit randomize_init_value = 0 )
static Returns a new data stream with the elements whose values are initiazlized with the specified constant.
static function ds_type constant( int unsigned length, pa_type value = 0, bit randomize_value = 0 )
static Returns a new data stream with the elements whose values are randomized.
static function ds_type random( int unsigned length )
static Returns a scrambled data stream.
static function ds_type scramble( ds_type ds, scrambler#(T,DEGREE) scrblr, ref lfsr_type lfsr, input bit msb_first = 1 )
static Converts a data stream to the form of a string.
static function string to_string( ds_type ds, bit left_to_right = 1, int unsigned group = 0, string group_separator = " ", int num_head = -1, int num_tail = -1, string abbrev = "... " )
static Converts a data stream with corresponding data enables to the form of a string.
static function string to_string_with_en( ds_type ds, bit enables[], byte disabled_char = "-", bit left_to_right = 1, int unsigned group = 0, string group_separator = " ", int num_head = -1, int num_tail = -1, string abbrev = "..." )
Provides a function to scramble an input bit stream using Galois LFSR, which is also known as the internal LFSR.
class scrambler #( type T = bit, int DEGREE = 2 )