System Verilog 2
System Verilog 2
/4state
array:
module fixed_array;
int array_1[4];(compact declaration)
//int array_1[3:0](verbose declaration)
initial begin
array_1='{0,1,2,3};
end
$display("display array_1");
foreach(array_1[i])
$display("\t array_1[%0d]=%0d", i,array_1[i]);
endmodule
2.dynamic array :
sytax: data_type array_name []
methods: new[],size(),delete()
module dy_array;
int array_1[];
//int array_1[3:0](verbose declaration)
initial begin
dy_array = new[4];(1st method)
array_1='{0,1,2,3};
end
array_1.delete();(2nd method)
$display("display array_1");
foreach(array_1[i])
$display("\t array_1[%0d]=%0d", i,array_1[i]);
$display("size of the array=%0d",array_1.size());
array_1=new[8](array_1); (3rd method)
$display("size of the array after resizing=%0d",array_1.size());
endmodule
Methods:
num()
delete()
exist()
fisrt()
last()
next()
prev()
4. Queue
syntax: data_type queue[$];
methods:
size()
delete()
push_front()
push_back()
pop_front()
pop_back()
Types of Queue:
packed array:
-> dimensions are declared before identifier are called packed arrays
-> these are contigious set of bits
-> it supports single data type reg, logic, bit, enum
syntax: bit[2:0][3:0] array;
unpacked array:
Blocking Statements:
-> In blocking the statements execute in serial/sequentially
-> it is indicated with "="
-> It will execute at current timestamp
Non-Blocking Statements:
Unique if:
-> the statements will execute in parallel
Task
Argument Passing:
1. argument pass by value => any changes in arguments will not be visible outside
of the subroutine
2. argument pass by reference => any changes in argument will be visible outside
of the subroutine
3. argument pass by name => string => it specfies words/names
4. argument pass by position =>
const keyword => any changes made in arguments in function with const keyword will
give you compiler error
Ex:
intial begin
x = 6;
y = 3;
z = sum(x,y);
end
class:
class <class_name>
//functionality
endclass
This keyword:
class bindu;
int a;
int b;
endfunction
endclass
static property:
syntax:
static method:
class packet;
packet
pkt1
pkt2
Class Assignment:
Same memory location it will be allocated and which can be accessed by two
different handles. If any handle will change class properties,
it will reflect the same changes when your accessing by another handle.
EX:
class packet;
bit[31:0] data;
int start_addr; = 2
int end_addr; = 5
endclass
pkt1;
pkt2;
pkt2 = pkt1
pkt1.data
Shallow Copy:
objects will not be copied, only there handles are copied i.e., properties of class
are copied, unlike the objects
if your having an object then the handles as well object will share same memory
Deep Copy:
Deep copy will copy all the class members and its nested class
in deep both objects and handles are copied
to perform a deep copy, we need a method called copy
By adding copy method, new object will be created and then all class properties
will be copied to a new handle
Inheritance:
Example:
//properties
endclass
endclass
module tb;
child = new();
endmodule
Polymorphism:
-> As we know, the derived class object can override methods of its base class.
Similarly, the base class object can also override the method of one of the child
classes.
-> It means a base class method has different forms based on derived class
implementation.
-> To use many forms of the method, the virtual keyword must be used in the method
definition.
If any method is declared as virtual in the parent class then by default same
method works as virtual in child class
super keyword:
Casting:
1. static casting => these are not applicable to OOP, bcz these are not
dynamic in nature
=> static is nothing but the data type will be fixed
=> value, variable, expression
Example:
module prateek;
real r;
int i;
initial begin
r = (2*3.5);
i = int'(3*5);
$display("r = %0f, i =%0d", r,i);
end
endmodule
$cast(child_class,parent_class);
Data Hiding and Encapsulation:
By default all the class members are public, by using data hiding concept we can
make the class members as private
1. Local : it cannot access local properties inside the child class as well as
outside the class
2. Protected / Private : it can access in child class but outside of the class is
not possible(it will lead to compilation error)
Abstract class:
A class declared with keyword virtual then we call it is abstract class, it doesn't
let anyone to use this class, except its extended/derived class
syntax:
virtual class<class_name>
//
endclass
Virtual Methods:
A function which is declared with a virtual keyword before the function is called
as virtual function
A task which is declared with a virtual keyword before the task is called as
virtual task
syntax:
// function definition
endfuntion
or
virtual task task_name;
//task definition
endtask
Syntax:
<class_name>::<class member>
Extern Method:
Extern method will provide a facility for class methods to define them outside the
class body
If the method definition is lenghty i.e., lines of code inside a method are more),
this extern method will provide you better releability
this extern keyword is used for method declaration and a class name with scope
resoultion operator is used for method definition
1. method defintion and declaration should have the same number of argument lines,
data types, argument names
2. for the extern funtion return type should be same if you are using
Typedef class:
It is a user_defined class
It is used to allow forward declaration of the class
in some cases, the class needs to be instantiated before the class declaration
syntax:
Randomization:
$random is basically used in verilog => randomizing the object $random is not
sufficient, it is limited to 32-bit size
It is generating random values for variables by using rand and randc keywords.
keywords
1. rand => will give you random values for the variables values will repeat (i.e.,
2567132)
2. randc => will give you random values in random-cyclic, values will not
repeat(i.e., 2567135)
syntax:
rand bit[3:0] a;
randc bit[3:0] a;
=> for complex designs there are high chances of getting bugs in the design, to
verify dut we need to provide some stimulus by verification engineer,
there can be multiple cross comibinations of variables in real system, this is
not possible practically to write directed cases to verify every possible
combinatin,
that is the reason we are using randomization
Disable randomization:
=> the variable is declared withoud rand randc will not get random values on
randomization
=> to disable the randomization of a variable by using the method called
(rand_mode)
rand_mode method:
syntax:
<object_handle>,<variable_name>.rand_mode(enable = 1/disable = 0)
randomization methods:
these pre_randomize() and post_randomize() functions which are called before and
after the randomize call
1. pre_randomize => function call used to set pre-conditions before the object
randomization
2. post_randomize => function call used to check and perform post-conditions after
the object randomization
Constraint:
It is used to control the values which are getting randomized, this can be achieved
by constraints.
For ex: random variable, you can get specific value, and ranges by using
randomization
constraints blocks are enclosed within {}
Syntax:
Constraint inside:
=> By using inside operator we can achieve random values for a specified
value/range
=> values within the inside block can be variable, constant, range
=> inside block is written followed by {}
Syntax:
Ex:
:= the operator indicates specified weight of the value/item, if it is in range
then it specifies weight to every value in the range
a dist{2 := 6, 12 := 8, 15 := 7, 6: =7};
a == 2, weight 6
a == 12, weight 8
a == 15, weight 7
a == 6, weight 7
a dist{2 :/ 6, [14:16] :/ 7, }
a == 2, weight 6
a == 14, weight 7/3
a == 15, weight 7/3
a == 16, weight 7/3
Implication Constraint:
syntax:
Disable Constraints:
syntax:
<object_handle>.<constraint_block_name>.constraint_mode(enable = 1/diable = 0)
Static Constraints:
syntax:
Inline Constraint:
Constraints will be written inside the class, inline constraints allow the user to
have an extra constraint to existing constraints will be written outside d the
class
i.e., by using "with" in module
syntax:
Soft Constraints:
Constraints which are declared by using soft keyword is called soft constraints.
Any conflict which has arrived between class and inline constraints leads to
randomization faiure, It can say that it is not possible to override the class
constraint by inline constraint.
if you want to override then it is done only by soft keyword
syntax:
Unique constraints:
=> Constraint which is defined by keyword unique are called as unique constraints.
=> when you are doing randomization, you need to get unique values for a set of
variables or elements by using unique constraints
=> generate unique elements in an array(fixed, dynamic, associative, queue)
Bidirectional constraints:
ex:
Solve Constraint:
this is like constraint property, where slove before is used inside the constraint
block to specify the order of constraint solving
1. Semaphores
2. Mailbox
3. Events
Semaphore:
=> It is a built-in class and used to access shared resources and for
synchronization.
=> It is like a bucket with number of keys, first person should procure a key from
the bucket, all the other persons should wait until a key is retured.
Syntax:
semaphore semphore_name;
Methods:
get():
It is blocking method
get method is used to get keys from a semaphore
semaphore_name.get(no.of keys) -> semaphore_name.get();
put():
try_get();
Mailbox:
syntax:
mailbox mailbox_name;
Methods:
Types of mailbox:
1. Generic mailbox(type-less)
=> single mailbox which can send and receive data of type
=> syntax: mailbox mailbox_name;
2. Parameterized mailbox(with particular type)
Bounded mailbox:
Unbounded mailbox:
Events:
1. Event triggering:
-> operator:
this is used to trigger an named event, by triggering this event it will unblocks
all processes which are currently waiting on that event
->> operator:
@ operator:
to wait an event to be triggered by using @
if trigger an event (->) and wait for an event (@) these both are happened at same
time, race around condition will occur, this can be avoided by triggered property
wait operator:
if event triggering and waiting for event trigger with @ operator happens at same
time, then it will not detect proper event
wait(event_name.triggered);
wait_order():
it is a construct which is blocking the process until all specified events are
triggered
if the event is trigger without order will not unblock the process
wait_order(a, b, c);
else
$display("events are out of order");