Sys Verilog PPT PDF
Sys Verilog PPT PDF
INTRODUCTION, DATA
TYPES
What is SV?
Constrained
Randomization
OOPS Improved
Data Types
System Verilog
Functional
Synchronization
Coverage
Assertions
Futurewiz
www.futurewiz.co.in
Regions in SV
Futurewiz
www.futurewiz.co.in
Data Type
Futurewiz
www.futurewiz.co.in
4-State Type
Futurewiz
www.futurewiz.co.in
4-State Type
Example1:
module and_gate ( input logic a, b,
output logic c);
assign c= a & b; //driving logic using continuous
assignment
endmodule
Example2:
module flip_flop ( input logic din, clk,
output logic dout);
always @ (posedge clk)
dout<=din; //driving logic using procedural
assignment
endmodule Futurewiz
www.futurewiz.co.in
Logic
Example3:
module example3 ( input logic a, b,
output logic c);
always @ *
c= a | b; //driving logic using procedural
assignment
This code will give compilation error because of multiple
endmodule
driver.
Futurewiz
www.futurewiz.co.in
Logic
Example4:
module example1;
int a;
int unsigned b; //unsigned integer
bit signed [7:0] c; //same as byte
initial
begin
a=-32’d127;
b=‘1; //SV offers un-sized literal to fill all
c=‘0; // locations with given number
end
endmodule
Futurewiz
www.futurewiz.co.in
Example2
module example2;
int a;
logic [31:0] b=‘Z; //b=32’hzzzz_zzzz
initial
begin
a=b; //a=32’h0000_0000
b=32’h123x_5678;
if($unknown(b)) $display(“b is unknown”);
else $display(“b is known”);
end
endmodule
Futurewiz
www.futurewiz.co.in
Real Type
Example: Usage:
Futurewiz
www.futurewiz.co.in
Arrays
Futurewiz
www.futurewiz.co.in
Fixed Array
Examples
Example:
int array1 [16] [8]; //16 rows , 8 columns
bit array2 [3:0] [7:0]; //4 rows , 8 columns
bit [7:0] array3 [4]; //4 rows each containing 8 bits
Futurewiz
www.futurewiz.co.in
Unpacked Array
Futurewiz
www.futurewiz.co.in
Unpacked Array
Initializing Array:
int array1 [2] [4] = ‘{ ‘{ 1, 2, 3, 4 } , ‘{ 5, 6, 7, 8 } };
int array2 [2] [3] = ‘{ ‘{ 1, 3, 6 } , ‘{ 3 {2} };
// same as ‘{ 1, 3, 6 } , ‘{ 2, 2, 2 }
int array5 [2] [2] [2] = ‘{ ‘{ ‘{4, 5}, ‘{3, 1} }, ‘{ ‘{1, 7}, ‘{2, 5} }
}; Futurewiz
www.futurewiz.co.in
Unpacked Array
Accessing Array
int array1 [2] [4];
int array2 [0:5];
byte array3 [0:2] [1:4];
int a, b;
byte c;
a= array1[1] [3];
b= array2[4];
c= array3[1] [2];
Futurewiz
www.futurewiz.co.in
Basic Array Operation
initial
begin
for ( int i=0; i <$size(array1); i++) //$size returns size of
array
array1[ i ]= 0;
foreach(array2[ k ]) //k is defined implicitly
array2[ k ]=$random;
end
Futurewiz
www.futurewiz.co.in
Basic Array Operation
Example:
bit [7:0] array1[10] [20];
initial
begin
array1=‘{10 { ‘{0:2, 1 : 0 , default:$random} } };
foreach(array1[i ,k])
$display(“array1[%0d] [%0d]=%0d”, i, k, array1[i] [k]);
end
Futurewiz
www.futurewiz.co.in
Packed Array
7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
b[0] 76543210765432107654321076543210
b[0] [2] b[0] [1] [4:0]
b[1] 76543210765432107654321076543210
b[1]
b[2] 76543210765432107654321076543210
b[2] [2]
b[3] 7 6 5 4 3 2 1 0 7 6 5[2]
432107654321076543210
b[3] [0]
Futurewiz
www.futurewiz.co.in
Packed vs. Unpacked Array
Futurewiz
www.futurewiz.co.in
Operation on Arrays
A=0;
A=A + 3;
A=A * 2;
A=‘1;
A=A & 32’d255;
A[3:1]=16’b1101_1110_0000_1010;
Futurewiz
www.futurewiz.co.in
Dynamic Array
Futurewiz
www.futurewiz.co.in
Dynamic Array
initial
begin
dyn1=new[10]; //Allocate 10 elements
foreach (dyn1[ i ]) dyn1[ i ]=$random; // Initializing Array
dyn1=new[20] (dyn1); // Resizing array and
// Copying older values
dyn1=new[50]; // Resizing to 50 elements Old Values are lost
dyn1.delete; // Delete all elements
end
Futurewiz
www.futurewiz.co.in
Dynamic Array
initial
begin
repeat (2)
if (dyn1.size != 0)
begin
foreach(dyn1 [ i ] ) $display(“dyn1[%0d]=%0d”, i, dyn[ i ] );
dyn1.delete;
end
else
$display(“Array is empty”);
end
Futurewiz
www.futurewiz.co.in
Queue
Declaration:
int q1 [ $ ]; // Unbounded Queue
int q2 [ $ : 100 ]; // Bounded Queue max size is
101
Operators:
q [ a : b ];
0 < a < b returns queue with b - a + 1 elements.
a = b = n returns q[n]
a > b returns empty queue
a or b is either x or z returns empty queue
a < 0 returns q [0: b]
b > $ returns q [a:$]
Futurewiz
www.futurewiz.co.in
Queue Methods
int A [$] = ‘{ 0, 1, 2, 3, 4, 5, 6 }; A 0 1 2 3 4 5 6
int x, y, z;
q = { q, 6 }; // q.push_back(6)
q = { 3, q }; // q.push_front(3)
q = q [1:$]; // void'(q.pop_front())
// or q.delete(0)
q = q[0:$-1]; // void'(q.pop_back())
// or q.delete(q.size-1)
q = { q[0:3], 9, q[4:$] }; // q.insert(4, 9)
q = {}; // q.delete()
q = q[2:$]; // a new queue lacking the first two items
q = q[1:$-1]; // a new queue lacking the first and last items
Futurewiz
www.futurewiz.co.in
Array Query Functions
Futurewiz
www.futurewiz.co.in
Array Query Functions
Futurewiz
www.futurewiz.co.in
Array Locator Methods
find_index() returns the indices of all the elements satisfying the given
expression.
Futurewiz
www.futurewiz.co.in
Array Locator Methods
Futurewiz
www.futurewiz.co.in
Array Locator Methods
Futurewiz
www.futurewiz.co.in
Array Locator Methods
b = c.min; // {1}
b = c.max; // {7}
b = a.unique; // {1, 3, 4, 8, 9}
b = a.find with (item > 3); // {9, 8, 4, 4}
b = a.find_index with (item > 3); // {0, 2, 4, 5}
b = a.find_first with (item > 3); // {9}
b = a.find_first_index with (item==8); // {2}
b = a.find_last with (item==4); // {4}
b = a.find_last_index with (item==4); // {5}
Futurewiz
www.futurewiz.co.in
Array Ordering Methods
A.reverse(); A 7 2 8 9 1 3 5
A.sort(); A 1 2 3 5 7 8 9
A.rsort(); A 9 8 7 5 3 2 1
Futurewiz
www.futurewiz.co.in
Array Reduction Methods
Futurewiz
www.futurewiz.co.in
Associative Array
Futurewiz
www.futurewiz.co.in
Associative Array
int array1 [ * ];
int array2 [ int ];
//Array can be indexed by any integral expression.
class xyz; …
int array4 [ xyz ];
//Indices can be objects of xyz.
Futurewiz
www.futurewiz.co.in
Associative Array
int xyz [ * ];
5 7 2 1 3 9
0 1 2 3 7 10
xyz[0]=5; //Memory allocated during assignment
xyz[1]=7;
xyz[2]=2;
xyz[3]=1;
xyz[7]=3;
xyz[10]=9;
Futurewiz
www.futurewiz.co.in
Associative Array Methods
Futurewiz
www.futurewiz.co.in
Associative Array Methods
Futurewiz
www.futurewiz.co.in
Associative Array Methods
initial
begin
a.first(index); //index=Jan
$display(a[index]);
while(a.next(index)) //Go through all index
$display(a[index]);
end
Futurewiz
www.futurewiz.co.in
User Defined
uint8 a, b;
word c, d;
a=8’d10;
c=16’d25;
Futurewiz
www.futurewiz.co.in
Structures
Declaration :
Futurewiz
www.futurewiz.co.in
Structures
Initializing : Accessing :
Futurewiz
www.futurewiz.co.in
Packed Structures
Futurewiz
www.futurewiz.co.in
Packed Structures
Example :
typedef struct packed signed { shortint a; //16-bits [31:16]
byte b; //8-bits [15:8]
bit [7:0] c; //8-bits [7:0]
} exam_st;
exam_st pack1;
bit [7:0] a, b, c;
pack1=‘{a: ’1, b: -10, c: 8’b1001_0101};
a=pack1.b;
b=pack1.c;
c=pack1[9:2];
Futurewiz
www.futurewiz.co.in
Packed Structures
Only packed data type and integer data types are allowed
inside packed structures
Futurewiz
www.futurewiz.co.in
Unions
Example :
union union packed
{ real a; { real a;
int b; int b;
bit [7:0] c; } exam1; bit [7:0] c; }
exam2;
Futurewiz
www.futurewiz.co.in
Unions
Example :
typedef union
{ shortint a;
00 00 00 00
int b;
bit [7:0] c; } my_un;
my_un un1; 00 00 F0 F0
un1.a=16’hf0f0;
$displayh(un1.b);
00 00 F0 AA
un1.c=8’b1010_1010;
$displayh(un1.b);
Futurewiz
www.futurewiz.co.in
Structures vs Unions
Structure Union
Futurewiz
www.futurewiz.co.in
String
Futurewiz
www.futurewiz.co.in
String Operators
Futurewiz
www.futurewiz.co.in
String Operators
Example :
string s1=“hello”, s2=“Hello”, s3=“xyz”;
initial
begin
if(s1 != s2)
$display(“strings are different”);
if(s1 > s3)
$display(“s1 is more than s3”);
else
$display(“s3 is more than s1”);
$display({s1, s2, s3});
end
Futurewiz
www.futurewiz.co.in
String Methods
Futurewiz
www.futurewiz.co.in
String Methods
Futurewiz
www.futurewiz.co.in
String Methods
Futurewiz
www.futurewiz.co.in
String Methods
Example :
string s1, s2;
initial begin
s1 = "SystemVerilog";
$display(s1.getc(0)); //Display: 83 (‘S’)
$display(s1.toupper()); // Display: SYSTEMVERILOG
s1 = {s1, "3.1b"}; // "SystemVerilog3.1b"
s1.putc(s1.len()-1, "a"); // change b-> a
$display(s1.substr(2, 5)); // Display: stem
s2=$psprintf("%s %0d", s1, 5);
$display(s2); // Display: SystemVerilog3.1a 5
end
Futurewiz
www.futurewiz.co.in
Enumerated Type
Futurewiz
www.futurewiz.co.in
Enumerated Type
Example :
enum { RED, GREEN, BLUE } color;
//RED=0, GREEN=1, BLUE=2
Futurewiz
www.futurewiz.co.in
Enumerated Type Methods
Futurewiz
www.futurewiz.co.in
Enumerated Type Methods
Futurewiz
www.futurewiz.co.in
Enumerated Type Methods
Example
Futurewiz
www.futurewiz.co.in
Casting
Example :
int a;
initial a=int’(3.0 * 2.0);
Futurewiz
www.futurewiz.co.in
Casting
int a;
real b=3.0;
Futurewiz
www.futurewiz.co.in
Casting
Example :
int a=-10;
initial
begin
$display(a>>>1); // -5
$display(unsigned’(a)>>>1); // positive value
const’(a); // changing to constant
a=3; //Runtime error
end
Futurewiz
www.futurewiz.co.in
Casting
initial begin
col=green;
//col=3; Runtime error
a= blue * 2;
b= col + green;
end
Futurewiz
www.futurewiz.co.in
Casting
initial begin
$cast( col, 2 + 3 ); //col=black
Futurewiz
www.futurewiz.co.in
Example1
Futurewiz
www.futurewiz.co.in
Example2
Result:
int a, b, c, d; a=3 b=3 //Display
initial begin c=4
b=3; b= 4
if((a=b)) //brackets compulsory a=4
$display(“a=%d b=%d”, a, b);
(a=(b=(c=4))); if ((a=b)) is same as
end a=b;
if (a)
Futurewiz
www.futurewiz.co.in
Example3
a->b is same as !a || b
a<-> b is same as (!a || b) && (!b || a)
int a=1, b=2;
initial begin
Result:
if(a->b)
a implies b
$display(“a implies b”);
a is logically equivalent to b
if (a<-> b)
$display(“a is logically equivalent to
b”);
end
Futurewiz
www.futurewiz.co.in
Example4
Futurewiz
www.futurewiz.co.in
Loops
Futurewiz
www.futurewiz.co.in
Loops
inital begin
int i=10;
inital begin
do begin
int a [8] [5];
i -=1; //statements
foreach ( a [i, j] )
end
a[i] [j]=$random;
while (i >5)
end
end
Used to access all Statements executed first an
elements in an then execution depends upon
array condition
Futurewiz
www.futurewiz.co.in
Break and Continue
Futurewiz
www.futurewiz.co.in
package
Futurewiz
www.futurewiz.co.in
Example
“pack1.sv” “pack2.sv”
package mypack1; package mypack2;
int x; int y;
function int add (input int a, b ); function int add (input int a, b, c
add= a + b; );
endfunction add= a + b + c;
endfunction
endpackage
endpackage
Futurewiz
www.futurewiz.co.in
Example
`include “pack1.sv”
`include “pack2.sv”
module test;
import mypack1::*;
import mypack2::*;
initial begin
x=mypack1 :: add(3, 6); //x=9
y=mypack2 :: add(4, 5, 3); //y=12
end
endmodule
Futurewiz
www.futurewiz.co.in
unique and priority
Futurewiz
www.futurewiz.co.in
unique
Futurewiz
www.futurewiz.co.in
unique
always @ * Result:
unique case (sel) Inputs Outputs
2’b00: y=a; 00 : y=a;
2’b01: y=b; 01 : y=b; warning
2’b01: y=c; issued
2’b10: y=d; x1 : Latch; warning
2’b11: y=e; issued
endcase 11 : y=e;
Futurewiz
www.futurewiz.co.in
unique
always @*
casez (ip)
4’b1??? : y=2’b11; Synthesis Result:
4’b?1?? : y=2’b10; Priority Encoder
4’b??1? : y=2’b01;
4’b???1 : y=2’b00;
default: y=2’b00;
endcase
Futurewiz
www.futurewiz.co.in
unique
always @*
unique casez (ip)
4’b1??? : y=2’b11; Synthesis Result:
4’b?1?? : y=2’b10; Encoder
4’b??1? : y=2’b01;
4’b???1 : y=2’b00;
default: y=2’b00;
endcase
Futurewiz
www.futurewiz.co.in
priority
Futurewiz
www.futurewiz.co.in
priority
always @ *
priority case (sel) Result:
2’b00: y=a; Inputs Outputs
2’b01: y=b; 00 : y=a;
2’b01: y=c; 01 : y=b;
2’b10: y=d; x1 : Latch; warning
issued
2’b11: y=e;
11 : y=e;
endcase
Futurewiz
www.futurewiz.co.in
priority
Result:
always @ * Inputs Outputs
priority if (sel==2’b00) y=a; 00 : y=a;
else if (sel==2’b01) y=b; 01 : y=b;
else if (sel==2’b10) y=c; 10 : y=c;
else if (sel==2’b10) y=d; 11 : y=e;
else if (sel==2’b11) y=e; 1x : Latch; warning
issued
z1 : Latch; warning
issued
Futurewiz
www.futurewiz.co.in
Procedural Statements
All global variables have static lifetime i.e. they exist till
end of simulation. Global members can be explicitly
referred by $root.
Futurewiz
www.futurewiz.co.in
Example
int i;
//task increment task
module test; increment;
//task decrement i+= 1;
initial begin : label endtask
i=5;
task decrement;
#6 $root.i=3;
$root.i-=1;
#3 increment;
endtask
#4 decrement;
end : label
endmodule : test
Futurewiz
www.futurewiz.co.in
Scope and Lifetime
Futurewiz
www.futurewiz.co.in
Scope and Lifetime
Futurewiz
www.futurewiz.co.in
Example1
Futurewiz
www.futurewiz.co.in
Example3
initial begin
for (int i=0; i<3; i++) begin : l1
static int loop3 = 0; // executes once
for (int k=0; k<3; k++) begin : l2
loop3++;
$display(loop3); //loop3 stays till end of
end : l2 //simulation
end : l1
end
Result: 1 2 3 4 5 6 7 8 9
Futurewiz
www.futurewiz.co.in
Type Parameter
Futurewiz
www.futurewiz.co.in
Subprograms
Futurewiz
www.futurewiz.co.in
Function and Tasks
Futurewiz
www.futurewiz.co.in
Example1
initial begin
int y;
y=add(3, 5); //3+5+0
#3 y=add(); //0+0+0
#3 y=add(1, 2, 3); //1+2+3
#3 y=add(, 2, 1); //0+2+1
end
Futurewiz
www.futurewiz.co.in
Example2
initial begin
display(3, 5); //a=3 b=5
#3 display(); // a=0 b=0
#3 display(1); // a=1 b=0
#3 display( , 3); // a=0 b=3
end
Futurewiz
www.futurewiz.co.in
Example3
Futurewiz
www.futurewiz.co.in
Example4
Futurewiz
www.futurewiz.co.in
Example5
initial begin
#3 check(5, error); // error=0
#3 check(0, error); // error=1
end
Futurewiz
www.futurewiz.co.in
Example6
task add (int a=0, b=0, output int z); //Variables are static by
//default
#2 z=a + b;
endtask
int x, y; Result
:
initial fork x=6
add(3, 5, x); y=6
#1 add(2, 4, y);
join
Futurewiz
www.futurewiz.co.in
Example6
task add (int a=0, b=0, output int z); //Variables are static by
//default
#2 z=a + b;
endtask
int x, y; Result
:
initial begin x=8
add(3, 5, x); y=6
#1 add(2, 4, y);
end
Futurewiz
www.futurewiz.co.in
Example7
int x, y;
Result
initial fork :
add(3, 5 , x); x=8
#1 y=add(2, 4 , y); y=6
join
Futurewiz
www.futurewiz.co.in
System Verilog
CLASSES
Introduction
Futurewiz
www.futurewiz.co.in
Example1
class rectangle;
int lenght, width; //class properties
Futurewiz
www.futurewiz.co.in
Example2
class person;
string name, address; //class
properties
int number;
class packet;
bit [7:0] data; //class property
task display();
$display(“data is %d”, data);
endtask
endclass
Futurewiz
www.futurewiz.co.in
Objects
Futurewiz
www.futurewiz.co.in
Default Constructor
rectangle rec;
initial begin
rec=new; //memory allocated to length and width
int a, p;
rec.set_size(3, 5);
a=rec.area;
p=rec.perimeter; end
Futurewiz
www.futurewiz.co.in
Constructor
initial begin
p1=new(); p2=new(); p3=new(); p4=new();
p4.display;
p4.randomize;
p4.display;
end
Futurewiz
www.futurewiz.co.in
This
Futurewiz
www.futurewiz.co.in
Fundamental Principles of OOP
Encapsulation
o It’s a concept that binds together the data and functions
that manipulate the data.
o Encapsulation keeps both data and function safe from
outside world i.e. data hiding.
Abstraction
o Abstraction is the concept of moving the focus from the
details and concrete implementation of things, to the
types of things, the operations available thus making
the programming simpler, more general.
Futurewiz
www.futurewiz.co.in
Fundamental Principles of OOP
Inheritance
o New classes are created by inheriting properties and
method defined in an existing class.
o Existing class is called the base class(parent class),
and the new class is referred to as
the derived class(child class).
Polymorphism
o polymorphism means having many forms.
o A member function will cause a different function to be
executed depending on the type of object that invokes
the function. Futurewiz
www.futurewiz.co.in
Inheritance
Futurewiz
www.futurewiz.co.in
Example1
parent p;
parent p child c
child c;
a=2 ; a=7 ;
initial begin b=0; b=0;
p=new; c=0;
c=new;
c.display;
p.display; Child Class
Parent
c.a=7;
Class
p.a=2;
end
Futurewiz
www.futurewiz.co.in
Example3
parent p;
parent p child c
child c;
a=5 ; a=6 ;
initial begin b=0;
p=new;
c=new;
p.a=5; Parent
Class
c.a=6;
Child Class
p.display; Parent
c.display; Class
end 0
Futurewiz
www.futurewiz.co.in
Inheritance
Futurewiz
www.futurewiz.co.in
Example4
Futurewiz
www.futurewiz.co.in
Example5
Futurewiz
www.futurewiz.co.in
Example6
Futurewiz
www.futurewiz.co.in
Example8
endclass end
Futurewiz
www.futurewiz.co.in
Example2
Futurewiz
www.futurewiz.co.in
Example3
endclass
Now length and width are accessible to both rectangle and
square Futurewiz
www.futurewiz.co.in
Lifetime in Class
Futurewiz
www.futurewiz.co.in
Lifetime in Class
Futurewiz
www.futurewiz.co.in
Example1
Result :
p1.id= 1 p1.val=1
p2.id= 2 p2.val=1
p3.id= 3 p3.val=1
p1.id= 7 p1.val=1
p2.id= 7 p2.val=3
packet :: 7
Futurewiz
www.futurewiz.co.in
Example2
initial begin
class packet;
static int id; packet:: id=3;
$display(packet::id);
int val; //default: automatic
packet p1;
function new(); p1=new;
id=id+1; $display(packet::id);
val=val+1; end
endfunction
Result
endclass id=3; id=4;
Futurewiz
www.futurewiz.co.in
Functions and Tasks
Futurewiz
www.futurewiz.co.in
Example1
class test;
initial begin
task increment; test t1;
Result
int i; t1=new; :
i++; t1.increment; i=1
$display(“i=%d”, i); t1.increment; i=1
endtask t1.increment; i=1
end
endclass
Futurewiz
www.futurewiz.co.in
Example2
class test;
initial begin
task increment;
test t1;
static int x; Result:
t1=new;
int y; x=1 y=1
t1.increment;
x++; y++; x=2 y=1
t1.increment;
$display(“x=%d y=%d”, x, x=3 y=1
y); t1.increment;
endtask end
endclass
Futurewiz
www.futurewiz.co.in
Example3
class test;
endclass
Futurewiz
www.futurewiz.co.in
Example4
class test;
initial begin
task static increment;
test t1; Result:
int x;
t1=new; x=1 y=1
automatic int y;
t1.increment; x=2 y=1
x++; y++;
t1.increment; x=3 y=1
$display(“x=%d y=%d”, x,
y); t1.increment;
endtask end
endclass
Futurewiz
www.futurewiz.co.in
Example5
Futurewiz
www.futurewiz.co.in
Functions and Tasks
Futurewiz
www.futurewiz.co.in
Example1
class test;
int i;
initial begin
local function void increment; test t1;
i++; $display(“i=%0d”, i); t1=new; Result
endtask t1.inc; :
t1.inc; i=1
function void inc;
//t1.increment; will give
increment; i=2
//compilation error
endfunction
end
endclass
Futurewiz
www.futurewiz.co.in
Example2
class test;
initial begin
static function int add(int x, $display(test::add(3,2));
y); $display(test::add(1,1));
int i; end
i++;
$display(“i=%0d”, i); Result:
return x + y; 5 i=1
endfunction 2 i=1
endclass
Futurewiz
www.futurewiz.co.in
Example3
class test;
initial begin
int i;
$display(test::add(3,2));
static function int add(int x, $display(test::add(1,1));
y); end
i++;
$display(“i=%0d”, i);
return x + y; Result :
endfunction Error, Static function cannot access
non-static class properties
endclass
Futurewiz
www.futurewiz.co.in
Example4
class test;
initial begin
static int i;
$display(test::add(3,2));
static function int add(int x, $display(test::add(1,1));
y); end
i++;
$display(“i=%0d”, i); Result:
return x + y; 5 i=1
endfunction 2 i=2
endclass
Futurewiz
www.futurewiz.co.in
Polymorphism
endclass
Futurewiz
www.futurewiz.co.in
Example1
Futurewiz
www.futurewiz.co.in
Example1
Futurewiz
www.futurewiz.co.in
Example1
Futurewiz
www.futurewiz.co.in
Example1
Result :
I am shape I don’t know
perimeter
I am rectangle Perimeter= 10
I am triangle Perimeter= 6
I am triangle Perimeter= 6
I am square Perimeter= 16
I am rectangle Perimeter= 10
Futurewiz
www.futurewiz.co.in
Example2
initial begin
parent p1; child c1;
c1=new;
$cast(p1, c1); // checks run-time casting errors
//p1=c1; //checks compile time casting errors
//properties and virtual methods in parent class
//points to one defined in child class
p1.d1; p1.d2;
$display(“p1.a=%0d”, p1.a); c1.a=9;
$display(“p1.a=%0d”, p1.a);
end
Futurewiz
www.futurewiz.co.in
Example2
initial begin
parent p1; child c1;
c1=new;
p1=c1; //Polymorphism occurs
//c1=p2; will give compilation error
p1.d1; p1.d2;
$display(“p1.a=%0d”, p1.a); c1.a=9;
$display(“p1.a=%0d”, p1.a);
end
Futurewiz
www.futurewiz.co.in
Example3
Futurewiz
www.futurewiz.co.in
Example1
endclass Futurewiz
www.futurewiz.co.in
Example1
Futurewiz
www.futurewiz.co.in
Example1
Futurewiz
www.futurewiz.co.in
Example2
endclass
Futurewiz
www.futurewiz.co.in
Example2
endclass
Futurewiz
www.futurewiz.co.in
Nested Class
class timestat;
time start_time,
end_time;
class packet;
int data[7:0];
task packet :: transmit();
timestat t;
t.start;
function new; //do some operation
t=new; t.end;
endfunction endtask
endclass
Futurewiz
www.futurewiz.co.in
Typedef Class
Futurewiz
www.futurewiz.co.in
Example
module test;
class packet;
timestat t; Compilation error class
//definitions timestat is not defined.
endclass
Futurewiz
www.futurewiz.co.in
Example
module test;
typedef class timestat;
class packet;
timestat t; typedef allows compiler
//definitions to process packet class
endclass before timestat class.
class timestat;
//definitions
enclass
endmodule
Futurewiz
www.futurewiz.co.in
Copy
Futurewiz
www.futurewiz.co.in
Shallow Copy
Futurewiz
www.futurewiz.co.in
Shallow Copy
Futurewiz
www.futurewiz.co.in
Example
class pkt;
bit addr [15:0];
class timestat;
bit [7:0] data;
time start_time, int id; static int count;
end_time;
timestat t;
endclass
function new();
id=count++;
t=new;
endfunction
endclass
Futurewiz
www.futurewiz.co.in
Example
dst.t.start_time=14; t
//modifies t since start_time=14 ;
// handler is common
end
Futurewiz
www.futurewiz.co.in
Deep Copy
Futurewiz
www.futurewiz.co.in
Example
class pkt;
bit addr [15:0];
bit [7:0] data;
int id; static int count; function pkt pkt :: copy;
copy=new;
timestat t; copy.addr=this.addr;
copy.data=this.data;
function new(); copy.t.start_time=this.t.start_ti
id=count++; me;
t=new; copy.t.end_time=this.t.end_tim
endfunction e;
extern function pkt copy; endfunction
endclass
Futurewiz
www.futurewiz.co.in
Example
Futurewiz
www.futurewiz.co.in
Interface Class
Futurewiz
www.futurewiz.co.in
Interface Class
Futurewiz
www.futurewiz.co.in
Interface Class
endclass
Futurewiz
www.futurewiz.co.in
Singleton Class
Process using semaphore must first procure a key from bucket before
they can continue to execute.
Futurewiz
www.futurewiz.co.in
Semaphore - Methods
Futurewiz
www.futurewiz.co.in
Semaphore - Methods
semaphore smp;
int got=0;
initial
initial begin begin
smp=new(5); #8 smp.get(2);
#5 smp.get(3); #7 smp.put(2);
#6 smp.get(1); got=got +1; end
#2 if(smp.try_get(3)) got=got +1; got=1 at 15
end
Futurewiz
www.futurewiz.co.in
Example
Futurewiz
www.futurewiz.co.in
Mailbox - Methods
If the type of the message variable is not equivalent to the type of the
message in the mailbox, a run-time error is generated.
Futurewiz
www.futurewiz.co.in
Parameterized Mailboxes
Futurewiz
www.futurewiz.co.in
Example
module test;
mailbox mb; //typeless Mailbox
string s; int i;
initial begin
mb=new(); //Unbound Mailbox
$monitor(“s=%s and i=%0d at time=%0d”, s, i, $time);
fork gen_data;
rec_data;
join end
endmodule
Futurewiz
www.futurewiz.co.in
Example
task rec_data;
task gen_data;
#1 mb.peek(s);
mb.put(“Hello”);
#2 mb.get(s);
#3 mb.put(7);
#2 mb.get(i);
#4 mb.put(“Test”);
#1 mb.peek(s);
#3 mb.put(3);
#2 void’(mb.try_get(s));
#3 mb.put(“Hi”);
#1 void’(mb.try_get(i));
#2 mb.put(9);
#4 mb.get(s);
endtask
#2 mb.get(i);
endtask
Futurewiz
www.futurewiz.co.in
Example
Result:
# s= and i=0 at time=0
# s=Hello and i=0 at time=1
# s=Hello and i=7 at time=5
# s=Test and i=7 at time=7
# s=Test and i=3 at time=16
Futurewiz
www.futurewiz.co.in
Example
module test;
mailbox #(int) mb; //Parameterized Mailbox
int i;
initial begin
mb=new(3); //bound mailbox
$monitor(“i=%0d at %0d”, i ,$time);
fork gen_data;
rec_data;
join end
endmodule
Futurewiz
www.futurewiz.co.in
Example
Result:
# i=0 at time=0
# i=1 at time=1
# i=7 at time=8
# i=4 at time=10
# i=3 at time=11
# i=2 at time=13
# i=5 at time=18
Futurewiz
www.futurewiz.co.in
System Verilog
RANDOMIZATION
Why Randomize?
Futurewiz
www.futurewiz.co.in
Comparison
Futurewiz
www.futurewiz.co.in
What to Randomize?
Device configuration
Environment configuration
Primary input data
Encapsulated input data
Protocol exceptions
Errors and violations
Delays
Test order
Seed for the random test
Futurewiz
www.futurewiz.co.in
Verilog Constrained Randomization
Futurewiz
www.futurewiz.co.in
Random in range
module test;
integer a, b, c;
initial
repeat(20) begin
a=$random % 10; //-9 to 9 (Random range)
b={$random} % 20; //0 to 19 (Random range)
c=$unsigned($random)%15; //0 to 14 (Random
range)
#2; end
endmodule
Futurewiz
www.futurewiz.co.in
Random in range
module test;
integer a, b, c;
initial
repeat(20) begin
a=10 + {$random} % 6; //10 to 15 (positive range)
b=-5 - {$random} % 6; //-5 to -10 (negative range)
c =-5 + {$random} % 16; //-5 to 10 (mix range)
#2; end
endmodule
Futurewiz
www.futurewiz.co.in
Algorithms
Positive Range:
result= min + {$random} % (max – min + 1);
Negative Range:
result= -min - {$random} % (max – min + 1);
Mix Range:
result= -min + {$random} % (max + min + 1);
//min is the magnitude of minimum number
//max is the magnitude of maximum number
Futurewiz
www.futurewiz.co.in
Random between ranges
module test;
integer a;
initial
repeat(20)
if ({$random} % 2)
#2 a=10 + {$random} % 6; //10 to 15
else
#2 a= 3 + {$random} % 5; // 3 to 7
endmodule
Futurewiz
www.futurewiz.co.in
Weighted Random numbers
module test;
integer a, count=0;
initial repeat(20)
if (count<3)
#2 a=1 + {$random} % 9; //1 to 9
else
#2 a=11 + {$random} % 8; // 11 to 18 Higher weight
endmodule
Futurewiz
www.futurewiz.co.in
Real random numbers
module test;
reg sign; reg [7:0] exp;
reg [22:0] mantisa; real a;
while(index!=10) begin
Generate 10 unique
random numbers temp=$random;
begin: loop
integer rec [0:9]; for(i=0; i<index; i=i+1)
integer i, temp, num, index=0; if(rec[i]==temp)
disable loop;
initial begin rec[index]=temp;
$monitor(“num=%0d”, num); index=index + 1; num=temp;
#2; end
end end
Futurewiz
www.futurewiz.co.in
Result
# num=303379748
# num=-1064739199
# num=-2071669239
# num=-1309649309
# num=112818957
# num=1189058957
# num=-1295874971
# num=-1992863214
# num=15983361
# num=114806029
Futurewiz
www.futurewiz.co.in
Unique random numbers
while(index!=10) begin
Generate 10 unique
random numbers between temp={$random} % 100;
0 to 99 begin: loop
integer rec [0:9]; for(i=0; i<index; i=i+1)
integer i, temp, rand, index=0; if(rec[i]==temp)
disable loop;
rec[index]=temp;
index=index + 1; rand=temp;
#2; end
end
Futurewiz
www.futurewiz.co.in
Result
# num=48
# num=97
# num=57
# num=87
# num=57
# num=25
# num=82
# num=61
# num=29
Futurewiz
www.futurewiz.co.in
Other types
Futurewiz
www.futurewiz.co.in
$dist_uniform
module test;
integer num1, num2, seed;
initial
repeat(20) begin
num1=$dist_uniform (seed, 5, 15); //5 to 15
num2=$dist_uniform (seed, -5, 10); //-5 to
10
#2; end
endmodule
Futurewiz
www.futurewiz.co.in
SV Constrained Randomization
Futurewiz
www.futurewiz.co.in
$urandom
module test;
integer num1, num2, seed;
initial
repeat(20) begin
#2 num1=$urandom (seed); //Unsigned 32-bit
//Random Number
num2=$urandom;
end
endmodule
Futurewiz
www.futurewiz.co.in
$urandom_range
module test;
integer num1, num2 , num3;
initial
repeat(20) begin
#2 num1=$urandom_range(35, 20); //35:max to 20:min
num2=$urandom_range(9); //9:max to 0:min
num3=$urandom_range(10,15); //10:min to 15:max
end
endmodule
Futurewiz
www.futurewiz.co.in
Result
Futurewiz
www.futurewiz.co.in
Randomize function
module test;
integer num1, num2;
initial
repeat(20) begin
if(randomize(num1, num2)) //Randomize num1 and
num2
$display(“Randomization Successful”);
else $display(“Randomization Failed”);
#2 ; end
endmodule
Futurewiz
www.futurewiz.co.in
Randomize function with constraint
module test;
integer num;
initial
repeat(20) begin
if(randomize(num) with {num>10; num<20;} )
$display(“Randomization Successful”);
//num should be between 10 and 20 Inline
Constraint
#2 ; end
endmodule
Futurewiz
www.futurewiz.co.in
Result
# num=19
# num=15
# num=11
# num=13
# num=15
# num=14
# num=16
# num=15
# num=17
# num=15
# num=11
# num=15
Futurewiz
www.futurewiz.co.in
Randomize Object Properties
Futurewiz
www.futurewiz.co.in
Example1
Futurewiz
www.futurewiz.co.in
Result
# num1=-1884196597 num2=0
# num1=-326718039 num2=0
# num1=1452745934 num2=0
# num1=-2130312236 num2=0
# num1=1572468983 num2=0
# num1=131041957 num2=0
# num1=1115460554 num2=0
# num1=-818992270 num2=0
# num1=2000525113 num2=0
# num1=1547354947 num2=0
# num1=1196942489 num2=0
# num1=736230661 num2=0
Futurewiz
www.futurewiz.co.in
Example2
program test;
class sample; sample sm;
typedef struct { randc int a; initial begin
bit [3:0] b; sm=new;
} st_t; repeat(20)
rand st_t st; assert(sm.randomize()
//rand is must to randomize )
//int present inside structure $display(sm.st.a);
endclass end
endprogram
Futurewiz
www.futurewiz.co.in
Example4
Futurewiz
www.futurewiz.co.in
Result
# 14 # 0
# 4 # 0
# 9 # 0
# 6 # 0
# 5 # 0
# 15 # 0
# 4 # 0
# 13 # 0
# 1 # 0
# 8 # 0
# 9 # 0
# 14 # 0
Futurewiz
www.futurewiz.co.in
Specifying Constraints
class sample1;
rand int num;
class sample3;
constraint c { num>10;
randc int num;
num<100; }
int Max, Min;
endclass
constraint c1 { num>Min; }
class sample2; constraint c2 { num<Max; }
randc bit [7:0] num; endclass
constraint c1 { num>10; }
constraint c2 { num<100; }
endclass
Futurewiz
www.futurewiz.co.in
Example1
# 22 # 72
# 22 # 53
# 29 # 66
# 27 # 79
# 46 # 68
# 43 # 69
# 33 # 78
# 43 # 95
# 46 # 65
# 36 # 34
Futurewiz
www.futurewiz.co.in
Example2
# Randomization Fails
# Randomization Fails
# Randomization Fails
# Randomization Fails
# Randomization Fails
# Randomization Fails
# Randomization Fails
# Randomization Fails
# Randomization Fails
# Randomization Fails
Futurewiz
www.futurewiz.co.in
pre_randomize and post_randomize
Futurewiz
www.futurewiz.co.in
Example1
# Pre-Randomize
# Post-Randomize # 33
# Pre-Randomize
# Post-Randomize # 25
# Pre-Randomize
# Post-Randomize # 202
# Pre-Randomize
# Post-Randomize # 138
# Pre-Randomize
# Post-Randomize # 15
Futurewiz
www.futurewiz.co.in
Example2
endclass
Futurewiz
www.futurewiz.co.in
Example2
program test;
Result
B b1; # B: Pre-
Randomize
initial begin # B: Post-
b1=new; Randomize
# B: Pre-
repeat(2)
Randomize
void'(b1.randomize); # B: Post-
end Randomize
endprogram
Pre-Randomize and Post-
Randomize of parent class are
overridden Futurewiz
www.futurewiz.co.in
Controlling Randomization
When used as a task, the argument determines the state of rand and
randc variables.
Futurewiz
www.futurewiz.co.in
Controlling Randomization
Futurewiz
www.futurewiz.co.in
Example1
# 33
# 25
# 202
# 138
# 138
# 138
# 138
Futurewiz
www.futurewiz.co.in
Example2
class packet;
if(pkt.rand_mode()) //Check current Status
rand bit [7:0] data1;
$display(“Randomization on”);
rand int data2;
else $display(“Randomization off”);
endclass
end
pkt.rand_mode(0);
program test; void'(pkt.randomize);
packet pkt; if(pkt.rand_mode())
initial begin $display(“Randomization on”);
pkt=new; else $display(“Randomization off”); end
repeat(10) begin endprogram
void'(pkt.randomize);
Futurewiz
www.futurewiz.co.in
Example3
Futurewiz
www.futurewiz.co.in
Result
# 238 94
# 85 48
# 202 -92
# 29 38
# 155 48
# 225 -91
# 81 -66
# 232 -82
# 85 -112
# 141 -34
# 244 -34
# 32 -34
# 9 -34 Futurewiz
www.futurewiz.co.in
Example4
Futurewiz
www.futurewiz.co.in
Result
# 238 0
# 85 0
# 202 0
# 29 0
# 155 0
# 225 0
# 141 75
# 141 115
# 141 -24
# 141 111
# 141 -119
Futurewiz
www.futurewiz.co.in
Example5
class packet;
rand int data;
int Max, Min;
constraint c1{ data> Min; data<Max; }
constraint c2 { Max> Min; }
task set(int Min, Max);
this.Min=Min;
this.Max=Max;
endtask
endclass
Futurewiz
www.futurewiz.co.in
Example5
initial begin
packet p1=new;
p1.set(5, 25);
repeat(5) if(p1.randomize)
$display(“Random value=%0d”, p1.data);
p1.set(35, 20);
repeat(5) if(p1.randomize)
$display(“Random value=%0d”, p1.data);
else $display(“Randomization Failed”);
end
Futurewiz
www.futurewiz.co.in
Result
# Random value=14
# Random value=18
# Random value=15
# Random value=16
# Random value=16
# Randomization Failed
# Randomization Failed
# Randomization Failed
# Randomization Failed
# Randomization Failed
Futurewiz
www.futurewiz.co.in
Random Stability
Futurewiz
www.futurewiz.co.in
Result
# a1.data=12
# a1.data=7
# a1.data=15
# a1.data=6
# a1.data=9
# a2.data=13
# a2.data=13
# a2.data=6
# a2.data=2
# a2.data=15
Futurewiz
www.futurewiz.co.in
Random Stability
# a2.data=13
# a2.data=13
# a2.data=6
# a2.data=2
# a2.data=15
# a1.data=12
# a1.data=7
# a1.data=15
# a1.data=6
# a1.data=9
Futurewiz
www.futurewiz.co.in
Random Stability
initial begin
module test;
class A; a1=new(3); a2=new(3);
repeat(5)
rand bit [3:0] data;
if(a1.randomize)
function new(int seed);
$display("a1.data=%0d",a1.data);
srandom(seed);
//set a particular seed repeat(5)
if(a2.randomize)
endfunction
$display("a2.data=%0d",a2.data);
endclass
end
A a1, a2; endmodule
Futurewiz
www.futurewiz.co.in
Result
# a1.data=5
# a1.data=7
# a1.data=12
# a1.data=13
# a1.data=5
# a2.data=5
# a2.data=7
# a2.data=12
# a2.data=13
# a2.data=5
Futurewiz
www.futurewiz.co.in
Relation in Constraints
Futurewiz
www.futurewiz.co.in
Relation in Constraints
class packet;
rand int length, data, address;
constraint len { length==address * 5};
endclass
Futurewiz
www.futurewiz.co.in
Set Membership
class packet;
rand int address;
constraint limit {address inside { [1:5], [7:11], 15, 18, 25
};}
endclass
Futurewiz
www.futurewiz.co.in
Set Membership
Futurewiz
www.futurewiz.co.in
Set Membership
class packet;
rand int data;
constraint limit { ( (data==5) || (data==7) || (data==9) );}
endclass
There is a better way of providing such
constraints:
class packet;
rand int data;
constraint limit { data inside { 5, 7, 9}; }
endclass
Futurewiz
www.futurewiz.co.in
Weighted Distribution
class packet;
rand int data;
constraint con { data dist { 0:=40, [1:4] :=60, [6:7]:=20 }; }
endclass
//Total weight= 40 + 60 + 60 + 60 + 60 + 20 + 20=320
data=3 weight=60/320=18.75%
data=0 weight=40/320=12.5%
data=4 weight=60/320=18.75%
data=1 weight=60/320=18.75%
data=6 weight=20/320=6.25%
data=2 weight=60/320=18.75%
data=7 weight=20/320=6.25%
Futurewiz
www.futurewiz.co.in
Example2
class packet;
rand int data;
constraint con { data dist { 0:/20, [1:3] :/60, [6:7]:/20 }; }
endclass
//Total weight= 20 + 60 + 20=100
Futurewiz
www.futurewiz.co.in
Example3
Futurewiz
www.futurewiz.co.in
Bidirectional Constraints
Is equivalent to
constraint mode_c { (mode == small) -> len < 10;
(mode == large) -> len > 100; }
If mode is small that implies length should be less than 10.
If mode is large that implies length should be more than 100.
Implication helps in creating case like blocks.
Futurewiz
www.futurewiz.co.in
Efficient Constraints
Probabilit
Solution x y
y
class Unconstrained; S1 0 0 1/8
rand bit x;
S2 0 1 1/8
// 0 or 1
S3 0 2 1/8
rand bit [1:0] y;
S4 0 3 1/8
// 0, 1, 2, or 3
endclass S5 1 0 1/8
S6 1 1 1/8
S7 1 2 1/8
S8 1 3 1/8
Futurewiz
www.futurewiz.co.in
Solution Probabilities
Probabilit
class Implication1; Solution x y
y
rand bit x; S1 0 0 1/2
// 0 or 1 S2 0 1 0
rand bit [1:0] y; S3 0 2 0
// 0, 1, 2, or 3 S4 0 3 0
constraint c {
S5 1 0 1/8
(x==0) -> (y==0); }
S6 1 1 1/8
endclass
S7 1 2 1/8
S8 1 3 1/8
Futurewiz
www.futurewiz.co.in
Solution Probabilities
Probabilit
class Implication2; Solution x y
y
rand bit x; S1 0 0 0
// 0 or 1 S2 0 1 0
rand bit [1:0] y; S3 0 2 0
// 0, 1, 2, or 3 S4 0 3 0
constraint c {
S5 1 0 0
y>0;
S6 1 1 1/3
(x==0) -> (y==0); }
endclass S7 1 2 1/3
S8 1 3 1/3
Futurewiz
www.futurewiz.co.in
Solve before
Futurewiz
www.futurewiz.co.in
Controlling Constraints
When used with just handle, it controls all constraints for an object.
Futurewiz
www.futurewiz.co.in
Example
class Packet;
rand int length;
constraint c_short { length inside { [1:32] }; }
constraint c_long { length inside { [1000:1023]};
}
endclass
Futurewiz
www.futurewiz.co.in
Example
Packet p;
initial begin
p = new;
// Create a long packet by disabling short constraint
p.c_short.constraint_mode(0);
assert (p.randomize());
// Create a short packet by disabling all constraints
// then enabling only the short constraint
p.constraint_mode(0);
p.c_short.constraint_mode(1);
assert (p.randomize());
end
Futurewiz
www.futurewiz.co.in
Inline Constraints
Futurewiz
www.futurewiz.co.in
Inline Constraints
Transaction t;
initial begin
t = new(); // addr is 50-100, 1000-1500, data < 10
repeat(5)
assert(t.randomize() with { addr >= 50;
addr <= 1500;
data < 10;} );
Futurewiz
www.futurewiz.co.in
Example2
Futurewiz
www.futurewiz.co.in
Example3
Futurewiz
www.futurewiz.co.in
Example 4
Futurewiz
www.futurewiz.co.in
Constraint in Inheritance
Futurewiz
www.futurewiz.co.in
Example1
module rand_sequence1();
initial begin
repeat(5) begin
randsequence( main ) //main is production
main : one two three ; //main contains one production list
one : {$write("one");}; //one two three are production items
two : {$write("two");};
three: {$display("three");};
endsequence
end
end
endmodule : rand_sequence1
Futurewiz
www.futurewiz.co.in
Result
Futurewiz
www.futurewiz.co.in
Example2
module rand_sequence2();
initial begin
repeat(7) begin
randsequence( main ) //main contains three production list
main : one| two | three ; //one two three are production list
one : {$display("one"); }; //one list will be chosen randomly
two : {$display("two"); };
three: {$display("three"); };
endsequence
end
end
endmodule : rand_sequence2
Futurewiz
www.futurewiz.co.in
Result
# one
# one
# one
# one
# three
# one
# two
Futurewiz
www.futurewiz.co.in
Example3
module rand_sequence3();
initial begin
repeat(50) begin
randsequence( main )
main : one:=5 | two:=2 | three:=3 ; //production list with
weights
one : {$display("one");};
two : {$display("two");};
three: {$display("three");};
endsequence
end
end
endmodule : rand_sequence3 Futurewiz
www.futurewiz.co.in
Example4
module rand_sequence4();
int one_1, two_2, three_3; bit on;
initial begin
repeat(100) begin
randsequence( main )
main : one three;
one : if(on) incr_one else incr_two;
incr_one : {one_1 ++; on=~on;};
incr_two : {two_2 ++; };
three: {three_3++;};
endsequence end end
endmodule : rand_sequence4
Futurewiz
www.futurewiz.co.in
Example5
module rand_sequence5();
initial for (int i = 0 ; i < 10 ; i++)
randsequence( main )
main : case(i %3)
0 : zero;
1, 2 : non_zero;
default : def;
endcase
zero : {$display("zero");};
non_zero : {$display("non_zero");};
def : {$display("default");};
endsequence
endmodule : rand_sequence5
Futurewiz
www.futurewiz.co.in
System Verilog
PROGRAM BLOCK & INTERFACE
Program Block
Verilog module works well for design but when used for
Test benches may lead to race-around condition between
design and Test bench.
Futurewiz
www.futurewiz.co.in
Program Block
Preponed Active
Re-Active
Program Block
To Next Time
Slot Re-Inactive Runs Here
Postponed Re-NBA
Futurewiz
www.futurewiz.co.in
Example1
module tb;
reg clk=0, t=1;
module tff (q, clk, t);
wire q=0;
input clk, t;
output reg q=0; always #5 clk=~clk;
endmodule
Futurewiz
www.futurewiz.co.in
Example1
Result:
5 q= 0
15 q= 1
25 q= 0
35 q= 1
45 q= 0
55 q= 1
Futurewiz
www.futurewiz.co.in
Example2
endprogram
Futurewiz
www.futurewiz.co.in
Example2
module top;
reg clk=0, t;
wire q;
always #5 clk=~clk;
endmodule
Futurewiz
www.futurewiz.co.in
Example2
Result:
5 q= 1
15 q= 0
25 q= 1
35 q= 0
45 q= 1
55 q= 0
Futurewiz
www.futurewiz.co.in
Example3
program tb;
int a;
initial $monitor(“result is %d”,
Result : result is 2
a);
a=5
initial begin
#3 a= a + 2; $monitor does not execute
#4 a= a + 3; for a=5 because of implicit
end $exit
endprogram
Futurewiz
www.futurewiz.co.in
Example4
program tb;
int a;
initial $monitor(“result is %d”, a);
initial begin
#3 a= a + 2;
Result :
#4 a= a + 3;
result is 2
#1 ;
result is 5
end
endprogram
Futurewiz
www.futurewiz.co.in
Interface
Futurewiz
www.futurewiz.co.in
Design
endmodule
Futurewiz
www.futurewiz.co.in
Test Bench
initial
begin
$monitor (“a=%0d b=%0d sum=%0d”, a, b, sum);
forever begin a=$random; b=$random; #10; end
end
endprogram
Futurewiz
www.futurewiz.co.in
Top Level
logic [3:0] a, b;
logic [4:0] sum;
endinterface : inf
Futurewiz
www.futurewiz.co.in
Design
always @ (posedge
inf.clk)
inf.sum= inf.a + inf.b;
endmodule : adder
Futurewiz
www.futurewiz.co.in
Test Bench
initial begin
$monitor (“a=%0d b=%0d sum=%0d”, inf.a, inf.b,
inf.sum);
forever begin
inf.a=$random;
inf.b=$random;
#10; end
end
endprogram : tb
Futurewiz
www.futurewiz.co.in
Top Level
always #5 clk=~clk;
endmodule
Futurewiz
www.futurewiz.co.in
Modport
logic [3:0] a, b;
logic [4:0] sum;
//incase of inout port use wire
modport DUT (input clk, a, b, output sum);
modport TB (input clk, sum, output a, b);
endinterface : intf
Futurewiz
www.futurewiz.co.in
Design
endmodule : adder
Futurewiz
www.futurewiz.co.in
Test Bench
initial begin
$monitor (“a=%0d b=%0d sum=%0d”, inf.a, inf.b,
inf.sum);
forever begin
inf.a=$random;
inf.b=$random;
#10; end
end
endprogram : tb
Futurewiz
www.futurewiz.co.in
Top Level
always #5
clk=~clk;
intf i0 (.*);
adder a0 (.*);
tb t0 (.*);
endmodule
Futurewiz
www.futurewiz.co.in
Clocking Block
Futurewiz
www.futurewiz.co.in
Clocking Block
Clk
en
Output of Test Bench
en
Clk
count 1 2 3 4 5 6 7
count 0 1 2 3 4 5 6
Futurewiz
www.futurewiz.co.in
Clocking Block
………………………
clocking cb @ (posedge clk); //specifying active clock edge
default input #3ns output #2ns;
//Specifying user default for sampling and driving
Futurewiz
www.futurewiz.co.in
Clocking Block
………………………
clocking cb @ (posedge clk); //specifying active clock edge
default input #3ns output #2ns;
//Specifying user default for sampling and driving
Futurewiz
www.futurewiz.co.in
Interface
Futurewiz
www.futurewiz.co.in
Design
endmodule : counter
Futurewiz
www.futurewiz.co.in
Test Bench
initial begin
@inf.cb; //continue on active edge in cb
#3 inf.cb.en<=1; // use NBA for signals in cb
##8 inf.cb.en<=0; //wait for 8 active edges in cb
repeat(2) @inf.cb; //wait for 2 active edges in cb
inf.cb.en<=1;
wait (inf.cb.count==3) inf.cb.en<=0; //wait for count to become 3
end
endprogram : tb
Futurewiz
www.futurewiz.co.in
Parameterized Interface
endinterface
Futurewiz
www.futurewiz.co.in
Virtual Interface
Futurewiz
www.futurewiz.co.in
Virtual Interface
Futurewiz
www.futurewiz.co.in
Virtual Interface
module top;
class test;
bit clk=0;
virtual intf t1 ;
always #5 clk=~clk;
function new(virtual intf t2); intf inf(clk);
t1=t2; //initializing virtual initial begin
//interface test c1= new(inf);
endfunction fork
//task gen_req; c1.gen_req;
//task rec_gnt; c1.rec_gnt;
join end
endclass endmodule
Futurewiz
www.futurewiz.co.in
System Verilog
PROCESSES
final block
Result :
Before Fork
#3 occurs at 3
#5 occurs at 5
#6 occurs at 6
#8 occurs at 8
Out of Fork at 8
Futurewiz
www.futurewiz.co.in
fork – join_any
Result :
Before Fork
#3 occurs at 3
Out of Fork at 3
#5 occurs at 5
#6 occurs at 6
#8 occurs at 8
Futurewiz
www.futurewiz.co.in
fork – join_none
Result :
Before Fork
Out of Fork at 0
#3 occurs at 3
#5 occurs at 5
#6 occurs at 6
#8 occurs at 8
Futurewiz
www.futurewiz.co.in
wait fork
program test;
initial begin $display(“Before Fork”);
fork
begin #3 $display(“#3 occurs at %0d”, $time); end
begin #6 $display(“#6 occurs at %0d”, $time); end
begin #8 $display(“#8 occurs at %0d”, $time); end
begin #5 $display(“#5 occurs at %0d”, $time); end
join_none
$display(“Out of Fork at %0d”, $time); end
endprogram
program block exits simulation once it reaches end of initial
block
Futurewiz
www.futurewiz.co.in
wait fork
Result :
Before Fork
Out of Fork at 0
Futurewiz
www.futurewiz.co.in
wait fork
program test;
initial begin $display(“Before Fork”);
fork
begin #3 $display(“#3 occurs at %0d”, $time); end
begin #6 $display(“#6 occurs at %0d”, $time); end
begin #8 $display(“#8 occurs at %0d”, $time); end
begin #5 $display(“#5 occurs at %0d”, $time); end
join_none
$display(“Out of Fork at %0d”, $time);
wait fork; end
endprogram
Result :
Before Fork
Out of Fork at 0
#3 occurs at 3
#5 occurs at 5
#6 occurs at 6
#8 occurs at 8
Futurewiz
www.futurewiz.co.in
disable fork
module test;
initial begin $display(“Before Fork”);
fork
begin #3 $display(“#3 occurs at %0d”, $time); end
begin #6 $display(“#6 occurs at %0d”, $time); end
begin #8 $display(“#8 occurs at %0d”, $time); end
begin #5 $display(“#5 occurs at %0d”, $time); end
join_any
$display(“Out of Fork at %0d”, $time);
disable fork; end
endmodule
Disable fork kills all forked processes
Futurewiz
www.futurewiz.co.in
disable fork
Result :
Before Fork
#3 occurs at 3
Out of Fork at 3
Futurewiz
www.futurewiz.co.in
Conditional Event Control
sequence abc;
@ (posedge clk) a ##1 b ##1 c;
endsequence
always @(abc)
$display(“event occurred on a, b and c in order”);
Futurewiz
www.futurewiz.co.in
Named Events
Futurewiz
www.futurewiz.co.in
Example1
initial
begin
-> myevent; //Triggering event Result :
#3 -> myevent; count=2
end
Futurewiz
www.futurewiz.co.in
Example2
Futurewiz
www.futurewiz.co.in
Example4
Futurewiz
www.futurewiz.co.in
Example5
initial
fork
->myevent; //Triggering event
@(myevent) //waiting for event
count+=1;
join
count value depends upon which statement is executed
first result varies from simulator to simulator.
Futurewiz
www.futurewiz.co.in
Example6
Futurewiz
www.futurewiz.co.in
Example7
Futurewiz
www.futurewiz.co.in
always_comb
Futurewiz
www.futurewiz.co.in
always_latch
always_latch
if(en) b=a;
Futurewiz
www.futurewiz.co.in
always_ff
Tools should perform additional checks to warn if the behavior does not
represent sequential logic.
Futurewiz
www.futurewiz.co.in
Fine Grain process control
Futurewiz
www.futurewiz.co.in
Fine Grain process control
Futurewiz
www.futurewiz.co.in
Fine Grain process control
kill() function terminates the current process and all its sub
processes.
Futurewiz
www.futurewiz.co.in
Example
Futurewiz
www.futurewiz.co.in
Example
Futurewiz
www.futurewiz.co.in
Example
initial begin
#3 p1.suspend();
#10 p2.suspend();
#5 p1.resume();
$display(“%s”,p1.status());
$display(“%s”,p2.status());
#2 p2.resume();
#1 p2.await();
#1 p1.kill();
end
Futurewiz
www.futurewiz.co.in
System Verilog
COVERAGE
Coverage
Types of Coverage's:
o Code Coverage.
o Functional Coverage.
Futurewiz
www.futurewiz.co.in
Code Coverage
o Branch coverage
o Checks whether each branch of control statement (if, case)
has been covered.
o Example: choices in case statements.
Futurewiz
www.futurewiz.co.in
Code Coverage
o Condition coverage
o Has Boolean expression in each condition evaluated to both true
and false.
o Toggle coverage
o Checks that each bit of every signal has toggled from 0 to 1 and 1
to 0.
o Transition coverage
o Checks that all possible transitions in FSM has been covered.
o State coverage
o Checks that all states of FSM has been covered.
Futurewiz
www.futurewiz.co.in
Functional Coverage
Futurewiz
www.futurewiz.co.in
Examples
Futurewiz
www.futurewiz.co.in
Code vs. Functional Coverage
Functional Coverage
Low High
Code Coverage
Futurewiz
www.futurewiz.co.in
Coverage Driven Verification
Coverage Met ?
YES
NO
Verification
Identify Coverage Holes
Complete
Add tests to target holes,
Enhance stimulus generator,
Enhance cover metrics if
required Futurewiz
www.futurewiz.co.in
SV Functional Coverage Support
Syntax:
covergroup cg_name [(port_list)]
[coverage_event];
//coverage_specs;
//coverage_options;
endgroup [ : cg_name]
Example:
covergroup cg;
……
endgroup
cg cg1=new;
Futurewiz
www.futurewiz.co.in
Coverpoint
Futurewiz
www.futurewiz.co.in
Example
Syntax:
[label : ] coverpoint expression [ iff
(expression)]
[{
//bins specifications;
}] ;
Example:
covergroup cg;
coverpoint a iff (!reset);
endgroup
Futurewiz
www.futurewiz.co.in
bins
bins are buckets which are used to collect number of times a particular
value/transaction has occurred.
If bins construct is not used inside coverpoint then automatic bins are
created based on the variable type and size.
Futurewiz
www.futurewiz.co.in
Example1
cg cg1;
initial cg1=new;
Futurewiz
www.futurewiz.co.in
Example2
Futurewiz
www.futurewiz.co.in
Example3
Futurewiz
www.futurewiz.co.in
Example4
Futurewiz
www.futurewiz.co.in
Example5
Futurewiz
www.futurewiz.co.in
Questa (How to obtain coverage)
Futurewiz
www.futurewiz.co.in
Covergroup Arguments
Futurewiz
www.futurewiz.co.in
Example
covergroup addr_cov (input int low, int high, ref bit [16:0] address)
@ (posedge clk);
addr_range : coverpoint address {
bins addrbin= { [low: high] };
}
endgroup
Futurewiz
www.futurewiz.co.in
Covergroup inside a class
Futurewiz
www.futurewiz.co.in
Example
class xyz;
bit [3:0] m_x;
int m_y;
bit m_z;
covergroup cov1 @ (m_z); //Embedded Covergroup
coverpoint m_x; //16 bins
coverpoint m_y; //2^32 bins
endgroup
function new(); cov1=new; endfunction
endclass
Futurewiz
www.futurewiz.co.in
Example
class c1;
bit [7:0] x;
covergroup cv (input int arg) @ (posedge clk);
option.at_least=arg;
coverpoint x;
endgroup
function new (int p1); cv=new(p1); endfunction
endclass
initial c1 obj=new(4);
Futurewiz
www.futurewiz.co.in
Bins for Transition
Futurewiz
www.futurewiz.co.in
Specifying Transition
Sequence of Transitions
(value1=> value2 => value3=> value4)
Set of Transitions
(value1, value2 => value3, value4)
bit [4:1] a;
covergroup cg @ (posedge clk);
coverpoint a
{ bins sa [ ]= ( 4=>5=>6 ), ( [7:9],10=>11,12) ;
bins allother= default sequence;
}
endgroup
Sa will be associated with individual bins (4=>5=>6) ,
(7=>11), (7=>12), (8=>11), (8=>12), (9=>11), (9=>12),
(10=>11), (10=>12)
Futurewiz
www.futurewiz.co.in
Example2
Consecutive Repetition
bins sb={ 4 [*3] } ;
// (4=>4=>4)
bins sc [ ]={ 3 [*2:4] };
// (3=>3) , (3=>3=>3), (3=>3=>3=>3)
Non-Consecutive Repetition
bins sd [ ]={ 2 [->3] };
//2=>…. =>2 …. =>2
Futurewiz
www.futurewiz.co.in
Automatic Bin creation
covergroup cg;
coverpoint num
{ wildcard bins even={3’b??0};
wildcard bins odd={3’b??1};
}
endgroup
Futurewiz
www.futurewiz.co.in
Wildcard Bins
covergroup cg;
coverpoint count1
{ wildcard bins n12_15={4’b11??};
//1100 || 1101 || 1110 || 1111
}
coverpoint count2
{ wildcard bins t =(2’b0x=>2’b1x);
//(0, 1=>2, 3)
}
endgroup
Futurewiz
www.futurewiz.co.in
Excluding bins
Futurewiz
www.futurewiz.co.in
Ignore Bins
Futurewiz
www.futurewiz.co.in
Ignore Bins
covergroup cg;
coverpoint num {
option.auto_bin_max=4;
//<0:1> , <2:3>, <4:5>, <6:7>
ignore_bins bins hi={6, 7};
// bins 6 and 7 are ignored from
coverage
}
endgroup
Futurewiz
www.futurewiz.co.in
Illegal Bins
They will result in a run-time error even if they are also included in
another bin.
bit [3:0] num;
covergroup cg;
coverpoint num {
illegal_bins bins illegalval={ 2, 3 }; //illegal bins 2 and 3
illegal_bins bins illegaltran=(4=>5); //4 to 5 is illegal
//transition
} endgroup
Futurewiz
www.futurewiz.co.in
Cross Coverage
Examples:
o Was write enable 1 when address was 4’b1101.
o Have we provide all possible combination of inputs to a Full
Adder.
Futurewiz
www.futurewiz.co.in
Example1
bit [3:0] a, b;
covergroup cg @ (posedge clk);
cross_cov: cross a , b;
endgroup
bit [3:0] a, b, c;
covergroup cg @ (posedge clk);
cov_add: coverpoint b+c;
cross_cov: cross a , cov_add;
endgroup
Futurewiz
www.futurewiz.co.in
Example3
bit [31:0] a;
bit [3:0] b;
covergroup cg @ (posedge clk);
cova: coverpoint a { bins low [ ]={ [0:9] }; }
cross_cov: cross b, cova;
endgroup
Futurewiz
www.futurewiz.co.in
Cross Coverage
Futurewiz
www.futurewiz.co.in
binsof and intersect
Examples:
o binsof(X) intersect { Y } , denotes the bins of coverage
point X whose values intersect the range given by Y.
o ! binsof(X) intersect { Y } , denotes the bins of
coverage point X whose values do not intersect the
range given by Y.
Futurewiz
www.futurewiz.co.in
binsof and intersect
bit [7:0] a, b;
covergroup cg @ (posedge clk);
cova : coverpoint a
{
bins a1 = { [0:63] };
bins a2 = { [64:127] };
bins a3 = { [128:191] };
bins a4 = { [192:255] };
} endgroup
Futurewiz
www.futurewiz.co.in
binsof and intersect
covb : coverpoint b
{
bins b1 = { 0 };
bins b2 = { [1:84] };
bins b3 = { [85:169] };
bins b4 = { [170:255] };
}
Futurewiz
www.futurewiz.co.in
binsof and intersect
covergroup cg;
cross a, b
{
ignore_bins bins ig=binsof(a) intersect { 5, [1:3] };
}
endgroup
All cross products that satisfy the select expression are
excluded from coverage even if they are included in other
cross-coverage bins of the cross.
Futurewiz
www.futurewiz.co.in
Illegal Cross products
Futurewiz
www.futurewiz.co.in
Coverage Options
Futurewiz
www.futurewiz.co.in
option.comment
covergroup cg;
option.comment=“Cover group for data and address”;
coverpoint data;
coverpoint address;
endgroup
Futurewiz
www.futurewiz.co.in
per instance coverage
covergroup cg;
option.per_instance=1;
coverpoint data;
endgroup
Futurewiz
www.futurewiz.co.in
at_least coverage
option.at_least=10
Futurewiz
www.futurewiz.co.in
Coverage goal
Futurewiz
www.futurewiz.co.in
option.weight
covergroup cg;
a: coverpoint sig_a { bins a0= {0};
option.weight=0; //will not compute to
//coverage
}
b: coverpoint sig_b { bins b1= {1};
option.weight=1;
}
ab: cross a , b { option.weight=3; }
endgroup
Futurewiz
www.futurewiz.co.in
option.auto_bin_max
Futurewiz
www.futurewiz.co.in
Predefined Coverage Methods
Futurewiz
www.futurewiz.co.in
Example1
covergroup packet_cg;
coverpoint dest_addr;
coverpoint packet_type;
endgroup
packet_cg pkt;
initial pkt=new;
always @ (pkt_received)
pkt.sample();
Futurewiz
www.futurewiz.co.in
Example2
covergroup packet_cg;
coverpoint dest_addr;
coverpoint packet_type;
endgroup
packet_cg pkt;
initial pkt=new;
$set_coverage_db_name ( name )
Sets the filename of the coverage database into which
coverage information is saved at the end of a simulation
run.
$load_coverage_db ( name )
Load from the given filename the cumulative coverage
information for all coverage group types.
$get_coverage ( )
Returns as a real number in the range 0 to 100 that
depicts the overall coverage of all coverage group types.
Futurewiz
www.futurewiz.co.in
Cover property
property ab;
@(posedge clk) a ##3 b;
endproperty
Futurewiz
www.futurewiz.co.in
Effect of coverage on performance
Futurewiz
www.futurewiz.co.in
System Verilog
ASSERTIONS
Assertions and Coverage
Assertions
These are checks which used to verify that your design meets the
given requirements.
Example: grant should be high two clock cycles after request.
Coverage
These are used to judge what percentage of your test plan or
functionality has been verified.
They are used to judge quality of stimulus.
They help us in finding what part of code remains untested.
Futurewiz
www.futurewiz.co.in
Assertions
Clock
Request
Assertion Passed
Grant
Assertion Failed
Grant
Futurewiz
www.futurewiz.co.in
Assertions
Types of Assertions
Immediate Assertions.
Concurrent Assertions.
Futurewiz
www.futurewiz.co.in
Immediate Assertions
These checks are Non Temporal i.e. checks are not performed across
time or clock cycles.
Futurewiz
www.futurewiz.co.in
Example
clk
req1
req2
Futurewiz
www.futurewiz.co.in
Example
Futurewiz
www.futurewiz.co.in
Assertions Severity
Futurewiz
www.futurewiz.co.in
Examples
always @ (state)
assert($onehot(state)) else $fatal(“state is not one hot”);
//In a one-hot encoded state machine all states should be one-hot
Futurewiz
www.futurewiz.co.in
Concurrent Assertions
They are called concurrent because they occur in parallel with other
design blocks.
Futurewiz
www.futurewiz.co.in
Assertions
Clk
Req
Assertion
Gnt
Passed
Gnt Assertion
Passed
Futurewiz
www.futurewiz.co.in
Example
property req_gnt;
@ (posedge clk) req ##2 gnt ##1 !req ##1 !gnt;
endproperty
assert property(req_gnt) else $error(“req_gnt property violated”);
If gnt is not high 2 clock cycles after req goes high, violation will be
reported.
If req and gnt come at proper time but req is not low in next clock
cycle, that will also lead to violations.
Futurewiz
www.futurewiz.co.in
Assertion Region
Postponed Re-NBA
Futurewiz
www.futurewiz.co.in
Properties and Sequences
Futurewiz
www.futurewiz.co.in
Properties and Sequences
property disable_property;
@ (posedge clk) disable iff (reset)
a ##1 b ##1 c;
endproperty
property p1;
@ (posedge clk) disable iff assert
(reset) property(p1);
s1 ##1 s2;
endsequence
Futurewiz
www.futurewiz.co.in
Sequences
Futurewiz
www.futurewiz.co.in
Example
Futurewiz
www.futurewiz.co.in
Example
clk
Syntax:
sequence sequence_name [ (arguments) ];
boolean_expression;
endsequence [ : sequence_name]
Futurewiz
www.futurewiz.co.in
Sequence Arguments
Futurewiz
www.futurewiz.co.in
Implication Operator
Futurewiz
www.futurewiz.co.in
Overlapping Implication Operator
property p1;
@ (posedge clk) en |-> (req ##2 ack);
endproperty
Futurewiz
www.futurewiz.co.in
Example
Futurewiz
www.futurewiz.co.in
Example
clk
en
re
q
gnt
clk
en
re
q
gnt
property p1;
@ (posedge clk) en |=> (req ##2
ack);
endproperty
Futurewiz
www.futurewiz.co.in
Example
clk
en
re
q
gnt
Vacuous Pass
Error Reported Evaluation in progress Sequence Occurred
Futurewiz
www.futurewiz.co.in
Example
clk
en
re
q
gnt
clk
a
Assertion
b
Passed
Assertion
b Passed
Assertion
b Passed
Assertion
b Failed
Futurewiz
www.futurewiz.co.in
Sequence Operators
Futurewiz
www.futurewiz.co.in
Sequence Operators
b must be true for two consecutive clock cycles after a goes high
a ##1 (b ##1 c) [*2];
sequence s5;
@ (posedge clk) a ##1 b [=2];
endsequence
clk
b
Assertion
Passed
b
Assertion
Passed
Futurewiz
www.futurewiz.co.in
Sequence Operators
sequence s6;
@ (posedge clk) a ##1 b [=2: 3];
endsequence
clk
a
b
Seq1detecte
d Resultant Sequence
c Detected
d
e
Seq detection started Seq2 detected
Futurewiz
www.futurewiz.co.in
Example
(a and b)
clk
clk
a
b
Seq detection started
c
d
e
Seq1 Seq2 Detected Resultant Sequence
Detected Detected Futurewiz
www.futurewiz.co.in
Intersect Operator
Futurewiz
www.futurewiz.co.in
Example
clk
a
b
Seq detection
c started
d
e
Seq1 Seq2 Detected Resultant Sequence
Detected Detected Futurewiz
www.futurewiz.co.in
OR Operator
seq1 or seq2
clk
a
b
Seq1detecte
d Resultant Sequence
c Detected
d
e
Seq detection started Seq2 detected
Futurewiz
www.futurewiz.co.in
Example
(a or b)
clk
clk
a
b
Seq detection started
c
d
e
Seq1 Seq2 Detected Resultant Sequence
Detected Detected Futurewiz
www.futurewiz.co.in
throughout Operator
Futurewiz
www.futurewiz.co.in
First_match Operator
first_match(a ##[2:4] b)
clk
sequence abc;
a ##1 b ##1 c;
endsequence
property nomatch;
@(posedge clk) start |-> not (abc);
endproperty
Futurewiz
www.futurewiz.co.in
not Operator
property incorrect;
@(posedge clk) not (a ##1 b |=> c ##1 d);
endproperty
property correct;
@(posedge clk) not(a ##1 b ##1 c ##1 d);
endproperty
Futurewiz
www.futurewiz.co.in
If-else Expression
property test;
@(posedge clk) (req1 || req2) ->
if(req1)
##1 ack1;
else
##1 ack2;
endproperty
Futurewiz
www.futurewiz.co.in
Local Variables
Futurewiz
www.futurewiz.co.in
Example
sequence s1;
int i;
(data_valid, (i = tag_in))
##7 (tag_out == i);
endsequence
Futurewiz
www.futurewiz.co.in
Sample Value Functions
Futurewiz
www.futurewiz.co.in
$rose, $fell
Futurewiz
www.futurewiz.co.in
$rose vs @(posedge)
Futurewiz
www.futurewiz.co.in
$rose
clk
p1 p2 asserted
asserted Futurewiz
www.futurewiz.co.in
$stable, $past
Futurewiz
www.futurewiz.co.in
Properties
Futurewiz
www.futurewiz.co.in
Types of Properties
Types of Properties
o sequence
o negation
o disjunction
o conjunction
o if..else
o implication
o instantiation
Futurewiz
www.futurewiz.co.in
Sequence
Futurewiz
www.futurewiz.co.in
Negation
property p3;
@ (posedge clk) not ( a ##1 b ##1 c );
endproperty
Futurewiz
www.futurewiz.co.in
Disjunction (OR)
property p4;
@ (posedge clk) ( (##[1:3] a) or (b |=> c) );
endproperty
Futurewiz
www.futurewiz.co.in
Conjunction (AND)
property p4;
@ (posedge clk) ( (##[1:3] b) and (c |=> d) );
endproperty
Futurewiz
www.futurewiz.co.in
If..else
if (expression) property_expr1
Futurewiz
www.futurewiz.co.in
Instantiation
property p2;
@ (posedge clk)
a ##1 b |->
if(c) p1(d, e);
else f;
endproperty Futurewiz
www.futurewiz.co.in
Recursive Properties
Futurewiz
www.futurewiz.co.in
Example
clk
intr
Assertion
intra Passed
Assertion Failed
intra
Futurewiz
www.futurewiz.co.in
Example
Futurewiz
www.futurewiz.co.in
Restriction on Recursive Property
property incorrect(p);
p and (1’b1 |=> not incorrect(p));
endproperty
Futurewiz
www.futurewiz.co.in
Restriction on Recursive Property
property incorrect(p);
disable iff (a)
Rewrite as p and (1’b1
follows |=> is not recursive.
as legal
incorrect(p));
endproperty
property rec(p);
p and (1’b1 |-> rec(p));
endproperty
The overlapping operator will make this recursion
stuck in an infinite loop
Futurewiz
www.futurewiz.co.in
Mutual Recursion
property chk1;
a|-> b and (1’b1 |=> chk2);
endproperty
property chk2;
c |-> d and (1’b1 |=> chk1);
endproperty
Futurewiz
www.futurewiz.co.in
Labeling Assertions
ERROR_q_did_not_follow_d:
assert property
( @(posedge clk) disable iff (!rst_n) (q==$past(d)) );
Futurewiz
www.futurewiz.co.in