Data Types
Integer data types
Type | Description |
---|---|
bit | 2-state data type, user-defined vector size representing unsigned data |
byte | 8 bit 2-state integer representing signed data or ASCII character |
shortint | 16 bit 2-state integer representing signed data |
int | 32 bit 2-state integer representing signed data |
longint | 64 bit 2-state integer representing signed data |
logic | 4-state data type, user-defined vector size, unsigned data |
reg | 4-state data type, user-defined vector size, unsigned data |
wire | Used to connect different elements in a design. They can be read or assigned, but no values can be stored in them. |
integer | 32 bit 4-state integer representing signed data |
time | 64 bit 4-state integer representing signed data |
Real data types
Type | Description |
shortreal | 32 bit, single-precision, floating-point number |
real | 64 bit, single-precision, floating-point number |
realtime | 64 bit, single-precision, floating-point number |
Enum data types
Declares a user-defined enumerated type having a set of explicitly named values. Syntax:
enum data_type {item[0], item[1], ...} enum_type_name;
Defaults | Description |
data_type | If not specified data type defaults to int.
Example:
|
item[0] value | If not specified the first item in an enumerated list will be represented as 0 |
item[n] value | If not specified the n-th item in an enumerated list will be represented as item[n-1] + 1 |
Method | Description |
first() | Returns the first value of an enumeration |
last() | Returns the last value of an enumeration |
next(N) | Return the N-th next value, wrapping to the beginning if needed. Default N = 1. |
prev(N) | Return the N-th previous value, wrapping to the end if needed. Default N = 1. |
num() | Returns the number of values in the enum |
Struct data types
Type | Description |
Unpacked (default) | Syntax:
Access to a certain field: <struct_name>.<field_name> |
Packed | Syntax:
Members of a packed structure can be accessed either by their name, or by indexing a vector. By default the first field will be the leftmost item in the vector: Example:
In this case my_struct[0] is my_struct.data[0] |
Dynamic array
A dynamic array is an unpacked array whose size can be set or changed at runtime. Syntax:
type array_name[];
array_name = new[expression1](expression2);
expression2 is an optional initialization of the array
Method | Description |
new[expression] | Constructor that sets the size of the dynamic array and initializes its elements
Example:
|
size() | Returns the current size or 0 if the array is not created or if it was deleted. Example:
|
delete() | Empties the array, resulting in a zero-sized array
Example:
|
Queue data type
Syntax:
<type> my_queue[$:max_size]; //where max_size is optional
Example:
int q_int[$];
my_class my_q[$:5]; // accepts maximum 6 elements
Method | Description |
size() | Returns current size of the queue |
insert(i,d) | Inserts item d at index i |
delete(i) | Deletes item at index i, if index is omitted, deletes queue |
pop_front() | Reads and removes the item from the front of the queue |
pop_back() | Reads and removes the item from the back of the queue |
push_front(d) | Adds item d to front of the queue |
push_back(d) | Adds item d to back of the queue |
Casting
Static Cast
In a static cast, if the expression is assignment compatible with the casting type, then the cast shall return the value of a variable of the casting type. Syntax:
casting_type‘(expression)
Example 1:
shortint a;
int b;
b = int’(a);
Example 2:
logic[7:0] register;
register = signed’(4’b1100) // register = -4
Example 3:
shortint a;
int b;
b = a; // implicit cast
Dynamic Cast
Used to assign values to variables that might not ordinarily be valid because of differing data types. Syntax:
function int $cast(destination, source)
task $cast(destination, source)
If the assignment is invalid, a task will generate a runtime error, while the function will return 0.
typedef enum(idle,busy,pause,done) state;
state current_state;
if(!$cast(current_state,6)
$display(“Error in cast”);
Classes
Class Declaration Syntax:
class my_class;
constructor
local/static/protected items
Methods/method prototypes
endclass
Class Instance Syntax:
my_class obj; // declare an object of class my_class
Obj = new(); // initialize variable to a new allocated object of class my_class
Relevant keywords
Keyword | Description |
static | A static class field shares its value with all instances of the class A static method can only access static properties, but it can be called even when no class instances exist by using class name and the scope resolution operator. Example:
|
this | The this keyword gives unambiguous access to members of the current class instance
Example:
|
super | The super keyword gives unambiguous access to members of the parent class of the calling object.
Example:
|
virtual | A virtual class is an abstract class which can only be inherited, but not instantiated. |
const | Class properties can be made read-only by using a const declaration.
Example:
|
Encapsulation
Keyword | Description |
local | Used to specify that class members are only visible within the class where they were declared.
|
protected | Used to specify that class members are only visible within the class where they were declared and any subclasses.
|
Inheritance
Keyword | Description |
extends | It is used to create a new class that inherits the members of a base class.
|
Polymorphism
Keyword | Description |
virtual | Virtual (class method) is used to define basic polymorphic constructs. A virtual method is used to override a method in all of its base classes.
|
Parameterized classes
Class implementation can be customized by using class parameters. Example:
class vector#(int size = 1)
bit [size -1 : 0] a;
endclass
class stack#(type T = int)
local T items[];
...
endclass
Instantiation:
vector#(10) a = new();
stack#(real) b = new();
Interface class
The interface class is a class that can be viewed as having a common set of behaviours. An interface class shall contain only pure virtual methods, type declarations and parameter declaration, all other blocks and declarations shall not be allowed.
Syntax:
interface class class_name [extends interface_class_type]
// pure virtual methods
// parameters
// type declarations
endclass
A class may implement one or more interface classes.
Example:
interface class set_data#(type SET_TYPE = logic)
pure virtual function void set(SET_TYPE a);
endclass
interface class get_data#(type GET_TYPE = logic)
pure virtual function void get();
endclass
class my_queue#(type T =logic, DEPTH = 1);
T q[$:DEPTH - 1]
virtual void function delete_queue();
q.delete();
endfunction
enclass
class fifo (type T = logic, DEPTH = 1)
extends my_queue#(T, DEPTH)
implements set_data#(T), get_data#(T);
virtual function void set(T a);
q.push_back(a);
endfunction
virtual function void get();
q.pop_front();
endfunction
endclass
Copy-Constructor
The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. Example:
class my_class;
int x,y;
function new();
// simple constructor
endfunction
function new(my_class obj);
this.x = obj.x;
this.y = obj.y;
endfunction
endclass
Operators
Symbol | Description |
= | Binary assignment operator |
+= -= /= *= | Binary arithmetic assignment operator |
%= | Binary arithmetic modulus assignment operator |
&= |= ^= | Binary bitwise assignment operator |
>>= <<= | Binary logical shift assignment operator |
>>>= <<<= | Binary arithmetic shift assignment operator |
+ - * / ** | Binary arithmetic operators |
% | Binary arithmetic modulus operators |
& | ^ | Binary bitwise operators |
>> << | Binary shift operators |
! | Unary logical negation operator |
~ & ~& | ~|
^ ~^ |
Unary logical reduction operator
Example: &y will return the result of an AND operation between all the bits of y |
&& || | Binary logical operations |
< > <= >= | Binary relational operation |
== != | Binary logical equality operators |
=== !== |
Binary case equality operators.
Unlike logical equality operator, this operators can identify x and z. |
++ -- | Unary increment/decrement operation |
Package
package my_pacakge;
//classes
//variables
//functions
//structs
//etc..
endpackage
Wildcard import - Imports all symbols within the package
import my_package::*;
Explicit import - Imports only the mentioned symbol from the package
import my_package::my_symbol;
Processes
Parallel processes:
fork
begin
//Task 1
end
begin
//Task 2
end
begin
//Task n
end
join_keyword
join_keyword | Description |
join | The fork completes when all tasks complete |
join_any | The fork completes when the first task is completed |
join_none | The fork completes immediately |
Verification Features
Randomizations
Declaration | Description |
rand | Used in class declaration to specify that a class property is a random variable with an uniform distribution
|
randc | Used in class declaration to specify that a class property is a random variable with an cyclic distribution
X can take on values in rage of 0 to 3. Randomize will compute an initial random permutation of the range values and return them in order on successive calls. Initial permutation 0,2,1,3 next permutation 2,3,0,1 The values will be generated in the following order 0,2,1,3,2,3,0,1. |
Function | Description |
std::randomize() | It is a built-in function used to randomize local variables or class properties
The randomize function will return 1 if the randomization was successful or 0 otherwise. |
randomize(class method) | Built-in method used to randomize all properties declared with rand and randc. The properties that are not declared rand or randc can still be randomized if they are passed as arguments.
Cannot be overridden!
|
pre_randomize() | Built-in method that is called by the randomize() method before the objects are randomized.
|
post_randomize() | Built-in method that is called by the randomize() method after the objects are randomized.
|
Constraint
Used in class-based randomization, restricting values to specific ranges.
Syntax:
constraint name_c {<constraint_item>;}
class my_class;
rand int random_value;
constraint random_value_c{
random_value >= 0;
random_value <= 15;
}
endclass
Constraint item | Description |
solve..before... | Defines the order of generation for multiple values
Syntax:
Example without solve...before...:
In this case we have three possible combinations (set,reset) = {(0,0);(0,1);(1,0)} each having a 33% chance of occurring. Example with solve...before...:
In this case set is solved first, so (set,reset) = (1,0) has a 50% chance of occurring, instead of 33%. |
foreach | Used to specify constraints over the elements of an array
|
soft | Designates a constraint that is to be satisfied unless contradicted by another constraint with an higher priority.
|
Keyword | Description |
inside | Comparison operator which is true if an expression is contained within a specific list
|
dist | Used to define weighted distributions
Syntax:
The operator is one of the following
Example:
|
with | Used to specify in-line constraints for randomization.
Syntax:
|
Operators and methods | Description |
-> | Implication operator used for conditional constraints. It is similar to the if construct.
Syntax:
Similar to:
|
constraint_mode() task | Used to enable and disable class constraints.
Syntax:
|
constraint_mode() function | Returns the current status of a constraint
Syntax:
|
Functional Coverage
Covergroups
Defines probes that sample relevant information from functional coverage and defines how coverage results will be reported.
covergroup name_cg <coverage event>
//coverpoints
//cross
endgroup
<coverage event> could be:
- @(block_event) example: @(posedge clk)
- with function sample([port_list])
Initialization code:
name_cg = new();
name_cg.set_inst_name(“my_name”);
Coverpoints
Identifies a variable that will be tracked for coverage
Syntax:
coverpoint variable [iff (boolead_expresion)]
{ /* bins */ }
If no bins are defined , the coverpoint creates an automatic bin for every value of the variable.
covergroup my_cg with function sample(bit[31:0] addr)
coverpoint addr iff(rst_n);
{
bins null_addr = {0};
bins valid_addr = {[2:20]};
}
endgroup
Cross
Correlates bins from two or more coverpoints so that an inter-variable value relationship can be explored.
Syntax:
cross expression1 , expression2, … expression n [iff (boolean expression)];
// or
cross expression1 , expression2, … expression n [iff (boolean expression)]
{ /* user defined cross coverage bins; */ }
covergroup my_cg with function sample(bit signal1,bit signal2)
coverpoint signal1;
coverpoint signal2;
cross signal1, signal2;
endgroup
Transitions
Type | Description |
Sequence | A transition from valueA to valueB is defined as such: valueA => valueB 0 => 1 |
Set | Syntax:
|
Consecutive repetitions [*n] | Syntax:
|
Range of repetitions [*n:m] | Syntax:
Example:
|
Goto repetition[->n] | Syntax:
Examples:
Where … is any transition that does not contain the value 1
Notice that the last transition happens immediately after the second 1 to 1 transition. |
Nonconsecutive repetition[=n] | Syntax:
Example:
Where … is any transition that does not contain the value 1
Notice that the transition following the nonconsecutive repetition may occur after any number of transition as long as the value 1 doesn’t occur again. |
Bins
Type of bins | Description |
bins | Allows explicit named coverage bins to be defined and a range of values to be tracked for each bins.
|
wildcard bins | Allows x,z and ? as wildcard values in bins definition
|
illegal_bins | Identifies that a certain range of values are illegal. |
ignore_bins | Identifies that a certain range of values are excluded from coverage. |
default | Default bins are used for all values not covered in other bin ranges. Default bins are not tracked in cross-coverage.
|
Assertions
Type | Description |
Immediate assertions | Syntax:
|
Concurrent assertions | Are SVA directives used to verify that a property holds. Syntax:
|
Cover | Is SVA directive used to verify that a property occurs during simulation. Syntax:
|
SVA Syntax
Sequences
Sequence Type | Description |
Temporal delay ## with integer |
|
Temporal delay ## with range |
|
Consecutive repetition [*m] or range [*n:m] | Where n,m re natural numbers, m>n>=1. The $ sign can be used to represent infinity
|
Non-consecutive repetition [=n], [=n:m] | Example 1:
This is a shortcut for the following sequence
Example 2:
|
Goto non-consecutive repetition [->n], [->n:m] | Example 1:
The difference between the two non-consecutive repetition is that the pattern
Observe that signal_1 is matched before returning to the LOW state. Example 2:
|
Properties
Operator | Description |
Overlapping sequence implication operator |-> | Syntax:
sequence_2 will start in the same clock cycle in which sequence_1 will end Example:
|
Non-overlapping sequence implication operator |=> | Syntax:
sequence_2 will start one clock cycle after sequence_1 has ended
Observation! |
System functions
Function | Description |
$onehot(signal) | Returns true if only one bit of the signal HIGH |
$onehot0(signal) | Returns true if only one bit of the signal is LOW |
$isunknown(signal) | Returns true if at most one bit of the signal is X or Z |
$rose(signal) | Returns true if the signal has changed value to 1 in the current evaluation cycle |
$fell(signal) | Returns true if the signal has changed value to 0 in the current evaluation cycle |
$stable(signal) | Returns true if the signal has the same value as it had in the previous evaluation cycle |
#past(signal, number_of_cc) | Returns the value of the signal at a previous evaluation cycle specified through the number_of_cc argument |
Design and Verification Blocks
Block | Description |
Module | Syntax:
|
Interface | Syntax:
An interface can have different views by defining modports.
Module declaration:
|
Virtual Interface | A virtual interface is a variable that represents an interface instance, providing a mechanism of separating abstract models from the actual RTL implementation. Syntax:
|