Escolar Documentos
Profissional Documentos
Cultura Documentos
Verification Methodology
System Verilog Fundamentals
7/16/15
Content
Verification Methodology
Data types, procedural statements and routines in
System Verilog
Basic OOP and connecting test bench to the DUT
System Verilog Assertion SVA
Randomization in System Verilog
Advanced OOP, thread and inter process
communication
7/16/15
Content
Verification Methodology
System Verilog Fundamentals
Data types
Procedural statements and routines
Verification Methodology
ASIC design
Test bench
Code coverage
Functional coverage
ASIC design
Testbench
Linear Testbench.
+ Instantiate the design under test (DUT)
+ Stimulate the DUT by applying test vectors.
+ Output results waveform window or to a terminal for visual
inspection manually.
Flat testbenh: they probably looked like the low-level code, all in
one file.
Layered testbench : dividing the code into smaller pieces
Code coverage
Statement coverage: also known as line
coverage. This is required to be 100% for every
project.
Block coverage: The block coverage considers
branched blocks of if/else, case branches, wait,
while, for etc.
Conditional coverage: also called as expression
coverage, will reveals how the variables or subexpressions in conditional statements are
evaluated.
Brand coverage: reports the true or false of the
conditions like if-else, case and the ternary
operator (? :) statements in every branch.
Functional coverage
SystemVerilog provides a mechanism to know
the untested feature using functional coverage.
Summary of functional coverage advantages:
+ Functional coverage helps determine how
much of your specification was covered.
+ Functional coverage qualifies the testbenchs.
+ Considered as stopping criteria for unit level
verification.
+ Gives feedback about the untested features.
+ Gives the information about the redundant
tests which consume valuable cycle.
+ Guides to reach the goals earlier based on
grading.
14
15
Phases of verification
16
Verification Plan
The Verification Plan
is the focal point for defining exactly what needs to be tested,
and drives the coverage criteria.
17
18
Fixed-Size Arrays
Declaring:
int fix_arr1[0:15]
bit fix_arr2[7:0][3:0]
bit fix_array3[8][4]
Packed vs Unpacked
PackedUnpacked
Dolphin Technology Inc.
19
Fixed-Size Arrays
Initializing:
int fixed_arr[5];
fixed_arr = {0,1,2,3,4};
fixed_arr[0:2] = {7,6,5};
fixed_arr = {4{5}};
fixed_arr = {defaut:42};
Array Operator:
For
Foreach
int array[0:4];
for (int i =0;i<=4;i++); = foreach(array[i]);
20
Dynamic array
Declaring:
integer dyn_arr_1[], dyn_arr_2[];
interger multi_d_dyn_arr[][];
Initializing:
dyn_arr_1 = new [4];
//allocate 4 element
dyn_arr_1 = {0,1,2,3,4};
dyn_arr_2 = dyn_arr_1;
// copy a dynamic array
dyn_arr_1 = new[20](dyn_arr_1);// allocate 20 element and
copy
Dyn_arr_1.delete;
Dolphin Technology Inc.
21
Queue
A queue is a variable-size, ordered collection of
homogeneous elements.
A Queue is analogous to one dimensional
unpacked array that grows and shrinks
automatically.
Queues can be used to model a last in, first out
buffer or first in, first out buffer
22
Queue
Operator:
int q[$] = { 2, 4, 8 };
int p[$];
int e, pos;
e = q[0]; // read the first (leftmost) item
e = q[$]; // read the last (rightmost) item
q[0] = e; // write the first item
p = q; // read and write entire queue (copy)
q = { q, 6 }; // insert '6' at the end (append 6)
q = { e, q }; // insert 'e' at the beginning (prepend e)
q = q[1:$]; // delete the first (leftmost) item
q = q[0:$-1]; // delete the last (rightmost) item
q = q[1:$-1]; // delete the first and last items
q = {}; // clear the queue (delete all items)
q = { q[0:pos-1], e, q[pos,$] }; // insert 'e' at position pos
q = { q[0:pos], e, q[pos+1,$] }; // insert 'e' after position pos
Dolphin Technology Inc.
23
Queue
Method
The size() method returns the number of items in the queue. If
the queue is empty, it returns 0.
The insert() method inserts the given item at the specified
index position.
The delete() method deletes the item at the specified index.
The pop_front() method removes and returns the first
element of the queue.
The pop_back() method removes and returns the last
element of the queue.
The push_front() method inserts the given element at the
front of the queue.
The push_back() method inserts the given element at the end
of the queue.
Dolphin Technology Inc.
24
Queue
byte qu [$] ;
qu.push_front(2);
qu.push_front(12);
qu.push_front(22);
qu.push_back(11);
qu.push_back(99);
Answer: 22 12 2 11 99
25
Assciative Arrays
data_type array_id [ key _type];
data_type is the data type of the array elements.
array_id is the name of the array being declared.
key_type is the data-type to be used as an key.
Example:
int array_name[*]; //Wildcard index. can be indexed by any
integral datatype.
int array_name [ string ]; // String index
int array_name [ some_Class ]; // Class index
int array_name [ integer ]; // Integer index
typedef bit signed [4:1] Nibble;
int array_name [ Nibble ];
Dolphin Technology Inc.
Assciative Arrays
Methods
num() or size()method returns the number of entries in
the associative array.
delete() method removes the entry at the specified
index.
exists() function checks whether an element exists at
the specified index within the given array.
first() method assigns to the given index variable the
value of the first (smallest) index in the associative array.
It returns 0 if the array is empty; otherwise, it returns 1.\
27
Assciative Arrays
last() method assigns to the given index variable the
value of the last (largest) index in the associative array. It
returns 0 if the array is empty; otherwise, it returns 1.
next() method finds the entry whose index is greater
than the given index. If there is a next entry, the index
variable is assigned the index of the next entry, and the
function returns 1. Otherwise, the index is unchanged,
and the function returns 0.
prev() function finds the entry whose index is smaller
than the given index. If there is a previous entry, the
index variable is assigned the index of the previous
entry, and the function returns 1. Otherwise, the index is
unchanged, and the function returns 0.
Dolphin Technology Inc.
28
Linked list
Linked list: is defined as a parameterized class,
meaning that it can be customized to hold data of
any type.
Container: are objects that contain and manage other
objects
Iterator: provide the interface to containers.
are pointers to nodes within a list
`include <List.vh>
List#(integer) il;
List_Iterator#(integer) itor;
Dolphin Technology Inc.
29
Linked List
`include <List.vh>
module lists();
List#(integer) List1;
List_Iterator#(integer) itor;
initial begin
List1 = new();
List1.push_back(10);
List1.push_front(22);
List1.pop_front();
List1.pop_front();
List1.push_back(5);
List1.push_back(55);
List1.push_back(555);
List1.push_back(5555);
itor = List1.start();
itor.next();
itor.next();
itor.next();
itor = List1.erase(itor);
end
endmodule
Dolphin Technology Inc.
30
Array Methods
sum, product
and or xor
min max unique find
reverse sort rsort - shuffle
31
Compare
Flexibility:
Choose a fixed-size array if the array size is known at
compile time
Choose a dynamic array if the array size is not known
until run time
Choose associative arrays for nonstandard indices such
as widely separated values because of random values or
addresses
Choose queues or linked list are a good way to store
values when the number of elements grows and shrinks
a lot during simulation
32
Compare
Speed:
Fixed-size array, dynamic array : fastest because
elements are stored in contiguous
Queue: not fast if Inserting or removing elements in the
middle
Linked list: not fast if Inserting or removing elements in
the middle
associative array: slowest and increase with size of array
33
Compare
Size
Fixed-size, dynamic array: good if array has a thousand
to a million elements
Queue: if your data set grows and shrinks often
Associative array: good if array has larger than a few
megabytes
Linked list: not good if array size is big
34
35
36
Enumerated Types
An enumerated type allows you to create a set of
related but unique constants such as states in a state
machine or opcodes.
Eg : enum {red, blue, green} color;
You can get the string representation of an
enumerated variable with the built-in function name()
Defining Enumerated Values: The actual values
default to intstarting at 0 and then increase.
Provides several functions: first, last, next, prev
The default type for an enumerated type is int(2state).
Dolphin Technology Inc.
37
Constants
Parameter: In SystemVerilog, parameters can be
declared in a package so they can be used across
multiple modules.
Const
Eg : parameter A = 10;
Const byte colon = :;
38
Strings
An individual character is of type byte. The
elements of a string of length N are numbered 0 to
N-1.
The character \0 is ignored because memory for
strings is dynamically allocated.
Provide several function: getc(N), toupper(),
tolower(), putc(M,C), substr(start,end),
s1.compare(s2)
39
Expression width
Expression width depends on context.
bit [7:0] b8;
bit one = 1b1;
$displayb (one + one);
//0
b8 = one + one;
//2
$displayb(b8);
$displayb(one + one + 2b0);
$displayb(2(one) + one);
//2
//2
40
41
42
43
7/16/15
Content
OOP brief
Object creation
Object de-allocation
Static and global variables
Class routines
Defining routines outside of the class
Using one class inside another
Dynamic objects
Copying object
Public and private
45
OOP Brief
Procedural programming (Verilog, C,)
Data structures (types) and the code (algorithms)
that uses them, are often separate in different files
=> Difficult to understand the functionality of a
program
There are no structures, only bit vectors and arrays
=> Limited in modeling and organizing data
The arrays are all static
=> Less flexibility and compatibility
46
OOP Brief
OOP - Object Oriented Programming
Create complex data types and tie them together
with the routines that work with them
Create testbenches and system-level models by
calling routines to perform an action
Working at a higher level, code is more easily
written and understood
More robust and easier to maintain and reuse on
future projects
47
OOP Brief
Terminology
Class
Object
Handle
Attribute
Method
Inheritance
Encapsulation
Abstraction
Polymorphism
etc
48
OOP Brief
Class
Contains data and codes with behavior
Describes all the properties, behavior, and identity
of objects
Object
An instance of class with behavior, identity
Expressed by the variable and methods
49
OOP Brief
Handle
A pointer to an object
Attribute
A variable that holds data
Method
Procedural code that manipulates variables, are
tasks and functions
Define the abilities and behaviors of an object
Dolphin Technology Inc.
50
OOP brief
Example
Attribute
Method
Handle
Object
Dolphin Technology Inc.
51
Object Creation
Declare a handle
Transaction tr;
tr points to an object of type Transaction,
initialized to the special value null
Can refer to many objects, but only one at a time
Construct a object
tr = new();
Allocates space for the Transaction
Initializes the variables to their default value
Returns the address where the object is stored
Dolphin Technology Inc.
52
Object Creation
new() function
Making an instance of the class
For every class, SystemVerilog creates a default
new function to allocate and initialize an object
Custom constructor
53
Object Creation
Allocating multiple objects
Using objects
54
Object Deallocation
Long simulation might run out of memory
When a object is no longer use, should reclaim the
memory
Garbage collection is the process of automatically
freeing objects that are no longer referenced
When the last handle no longer references an
object, SystemVerilog releases the memory for it
55
Class Methods
Just a task
or function
defined
inside the
scope of
the class
56
57
58
Global
Visible to the entire testbench
Dolphin Technology Inc.
59
60
61
62
Dynamic Objects
In Verilog, every signal has a unique variable
associated with it
In OOP, there can be many objects, but only a few
named handles to manipulate them
Flexibility in allocate and de-allocated to save
memory in storing objects and during a simulation
63
Dynamic Objects
Passing Objects and Handles to Methods
64
Dynamic Objects
Modifying a Handle in a Task
Using ref on method arguments
SystemVerilog passes the address of the variable
so the method can modify it
65
Dynamic Objects
Modifying Objects in Flight
Need to create a new object for each transaction in
the testbench
66
Dynamic Objects
Arrays of Handles
The array made of handles, not objects
Need to construct each object in the array before
using it
Can not call new on an entire array of handles
67
Copying Objects
Copying an Object with the New Operator
Memory for the new object is allocated
all variables from the existing object are copied
68
Copying Objects
Any new() function that have defined is not called
69
Copying Objects
Writing Your Own Simple Copy Function
If class that does not contain any references to
other classes
70
Copying Objects
Writing a Deep Copy Function
If class that contain any references to other classes
71
72
74
endmodule
module top();
reg clk;
wire read, enable;
wire [7:0] addr;
wire [7:0] data;
Dut D
(clk,read,enable,Addr,data);
Testbench TB(clk,read,enable,Addr,data);
endmodule
Dolphin Technology Inc.
75
76
endmodule
endmodule
module top();
bit clk;
initial
forever #5 clk = ~clk;
intf bus_if(clk);
Dut d(bus_if);
Testbench TB (bus_if);
endmodule
Dolphin Technology Inc.
77
78
intf
bus_if(clk);
Dut
d(bus_if.dut);
Testbench TB(bus_if.tb);
endmodule
Dolphin Technology Inc.
79
Stimulus timing
- The timing between the testbench and the design should be
maintained to avoid race conditions.
80
Stimulus timing
Clocking block:
Identify clock signals, and captures the timing and
synchronization requirements of the blocks being
modeled.
Assembles signals that are synchronous to a
particular clock, and makes their timing explicit.
Clocking blocks can only be declared inside a
module, interface or program.
81
Stimulus timing
A testbench can contain one or more clocking
blocks.
Example interface use clocking block.
82
Stimulus timing
Referencing signals in the Clocking Block
83
Stimulus timing
Skew:
Input skew is specified then the signal is sampled at skew
time units before the clock event.
Output skew is specified, then output (or inout) signals are
driven skew time units after the corresponding clock event.
84
Stimulus timing
Skew can be specified in 3 ways:
#d: The skew is d time units.
#dns: The skew is d nano seconds.
#1step: specifies that signals be sampled in the postpone
region before any design activity.
If skew is not specified, default input skew is 1step and
output skew is 0.
85
Stimulus timing
Signal Synchronization:
Synchronize to active clock edge
86
SystemVerilog Assertion
Verification Training
7/16/15
88
89
SystemVerilog Assertion
Checker
Dolphin Technology Inc.
90
Sequence Assertion
sequence
name_of_sequence;
<test expression>;
endsequence
Sequence with edge definitions
Srose {boolean expression or
signal name)
$fell ( boolean expression or
signal name)
sequence s2 ;
@(posedge elk)
$rose(a) ;
endsequence
91
Sequence Assertion
Sequences with timing
relationship
sequence s4 ;
@( posedge clk ) a ##2 b;
endsequence
92
Property Assertion
Syntax:
property name_of_property;
<test expression>; or
< complex sequence
expression>
endproperty
assertion_name: assert property
(property_name);
Forbidding a property
sequence s6;
@ (posedge clk) a ##2 b;
endsequenee
property p6;
not s6;
endproperty
a6 : assert property(p6) ;
93
Property Assertion
property p7;
@ (posedge clk) a ##2 b;
endproperty
a7 : assert property(p7)
$display("Property p7
succeeded\n") ;
else
$ display (" Property p7 failed \ n
");
Implication operator
Overlapped implication
Non-overlapped implication
94
Property Assertion
Implication operator
Overlapped implication
property p8 ;
@(posedge clk) a
|-> b;
endproperty
a8 : assert
property(p8) ;
95
Property Assertion
Implication
operator
Non-overlappedproperty p9 ;
implication
@(posedge clk) a |
= > b;
endproperty
a9 : assert property
(p9) ;
96
SVA constructs
$past (signal_name, number of clock
cycles)
property p19;
@(posedge clk) ( c && d ) |->
($past((a&&b) , 2) == 1b1) ;
endproperty
a19: assert property (p19) ;
97
98
99
100
101
102
Randomize
7/16/15
Randomization in SystemVerilog
Simple
class Packet;
rand bit [3:0] src,dst;
randc bit [2:0] kind;
constraint c {src>2;
src<11;}
endclass
program main;
Packet p;
initial begin
p = new();
repeat(9)
begin
void'(p.randomize());
$display("src =%d ,dst= %d, kind = %d",
p.src, p.dst, p.kind);
end
end
endprogram
Result
#src = 3 ,dst=
5
# src = 3 ,dst=
=0
# src =10 ,dst=
=1
# src = 3 ,dst=
=6
# src =10 ,dst=
=7
# src = 3 ,dst=
=2
# src = 3 ,dst=
=4
# src =10 ,dst=
=3
# src = 3 ,dst=
=3
9, kind =
4, kind
2, kind
12,kind
3, kind
7, kind
0, kind
4, kind
14,kind
104
Randomization in SystemVerilog
Checking the Result from Randomization
class Packet;
rand bit [3:0] src,dst;
randc bit [2:0] kind;
constraint c {src>3;
src<2;}
endclass
program TestResult;
Packet p;
initial begin
p = new();
if (p.randomize())
$display("VALID RANDOM");
else
$display("INVALID RANDOM");
end
endprogram
Dolphin Technology Inc.
result
INVALID RANDOM
=> The
randomizefunction returns
0 if a problem is found
with the constraints
105
Randomization in SystemVerilog
106
Constraint Details
Simple Expresions
Repair:
Bad ordering constraint
class Order_good;
class Order_bad;
rand bit [7:0] lo, med,hi;
rand bit [7:0] lo, med,hi;
constraint bad {lo < med < hi;} constraint good {lo < med;
med < hi;}
endclass
endclass
result
lo = 20 , med = 224, hi = 164
lo = 114, med = 39 , hi = 189
lo = 186, med = 148, hi = 161
lo = 214, med = 223, hi = 201
107
Constraint Details
Weighted Distributions
changing distribution
Weight random distribution with Dynamically
dist
weights
class Transaction;
class BusOp;
rand bit [1:0] src,dst;
typedef enum {BYTE,WORD,LWRD}
constraint c_dist {
src dist {0:= 40, [1:3] := 60}; length_e;
rand leght_e len;
// src = 0 , weight = 40/220
bit [31:0] w_byte =1, w_word
// src = 1 , weight = 60/220
// src = 2 , weight = 60/220 =3,w_lwrd =5;
contraint c_len {
// src = 3 , weight = 60/220
len dist {BYTE
:= w_byte;
WORD := w_word;
dst dist {0:/40, [1:3] := 60};
LWRD := w_lwrd;};
// dst = 0, weight = 40/100
}
// dst = 1, weight = 20/100
endclass
// dst = 2, weight = 20/100
// dst = 3, weight = 20/100
}
endclass
108
Constraint Details
109
Constraint Details
110
Constraint Details
Bidirectional Constraints
Bidirectional constraints
class Birdir;
rand bit [15:0] r,s,t;
constraint c_bidir { // all are
solved in parallel
r < t;
// A value for r
affect s,t
s == r;
t < 10;
s >5 ;
}
endclass
111
Constraint Details
Implication Constraints
The expression A->B is equivalent to the
expression (! A || B)
Ex:
class LogImp;
rand bit d,e;
constraint c {
(d == 1) -> (e ==1);
}
endclass
=> when d==1, the variable
e must be 1, but when e==1,
d can be 0 or 1
112
Constraint Details
Implication Constraints
An if-else implication constraint
class BusOp;
rand operand_e op;
rand length_e len;
constraint c_len_rw {
if (op == READ) {
len inside {[BYTE:LWRD]};
else {
len == LWRD;
}
}
endclass
113
Constraint Details
Equivalence Operator
The equivalence operator <->is bidirectional. A<>Bis defined as ((A>B) && (B->A))
Ex:
rand bit d,e;
constraint c {d == 1} <-> (e ==
1);
=>}When dis true, emust also be true, and
when dis false, emust also be false
114
Solution Probabilities
Unconstrained
Implication
class Imp1;
class unconstrained;
rand bit x;
rand bit x;
// 0 or 1
rand bit [1:0] y;
rand bit [1:0] y; // 0 ,1,2 or 3
constraint c_xy {
endclass
(x == 0) -> (y == 0);
}
115
Solution Probabilities
116
Solution Probabilities
117
118
class rand_mode;
rand integer Var1;
rand integer Var2;
constraint Var_1 { Var1 == 20;}
constraint Var_2 { Var2 == 10;}
endclass
program rand_mo_p_38;
rand_mo obj = new();
initial
begin
obj.randomize();
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
obj.constraint_mode(0); //Both constraints Var_1 and Var_2 are turned off.
obj.randomize();
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
obj.constraint_mode(1); //Both constraints Var_1 and Var_2 are turned on.
obj.randomize();
$display(" Var1 : %d Var2 : %d ",obj.Var1,obj.Var2);
end
endprogram
Var1 : 20 Var2 : 10
Var1 : 733126180 Var2 : -119008195
Var1 : 20 Var2 : 10
119
In-Line Constraints
Inline constraints allows to add extra constraints to already existing
constraints which are declared inside class.
Syntax : using randomize with
Example
class inline;
rand integer Var;
constraint default_c { Var > 0 ; Var < 100;}
endclass
program inline_test;
inline obj;
initial
begin
obj = new();
repeat(2)
if(obj.randomize() with { Var == 50;})
$display(" Randodmize sucessful Var %d
",obj.Var);
else
$display(" Randomization failes");
end
endprogram
Dolphin Technology Inc.
# Randodmize sucessful
Var 50
# Randodmize sucessful
Var 50
120
# PRE_RANDOMIZATION
# POST_RANDOMIZATION
121
122
123
class Packet;
rand bit [31:0] length;
bit [3:0] max_length =100;
constrain c_length {
length inside {[1:max_length]}
}
endclass
124
endfunction
endclass
Packet p;
Initial begin
p = new();
p.randomize();
p.display( simple randomization);
p.length.rand_mode(0);
p.length = 40;
p.randomize();
p.display (randomization with rand_mode);
end
Dolphin Technology Inc.
125
126
127
(-63, 127)
128
129
Efficient constraint
rand bit [31:0] addr;
constraint c {
addr [11:0] inside {[0:20], [4075:4095]};
}
Dolphin Technology Inc.
130
131
132
133
sum
sum
sum
sum
sum
=-120,val=-120
= 50,val= 123 53 60
= 80,val= 80
=
5,val=-113 26 87
= 13,val=-111-123 -87
59
11
5
78
134
135
136
Random control
Introduction to randcase
You can use randcase tomake a weighted choice between
several actions, without having to create a class and
instance
Example:
initial begin
bit [15:0] len;
randcase
1: len=$urandom_range(0,2); //10%: 0,1,2
8: len=$urandom_range(3,5); //80%: 3,4,5
1: len=$urandom_range(6,7); //10%: 6,7
endcase
end
Dolphin Technology Inc.
137
138
139
random
random
random
random
random
=
=
=
=
=
-2147345408
-2147345408
-2147345408
-2147345408
-2147345408
140
141
142
Ran_1.Var
Ran_1.Var
Ran_1.Var
Ran_1.Var
Ran_1.Var
Ran_2.Var
Ran_2.Var
Ran_2.Var
Ran_2.Var
Ran_2.Var
:
:
:
:
:
:
:
:
:
:
0
5
0
3
4
5
5
1
7
1
143
144
Ran_2.Var
Ran_2.Var
Ran_2.Var
Ran_2.Var
Ran_2.Var
Ran_1.Var
Ran_1.Var
Ran_1.Var
Ran_1.Var
Ran_1.Var
:
:
:
:
:
:
:
:
:
:
5
5
1
7
1
0
5
0
3
4
145
146
147
SEED is initised to 20
: 1189201676 :
: -50602121 :
: 1441010736 :
: 999569011 :
: -161019490 :
SEED is initised to 1
: 1232952047 :
: 9295156 :
: -183300904 :
: -83119859 :
: 1832521658 :
148
7/16/15
Content
150
151
152
153
154
155
156
Disabling Threads
Disabling a Single Thread
- Labelling for
the blocks to
specify what
to stop.
- Use disable
function.
157
Disabling Threads
Disabling Multiple Thread
- Use disable
fork function.
- Stop threads
2,3,4
Dolphin Technology Inc.
158
IPC Events
A handle to a synchronization object that can be
passed around to routines
To share events across objects without having to make
the events global
The most common way is to pass the event into the
constructor for an object
Operator:
@ a thread waits for an event to change
-> unblocking the first thread
Status e.triggered check whether an event has been
triggered
Dolphin Technology Inc.
159
IPC Events
Blocking on the Edge of an Event
160
IPC Events
Waiting for an Event Trigger
161
IPC Events
Passing
Events
162
IPC Semaphores
Semaphore: to control access to a resource using
a key
semaphore sem; //create a semaphore
Tasks
new(num_key) create a semaphore with one or
more keys
get() get one or more
put() return one or more keys
try_get() try to get a semaphore, obtains
available keys and returns 1. returns 0 if there are
not sufficient keys
Dolphin Technology Inc.
163
IPC Semaphores
Example
164
IPC Mailboxs
Mailbox: To pass information between two threads
165
IPC Mailboxs
Mailbox in a Testbench
166
167
168
169
Advanced OOP
Advanced OOP
Introduction to inheritance
o
Inheritance is the mechanism which allows a class A
to inherit properties of a class B.
o
A inherits from class B, then B is called superclass of
A, A is called subclass of B.
171
Advanced OOP
Example
class Transaction;
rand bit [31:0] src,dst,data[8];
bit [31:0] csm;
virtual function void calc_csm();
csm = src^dst^data.xor;
endfunction
virtual function void display(input
string prefix="");
$display("%sTr: src = %h, dst=
%h, csm=%h, data=%p",
prefix,src,dst,csm,data) ;
endfunction
endclass
Advanced OOP
A subclass inherits all the members (fields, methods,
and nested classes) from its superclass. But constructor
not inherited by subclasses.
Example:
173
Advanced OOP
Downcasting and Virtual Methods
Downcasting is the act of casting a base class handle
to point to an object that is a class extended from that
base type.
174
Advanced OOP
Example:
175
Advanced OOP
SystemVerilog provides the $cast system task to assign
values to variables that might not ordinarily be valid
because of differing data type.
The syntax for $cast() is as follows:
task $cast( singular dest_handle, singular source_handle );
function int $cast(singular dest_handle, singular source_handle );
176
Advanced OOP
Example:
177
178