bit_stream

virtual class bit_stream #(type T =  bit) extends data_stream #( T, 1 )

A parameterized class that manages a bit stream.

Parameter

Toptional The type of the bit stream.  The T must be the single bit data types (bit, logic, or reg).  The default type is bit.
Summary
bit_streamA parameterized class that manages a bit stream.
Types
bs_typeThe bit stream type.
Functions
alternatestatic Returns a new bit stream with the elements whose values alternate between 0 and 1.
count_zerosstatic Counts the number of bit-stream items having value 0.
count_onesstatic Counts the number of bit-stream items having value 1.
count_unknownsstatic Counts the number of bit-stream items having value X.
count_hizsstatic Counts the number of bit-stream items having value Z.

Types

bs_type

typedef T bs_type[]

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

Functions

alternate

static function bs_type alternate(int unsigned length,  
init_value =  0,
bit randomize_init_value =  0)

static Returns a new bit stream with the elements whose values alternate between 0 and 1.

Argument

lengthThe length of the output bit stream.
init_valueoptional The value of the first element (0 or 1).  The default is 0.
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 bit stream with the elements whose values alternate between 0 and 1.

Example

bit expected[] = new[8]( '{ 1, 0, 1, 0, 1, 0, 1, 0 } );
assert( bit_stream#(bit)::alternate( 8, .init_value( 1 ) ) == expected );

count_zeros

static function int count_zeros(bs_type bs)

static Counts the number of bit-stream items having value 0.

Argument

bsA bit stream.

Returns

The number of items having value 0.  If the type T is not a single-bit data type, -1 is returned.

Example

bit bs[] = new[16]( '{ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1 } );
assert( bit_stream#(bit)::count_zeros( bs ) == 8 );

count_ones

static function int count_ones(bs_type bs)

static Counts the number of bit-stream items having value 1.

Argument

bsA bit stream.

Returns

The number of items having value 1.  If the type T is not a single-bit data type, -1 is returned.

Example

bit bs[] = new[16]( '{ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1 } );
assert( bit_stream#(bit)::count_ones( bs ) == 8 );

count_unknowns

static function int count_unknowns(bs_type bs)

static Counts the number of bit-stream items having value X.

Argument

bsA bit stream.

Returns

The number of items having value X.  If the type T is not a single-bit data type, -1 is returned.

Example

logic bs[] = new[16]( '{ 0, 0, 0, 0, 1, 1, 1, 1, 'x, 'x, 'x, 'x, 'z, 'z, 'z, 'z } );
assert( bit_stream#(logic)::count_unknowns( bs ) == 4 );

count_hizs

static function int count_hizs(bs_type bs)

static Counts the number of bit-stream items having value Z.

Argument

bsA bit stream.

Returns

The number of items having value Z.  If the type T is not a single-bit data type, -1 is returned.

Example

logic bs[] = new[16]( '{ 0, 0, 0, 0, 1, 1, 1, 1, 'x, 'x, 'x, 'x, 'z, 'z, 'z, 'z } );
assert( bit_stream#(logic)::count_hizs( bs ) == 4 );
virtual class bit_stream #(type T =  bit) extends data_stream #( T, 1 )
A parameterized class that manages a bit stream.
typedef T bs_type[]
The bit stream type.
static function bs_type alternate(int unsigned length,  
init_value =  0,
bit randomize_init_value =  0)
static Returns a new bit stream with the elements whose values alternate between 0 and 1.
static function int count_zeros(bs_type bs)
static Counts the number of bit-stream items having value 0.
static function int count_ones(bs_type bs)
static Counts the number of bit-stream items having value 1.
static function int count_unknowns(bs_type bs)
static Counts the number of bit-stream items having value X.
static function int count_hizs(bs_type bs)
static Counts the number of bit-stream items having value Z.