data_stream

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.

Parameters

Toptional 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.
WIDTHoptional The width of the packed array.  The default is 1.
DEGREEoptional The degree of an LFSR polynomial.  This parameter is used only if scramble function is used.  The default is 2.
Summary
data_streamA parameterized class that manages a stream of packed arrays.
Common Arguments
Types
pa_typeThe shorthand of the packed array of type T.
ds_typeThe data stream type.
bs_typeThe bit stream type.
lfsr_typeThe linear feedback shift register (LFSR) type.
Functions
to_bit_streamstatic Serializes a data stream of type T to a bit stream of the same type.
make_divisiblestatic Makes the data stream divisible by the specified number by padding data.
sequentialstatic Returns a new data stream with the elements whose values are initialized with sequential values.
constantstatic Returns a new data stream with the elements whose values are initiazlized with the specified constant.
randomstatic Returns a new data stream with the elements whose values are randomized.
scramblestatic Returns a scrambled data stream.
to_stringstatic Converts a data stream to the form of a string.
to_string_with_enstatic Converts a data stream with corresponding data enables to the form of a string.

Common Arguments

from_indexThe 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_indexThe 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).

Types

pa_type

typedef T [WIDTH-1:0] pa_type

The shorthand of the packed array of type T.

ds_type

typedef pa_type ds_type[]

The data stream type.  The shorthand of the dynamic array of pa_type.

bs_type

typedef T bs_type[]

The bit stream type.  The shorthand of the dynamic array of type T.

lfsr_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.

Functions

to_bit_stream

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.

Arguments

dsAn input data stream.
msb_firstoptional 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_indexoptional The index of the first element of ds to convert.  See Common Arguments.  The default is 0.
to_indexoptional The index of the last element of ds to convert.  See Common Arguments.  The default is -1.

Returns

A new bit stream serialized from ds.

Example

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 );

make_divisible

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.

Arguments

dsAn input data stream.
divisible_byoptional The output data stream is divisible by this number.  The default is 1.
paddingoptional Padding data.  The default is 0.

Returns

A new data stream made divisible by divisible_by.

Example

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 );

sequential

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.

Arguments

lengthThe length of the output data stream.
init_valueoptional The value of the first element.  The default is 0.
stepoptional The value difference between two adjacent elements.  The default is 1.
randomize_init_valueoptional If 1, the value of the first element is randomized (the init_value argument is ignored).  The default is 0.

Returns

A new data stream with the elements whose values are initialized with sequential values.

Example

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 );

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 initiazlized with the specified constant.

Arguments

lengthThe length of the output data stream.
valueoptional The value of the elements.  The default is 0.
randomize_valueoptional If 1, the value of the elements is randomized (the value argument is ignored).  The default is 0.

Returns

A new data stream with the elements whose values are initialized with value.

Example

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 );

random

static function ds_type random(int unsigned length)

static Returns a new data stream with the elements whose values are randomized.

Arguments

lengthThe length of the output data stream.

Returns

A new data stream with the elements whose values are randomized.

Example

bit[7:0] ds[];
ds = data_stream#(bit,8)::random( .length( 16 ) );
$display( data_stream#(bit,8)::to_string( ds, .group( 1 ) ) );

scramble

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.

Arguments

dsAn input data stream.
scrblrA scrambler to use.
lfsrThe 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_firstIf 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_endianoptional If 1, each data-stream item is scrambled from LSBs.  If 0, each data stream item is scrambled from MSBs.  The default is 0.

Returns

A new data stream scrambled by scrblr.

Example

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 ) ) );

to_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 to the form of a string.

Arguments

dsAn input data stream.
left_to_rightoptional 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.
groupoptional The number of items put together in a group.  If 0, no groups are created.  The default is 0.
group_separatoroptional A string to separate two groups if group is not 0.  The default is a single space (“ “).
num_headoptional 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_tailoptional 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.
abbrevoptional 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 (“...  “).

Returns

A string representing ds.

Example

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" );

to_string_with_en

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.

Arguments

dsAn input data stream.
enablesThe 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_charoptional The character representing disabled data.  The default character is a dash (“-”).
left_to_rightoptional 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.
groupoptional The number of items put together in a group.  If 0, no groups are created.  The default is 0.
group_separatoroptional A string to separate two groups if group is not 0.  The default is a single space (“ “).
num_headoptional 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_tailoptional 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.
abbrevoptional 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 (“...  “).

Returns

A string representing ds qualified with enables.

Example

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 **" );
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.
typedef T [WIDTH-1:0] pa_type
The shorthand of the packed array of type T.
typedef pa_type ds_type[]
The data stream type.
typedef T bs_type[]
The bit stream type.
typedef scrambler#(T,
DEGREE)::lfsr_type lfsr_type
The linear feedback shift register (LFSR) type.
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.
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.
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.
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.
static function ds_type random(int unsigned length)
static Returns a new data stream with the elements whose values are randomized.
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.
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.
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.
class scrambler #(type T =  bit,
int DEGREE =  2)
Provides a function to scramble an input bit stream using Galois LFSR, which is also known as the internal LFSR.