SystemVerilog PDF
SystemVerilog PDF
Extensions to Verilog
other data types: bounded queues, logic (0, 1, X, Z) and bit (0, 1),
tagged unions
extended operators
operator overloading
streaming operators
set membership
loop statements
pass by reference
default arguments
optional arguments
semaphores
mailboxes
synchronous samples
string literals enclosed in quotes: \v for vertical tab, \f for form feed,
\a for bell, \x02 for hex number
Data Types
A data type is a set of values and a set of operations that can be performed
on those values. Data types can be used to declare data objects or to define
user-defined data types that are constructed from other data types.
integer types
2-state - can simulate faster and take less memory: shortint (16-bit
signed), int (32-bit signed), longint (64-bit signed), byte (8-bit
signed or ASCII character), bit (unsigned with user-defined vector
size)
integral types - the data types that can represent a single basic integer
data type: packed array, packed struct, packed union, enum, time.
A simple bit vector type is the data types that can directly represent a
one-dimensional packed array of bits.
chandle data type - for storing pointers passed using DPI (default null)
string operators: ==, !=, <, <=, >, >=, {str1, str2, , strN),
{multiplier{str}}, str[index], string.method()
waited for
a tagged union saves a value and a tag (or a member name) for
strong type access checking
class is declared using the class endclass keywords
class properties
methods
casting: a data type can be changed by using a cast () operation
static casting
<size> ( <expression> )
signed (<expression> )
bit-stream casting
example
uses bit-stream casting to model a control packet transfer over a
data stream:
typedef struct {
shortint address;
reg [3:0] code;
byte command [2];
} Control;
typedef bit Bits [36:1];
Control p;
Bits stream[$];
p = ...
// initialize control packet
// append packet to unpacked queue of bits
stream = {stream, Bits'(p)}
Control q;
// convert stream back to a Control packet
q = Control'(stream[0]);
stream = stream[1:$]; // remove packet from stream
uses bit-stream casting to model a data packet transfer over a byte
stream:
typedef struct {
byte length;
shortint address;
byte payload[];
byte chksum;
} Packet;
function Packet genPkt();
Packet p;
void'( randomize( p.address, p.length, p.payload )
with { p.length > 1 && p.payload.size == p.length; }
);
p.chksum = p.payload.xor();
return p;
endfunction
The byte stream is modeled using a queue, and a bit-stream cast is
used to send the packet over the stream.
typedef byte channel_type[$];
channel_type channel;
channel = {channel, channel_type'(genPkt())};
And the code to receive the packet:
Packet p;
int size;
size = channel[0] + 4;
// convert stream to Packet
p = Packet'( channel[0 : size - 1] );
// remove packet data from stream
channel = channel[ size, $ ];
Arrays
multi-dimensional arrays
size( )
delete( )
array assignment between fixed-size arrays and dynamic arrays
arrays as arguments: pass by value
associative arrays
queues are declared using the same syntax as unpacked arrays, but
specifying $ as the array size
empty queue { }
right bound [$:N], where N+1 is the maximum size of the queue
Data Declarations
data have to be declared before they are used, except implicit nets
constants
$isunbounded(const_expr)
equivalent type
Classes
constructor new( )
static class properties shared by all instances of the class using static
static class method with automatic variable lifetime: static task foo( );
end task
nonstatic class method with static variable lifetime: task static foo( );
end task
shallow copy (putting an object after new) v.s. deep copy (custom code
is typically needed)
this and super
it is always legal to assign a subclass variable to a variable of a class
higher in the inheritance tree, but it is never legal to directly assign a
superclass variable to a variable of one of its subclasses; it is legal to
assign a superclass handle to a subclass variable if the superclass handle
refers to an object of the given subclass, and use $cast( ) to check
whether the assignment is legal
unqualified (public), local (private), and protected
const: read-only
inc_or_dec_operator ::= ++ | -
unary_module_path_operator ::= ! | ~ | & | ~& | | | ~| | ^ | ~^ | ^~
assignment patterns for assigning struct fields and array elements using
( { } ) either by positions, by type:value, or by member:value or by
default:value
match formal types exactly or the actual types are implicitly cast to
formal types
observed
post-observed
reactive
re-inactive
Scheduling Semantics
pre-postponed
pre-active
active
inactive
pre-NBA
NBA
post-NBA
semantics
The
#1step
sampling
delay
provides the ability to sample data
immediately before entering the
current time slot
allows PLI application routines
(cbAfterDelay,
cbNextSimTime,
cbAtStartOfSimTime) to read and
write values and create events
before events in the Active region
are evaluated
holds
current
events
being
evaluated
holds the events to be evaluated
after all the active events are
processed
allows PLI application routines
(cbNBASynch, cbReadWriteSynch)
to read and write values and
create events before the events in
the NBA region are evaluated
A nonblocking assignment creates
an event in this region
allows PLI application routines
(cbReadWriteSynch) to read and
postponed
note
IEEE1364
IEEE1364
IEEE1364
iterative
IEEE1364
iterative
IEEE1364
iterative
IEEE1364
iterative
IEEE1364
iterative
iterative
iterative
iterative
iterative
IEEE1364
iterative
IEEE1364
}
execute_region {
while (region is nonempty) {
E = any event from region;
remove E from the region;
if (E is an update event) {
update the modified object;
evaluate processes sensitive to the object and
possibly schedulefurther events for execution;
} else { /* E is an evaluation event */
evaluate the process associated with the event and
possibly schedule further events for execution;
}
}
}
the PLI callback control points
control flow
timing control
selection statements: if, else if, else, case, casez, casex, default,
endcase, unique (for mutual exclusive and can be executed in
parallel), priority (ordered evaluation), inside (for set membership),
matches (using &&& in if statements), ?:
named blocks and statement labels: begin end, fork join, join_any,
join_none
sequence, triggered
level-sensitive sequence control: wait
sequence abc;
@(posedge clk) a ##1 b ##1 c;
endsequence
sequence de;
@(negedge clk) d ##[2:5] e;
endsequence
program check;
initial begin
wait( abc.triggered || de.triggered );
if( abc.triggered )
$display( "abc succeeded" );
if( de.triggered )
$display( "de succeeded" );
end
endprogram
Processes
syntax:
assert
(
expression
)
[pass_statement]
[else
fail_statement]
there are 4 severity levels: $fatal, $error, $warning, and $info; all
the severity system tasks shall print a tool-specific message
indicating the severity of the failure and specific information about
the specific failure, which shall include the following information: