system verilog pdf
system verilog pdf
system verilog pdf
2. What is verification?
A:- In the front-end design process of VLSI (Very Large Scale Integration),
verification refers to the important step of ensuring the correctness and
functionality of the design before moving forward to the physical implementation
stages. The front-end design encompasses the stages of architecture design, logic
design, and functional verification before the design is translated into a physical
layout (the back-end design).
SV Verification architecture:-
Top
Tests
ENV Generator
DUV
Verifications are two types Functional verification and STA(static timing
analysis).
Functional verification: - This stage focuses on ensuring that the design
performs its intended functions correctly. It involves creating test cases that cover
all aspects of the design's functionality and simulating the design to check its
behaviour under various scenarios.
Formal verification: Formal verification is the process of mathematically
checking that the behaviour of a system, described using a formal model, satisfies
a given property, also described using a formal model.
typedef:-Allows users to define new types built up from the predefined types or
other user-defined types in Verilog and SystemVerilog.
syntax:-typedef data_type type_name [range];
ex:- module ex;
typedef enum {g, be}op;
op a,a1;
initial begin
a = g;
a1=b;
if(a == g)
$display("a is g packet");
else
$display("a is b packet");
if(a1 == g)
$display("a1 is g packet");
else
$display("a1 is b packet");
end
endmodule
output:-
a is g packet
a1 is b packet
8. What is an array?
A:- An array is a group of variables having the same data type. It can be accessed
using an index value. An index is a memory address, and the array value is stored
at that address.
Unpacked array :- The term unpacked array is used to refer to the dimensions
declared after the data identifier name types bit temp_var [7:0]; // unpacked array
of real types.
Syntax:-data type [range] var_name;
• bit [2:0][3:0]array[2:0];
10. Difference between packed and unpaced array?
A:-
Packed array Unpacked array
1.Packed refers to data storage where 1. Unpacked refers to data storage
multiple bits of data are stored in where each element of the data
contiguous memory locations. This is structure is stored independently. This
typically used for arrays of bits (logic is typically used for larger data types
or bit data types) or arrays of smaller or when elements need to have
bit-width data types. different memory addresses.
4.Synthesizable 4.Not-synthesizable
module inheritence;
initial begin
base p;
sub c=new();
sub c1;
c.addr = 10;
c.data = 20;
p = c; //p is pointing to child class handle c.
$cast (c1, p); //with the use of $cast, type check will occur during
runtime
c1. display ();
end
endmodule
o/p:- Addr = 10
Data = 20
String operations:
Operator Description
Equality (Str1 == Str2) Returns 1 if the two strings are equal
and 0 if they are not.
Inequality (Str1 != Str2) Returns 1 if the two strings are not
equal and 0 if they are.
Comparison (Str1 < Str2 Returns 1 if the corresponding
Str1 <= Str2 condition is true and 0 if false
Str1 > Str2
Str1 >= Str2)
Concatenation ({Str1, Str2, ..., All strings will be concatenated into
StrN}) one resultant string.
Replication ({multiplier{Str}}) Replicates the string N number of
times, where N is specified by the
multiplier.
Indexing (Str[index]) Returns a byte, the ASCII code at the
given index. If given index is out of
range, it returns 0.
Methods (Str.method([args])) The dot(.) operator is used to call
string functions.
Function Task
1. A function enables another function 1. A task can enable other tasks and
but not another task. functions.
3. Function must not contain any delay, 3. Tasks may contain delay, event, or
event, or timing control statements. timing control statements.
4. Functions must have at least one 4. Tasks may have zero or more
input argument. They can have more arguments of type input, output, or
than one input. inout.
2. User-defined data types are allowed. 2. User-defined data types are not
allowed.
10. Generate statements that replicate 10. Generate statements are not present
the number of instances. in Verilog.
Ex:-
• Automatic
->Automatic tasks allocate unique, stacked storage for each task call.
SystemVerilog allows,
• to declare an automatic variable in a static task
• to declare a static variable in an automatic task
• more capabilities for declaring task ports
• multiple statements within task without requiring a begin…end or
fork…join block
• returning from the task before reaching the end of the task
• passing values by reference, value, names, and position
• default argument values
• the default direction of argument is input if no direction has been
specified
• default arguments type is logic if no type has been specified
ex:- module sv_task;
int x;
task sum;// task arguments in declarations and mentioning directions
input int a,b;
output int c;
c = a+b;
endtask
/*task sum(input int a, b, output int c);// task arguments in parentheses
c = a+b;
endtask*/
initial begin
sum(10,5,x);
$display("\tValue of x = %0d",x);
end
endmodule
o/p:- Value of x = 15
Application Critical for setup and hold Critical for ensuring proper
time requirements in synchronization and timing
synchronous circuits. closure in designs.
begin
h1=new (); h
a=20
h1. b=10;
b=10
h1.h. a=20;
h2=h1.copy() ;//deep copy
h2.h. a=30;
end
endmodule h2
a=30
h
b=10
module test;
base b = new;
child c = new;
initial begin
b = c; // Allowed
end
endmodule
=>Assignment of base class handle to derived class handle is NOT allowed and
results in compilation error.
Ex: -
Class base;
//definition
endclass
Class child;
//definition
endclass
module test;
base b = new;
child c = new;
initial begin
c=b; // Compilation error
end
endmodule
=>$cast returns 0 if the cast failed, so use the return type to throw an error.
Use if or assert to ensure that the cast is successful.
Ex: -
Class base;
//definition
Endclass
Class child;
//definition
Endclass
module test;
base b = new;
child c = new;
initial begin
if ($cast (c, b))
$display (“casting ture”);
else
$display (“casting fail”);
end
endmodule
• :/
Syntax: value :/ weight
=>constraint c{var dist{value:/weight;}
=> The :/ operator assigns the specified weight to the item, or if the item is a
range, specified weight/n to every value in the range.
=> where n is the number of values in the range.
module test;
class trans;
rand int var;
constraint c {var dist {5:/10, 2=:10, [0:9]:=2,[0:9]:/2};}
endclass
trans h1=new ();
initial begin
assert (h1. randomize ())
$display (“display values %0d”, h1.var);
end
endmodule
static constraints:
=> “static” keyword using before constraint. We write multiple handles it will
create only one memory.
module test;
class trans;
rand int var;
static constraint c {var dist {5:/10, 2=:10, [0:9]:=2,[0:9]:/2};}
endclass
trans h1=new ();
initial begin
assert (h1. randomize ())
$display (“display values %0d”, h1.var);
end
endmodule
extern constrains:
module test;
class trans;
rand int var;
constraint c;
endclass
constraint c1::c {var inside {[1:19]};}
trans h1=new ();
initial begin
assert (h1. randomize ())
$display (“display values %0d”, h1.var);
end
endmodule
(::) scope resolution operator:
=>The scope resolution operator is used to refer identifier within the scope of a
class.
class packet;
bit [31:0] addr;
static bit [31:0] id;
function display (bit [31:0] a,b);
$display ("Values are %0d %0d”, a, b);
endfunction
endclass
module test;
int id=10;
initial begin
packet p;
p = new();
packet::id = 20;
p. display (packet::id,id);
end
endmodule
inline constraints:
module test;
class trans;
rand bit [7:0]z,b, c;
constraint c{c=a+b};
endclass
trans h1=new ();
initial begin
if (! h1. randomize () with {a<b;})
$display (“randomization fail);
end
endmodule
• fork ->join_any
=> Finishes when any child thread gets over.
Ex: module test;
initial begin
#10 $display (“thread A”, $time);
fork
#10 $display (“thread A1”, $time);
#20 $display (“thread A2”, $time);
#30 $display (“thread A3”, $time);
join_any
#50 $display (“thread B”, $time);
end
endmodule
o/p: : time unit10-thread A, time unit 20-thread A1, time unit 50-thread B
time unit 30-thread A2, time unit 40-thread A3
• fork ->join_none
=> Finishes soon after child threads are spawned.
Ex: module test;
initial begin
#10 $display (“thread A”, $time);
fork
#10 $display (“thread A1”, $time);
#20 $display (“thread A2”, $time);
#30 $display (“thread A3”, $time);
join_none
#50 $display (“thread B”, $time);
end
endmodule
o/p: time unit 10-thread A, time unit 20-thread A1, time unit 30-thread A2, time
unit 40-thread A3, time unit 50-thread B.
• bounded mailbox
syntax: mailbox mail_h=new (10);
• unbounded mailbox
syntax: mailbox mail_h=new ();
• generic mailbox
syntax: mailbox mail_h=new ();
generic mailbox that can accept items of any data type.
Ex:
module test;
mailbox mbx=new ();
initial begin
for (int i=0; i<10; i++)
begin
mbx.put(i);
$display (i);
end
end
initial begin
forever
begin
int idx;
mbx.get(idx);
$display (idx);
end
end
endmodule
47. What is a semaphore?
A: =>Semaphore is built in class
=>Syntax: semaphore [var_name];
=>Semaphore used for access control to shared resources, and for basic
synchronization.
=> The same memory location is accessed by two different cores.
=> To avoid unexpected results when cores try to write or read from the same
memory location, a semaphore can be used.
Semaphore methods:
get ()
=>The get () method in semaphore is used to obtain a specified number of keys.
=>By default, one key is returned if no value is specified.
=> The get () method is a blocking method and execution continues after
successful key or keys are obtained.
Syntax:
=>semaphore. get(no_of_keys);
put ()
=>The put () method in semaphore is used to return a specified number of keys
to the semaphore container or bucket.
Syntax:
=>semaphore. put (no_of_keys);
try_get ()
=>The try_get () is a non-blocking method. The execution is not blocked even if
the number of keys is not available.
=>The try_get () function returns 1 if keys are available otherwise, it returns 0 if
no keys are available,
Syntax:
=>semaphore.try_get(no_of_keys);
semaphore: multiple keys and single key also we can use.
Ex: module semaphore_example ();
semaphore sem = new (3);
task process_A ();
sem.get (3);
$display ("process_A started");
#5ns;
$display ("process_A completed");
sem.put (3);
endtask
initial begin
fork
process_A ();
process_B ();
join
end
endmodule
o/p:
process_A started
process_A completed
process_B started
process_B completed
illegal_bins:
=>A set of values or transitions associated with a coverage-point can be marked
as illegal by specifying them as illegal_bins.
Ex: covergroup cg @ (posedge clk);
c1: coverpoint addr{ illegal_bins b1 = {7,70,77};
ignore_bins b2 = (7=>70=>77);}
endgroup
cross:
=>Cross Coverage is specified between the cover points or variables. Cross
coverage is specified using the cross construct.
=> Expressions cannot be used directly in a cross; a coverage point must be
explicitly defined first.
Ex: bit [3:0] a, b;
covergroup cg;
c1: coverpoint a;
c2: coverpoint b;
c1Xc2: cross c1, c2;
endgroup : cg