SystemVerilog Veriflcation
SystemVerilog Veriflcation
Presented by,
Dr. Amit M Joshi,
Assistant Professor,
Department of Electronics & Communication,
MNIT-Jaipur
Outline
❑ Verification Basics
❑ Features of System Verilog
❑ Arrays of System Verilog
❑ Basic of Test Bench
❑ Assertion
❑ Coverage
Basics of Verifications
What is Verification ?
• Verification is a process used to demonstrate the functional
correctness of a design.
Design Flow
Design Flow
Verification Testing
0
1
0
1
1
0 Circuit 11000011
1 -
1 01100011
0 diff ?
0 expected
1 result
Any Problem? Whose Problem?
“My biggest problem about design
verification is that the time is never
enough. I can only do my best to run
more simulation, but I don’t know
whether it is sufficient.”
--- Broadcom designer (similar comments from
many others)
module half_adder(s,co,a,b);
output s,co;
Will this work??
input a,b;
xor1 u1(s,a,b);
nand1 u2 (co,a,b);
How to make sure design is
endmodule bug free??
How To Verify ?
A B S CO
B
Why System Verilog for Verification ?
➢ Verilog was initially used for writing testbench.
➢ But, writing complex testbenches is much more of a programming task
than describing hardware. No need to synthesize testbench.
classes encapsulation
OOP
polymorphism inheritance
What is OOP?
Why system
Verilog?
• Data members(properties)
• New Methods
❑Advantages
Logic :
Variable
Integer
Real
Void
Class
String
Event
User-
Defined
Enumeratio
n
Variable – a data storage element
Void
Class
Variable Typedef
Integer
typedef data_type type_identifier ;
Real
Void
Class
Ex.
String
typedef int animal;
Event
User- animal lion, tiger;
Defined
Enumeratio
n
Variable – a data storage element
✓ Arrays
✓ Dynamic Array
✓ Associative Array
✓ Queue
Arrays
Packed Arrays : Unpacked Array :
➢Treated as single vector
➢byte, shortint, int, longint, ➢size after variable name
integer, time ➢logic b1 [7:0]
byte c2; ➢int a1 [7:0]
integer a1; // 2D array - packed int;
➢bit signed [7:0] c2;//size unpacked byte
before variable
logic signed [31:0] a1;
Memory : Array Literals:
int a [3:0]; → a = ‘{4{3}} =
logic [7:0] mem [0:255] ‘{3,3,3,3}
mem[5] = 0;
data = mem[addr] int b [0:1] [0:2] → b =
‘{‘{1,2,3},’{3{4}}}
1 2 3
4 4 4
Fixed Size Arrays
Declaring fixed-size arrays
• int lo_hi[0:15]; // 16 ints [0]..[15]
• int c_style[16]; // 16 ints [0]..[15]
Multi Dimensional
• int array2 [0:7][0:3]; // Verbose declaration
• int array3 [8][4]; // Compact declaration
• array2[7][3] = 1; // Set last array element
Packed and Unpacked Arrays
Queue…
❑ Data storage array [$]
• Variable size array with automatic sizing
• Searching, sorting and insertion methods
• A queue is a variable-size, ordered collection of
homogeneous elements.
• Each element in a queue is identified by an ordinal
number that represents its position within the queue, with
0 representing the first, and $ representing the last.
• A queue is analogous to a one-dimensional unpacked
array that grows and shrinks automatically.
Examples of Queue
Method Description
next() Returns the smallest index whose value is greater than given
index
prev() Returns the largest index whose value is lesser than given
index
Interface
Interface:An example
ModPorts
Modports
❑ An interface can have multiple viewpoints
• Master/Slave, Transmitter/Receiver
❑ These can be specified using modports
❑Why Randomization ?
Directed Random
❑ Constrained Randomization
❑ Improves the result
❑ Speed-up the bug finding process
❑ More interesting cases can be achieved within the
constrained boundary
System Verilog Concepts
Fork/join
Initial
Begin
Clk =0;
fork
#5
Fork
#5 a = 0;
#10 b = 0;
join Join
Clk= 1;
end
System Verilog Concepts
Fork/join
Initial
Begin
Clk =0;
fork
#5
Fork
#5 a = 0;
#10 b = 0;
Clk becomes 1
join Join
at t=15
Clk= 1;
end
System Verilog Concepts
Fork/join_any
Initial
Begin
Clk =0;
fork
#5
Fork
#5 a = 0;
#10 b = 0;
Join_any Join_any
Clk= 1;
end
System Verilog Concepts
Fork/join_any
Initial
Begin
Clk =0;
fork
#5
Fork
#5 a = 0;
#10 b = 0;
Clk becomes 1
Join_any Join_any
at t=10
Clk= 1;
end
System Verilog Concepts
Fork/join_none
Initial
Begin
Clk =0;
fork
#5
Fork
#5 a = 0;
#10 b = 0;
Join_none
Join_none
Clk= 1;
end
System Verilog Concepts
Fork/join_none
Initial
Begin
Clk =0;
fork
#5
Fork
#5 a = 0;
#10 b = 0;
Clk becomes 1
Join_none
Join_none at t=5
Clk= 1;
end
Verification Targeted Capabilities
Verification environment
Checks Testbench
Verification
correctness Environment
Creates
stimulus
Identifies
Executes Test Self Check transactions
transactions
DUT
Assertions
Assertion
❑ asserts that the expression Read && Write is never true at any
point during simulation.
Concurrent Assertion
covergroup cg;
...
...
...
endgroup
cg cg_inst = new;
Cover points
❑ A covergroup can contain one or more coverage points. A
coverage point can be an integral variable or an integral expression.
A coverage point creates a hierarchical scope, and can be optionally
labeled. If the label is specified then it designates the name of the
coverage point.
program main;
bit [0:2] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y;
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
Cover points
❑ Results
VARIABLE : cover_point_y
Expected : 8
Covered : 3
Percent: 37.50.
Bins
COVERAGE BINS
In the above example, bins are created explicitly. The bins are named a,b,c and d.
Coverage report:
-------------------
VARIABLE : cover_point_y
Expected : 4
Covered : 3
Percent: 75.00
Uncovered bins
--------------------
a
Covered bins
--------------------
b
c
d
Array Of Bins
To create a separate bin for each value (an array of bins) the square brackets, [], must follow
the bin name.
program main;
bit [0:2] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins a[] = {[0:7]};
}
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
Array Of Bins
In the above example, bin a is array of 8 bins and each bin associates to one number between
0 to 7.
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 8
Covered : 3
Percent: 37.50
Uncovered bins
-------------------
a_0
a_1
a_2
a_4
a_7
Covered bins
-------------------
a_3
a_5
a_6
To create a fixed number of bins for a set of values, a number can be specified inside the
square brackets.
program main;
bit [0:3] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins a[4] = {[0:7]};
}
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
In the above example, variable y is 4 bit width vector. Total possible values for this vector
are 16.
But in the cover point bins, we have giving the interested range as 0 to 7. So the coverage
report is calculated over the range 0 to 7 only. In this example, we have shown the number
bins to be fixed to size 4.
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 4
Covered : 3
Percent: 75.00
Uncovered bins
-------------------
a[0:1]
Covered bins
------------------
a[2:3]
a[4:5]
a[6:7]
Cover points
A coverage point can be an integral variable or an integral Expression.
SystemVerilog allows specifying the cover points in various ways.
1)Using XMR
Example:
Cover_xmr : coverpoint top.DUT.Submodule.bus_address;
2)Part select
Example:
Cover_part: coverpoint bus_address[31:2];
3)Expression
Example:
Cocver_exp: coverpoint (a*b);
4)Function return value
Example:
Cover_fun: coverpoint funcation_call();
5)Ref variable
Example:
covergroup (ref int r_v) cg;
cover_ref: coverpoint r_v;
endgroup
Cover filter
The expression within the iff construct specifies an optional condition that
disables coverage for that cover point. If the guard expression evaluates to false at
a sampling point, the coverage point is ignored.
For example:
covergroup cg;
coverpoint cp_varib iff(!reset); // filter condition
endgroup
In the preceding example, cover point varible "cp_varib" is covered only if the
value reset is low.
COVERAGE BINS
Default Bins
The default specification defines a bin that is associated with none of the defined value bins.
The default bin catches the values of the coverage point that do not lie within any of the
defined bins. However, the coverage calculation for a coverage point shall not take into
account the coverage captured by the default bin.
program main;
bit [0:3] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins a[2] = {[0:4]};
bins d = default;
}
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
Default Bin
In the above example, we have specified only 2 bins to cover values from 0 to 4. Rest of
values are covered in default bin which is not using in calculating the coverage percentage.
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 2
Covered : 1
Percent: 50.00
Uncovered bins
------------------
a[0:1]
Covered bins
----------------
a[2:4]
Default bin
-----------------
d
TRANSITION BINS
Type of Transitions:
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 2
Covered : 1
Percent: 50.00
Uncovered bins
------------------
tran_34
Covered bins
----------------
tran_56
Sequence Of Transitions
A sequence of transitions is represented as:
value1 => value3 => value4 => value5
In this case, value1 is followed by value3, followed by value4 and followed by
value5. A sequence can be of any arbitrary length.
program main;
bit [0:3] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins tran_345 = (3=>4>=5);
bins tran_356 = (3=>5=>6);
}
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
In the above example, 2 bins re created for covering the transition of
point "y" from 3 to 4 to 5 and other for 3 to 5 to 6. The variable y is
given the values and only the transition 3 to 5 to 6 is occurring.
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 2
Covered : 1
Percent: 50.00
Uncovered bins
------------------
tran_345
Covered bins
-----------------
tran_356
Set Of Transitions
A set of transitions can be specified as:
range_list1 => range_list2
program main;
bit [0:3] y;
bit [0:2] values[$]= '{3,5,6};
covergroup cg;
cover_point_y : coverpoint y {
bins trans[] = (3,4=>5,6);
}
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
In the above example, bin trans creates 4 bin for covering
3=>5,4=>5,3=>6 and 4=>6.
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 4
Covered : 1
Percent: 25.00
Uncovered bins
------------------
tran_34_to_56:3->6
tran_34_to_56:4->5
tran_34_to_56:4->6
Covered bins
----------------
tran_34_to_56:3->5
Consecutive Repetitions
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 2
Covered : 1
Percent: 50.00
Uncovered bins
------------------
trans_3
Covered bins
----------------
trans_4
Range Of Repetition
covergroup cg;
cover_point_y : coverpoint y {
bins trans_3[] = (3[*3:5]);
}
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end
endprogram
In the above example, only the sequence 3=>3=>3=>3 is generated. Other
expected sequences 3=>3=>3 and 3=>3=>3=>3=>3 are not generated.
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 3
Covered : 1
Percent: 33.33
Uncovered bins
------------------
tran_3:3[*3]
tran_3:3[*5]
Covered bins
----------------
tran_3:3[*4]
Goto Repetition
The goto repetition is specified using: trans_item [-> repeat_range]. The
required number of occurrences of a particular value is specified by the
repeat_range. Any number of sample points can occur before the first
occurrence of the specified value and any number of sample points can
occur between each occurrence of the specified value. The transition
following the goto repetition must immediately follow the last occurrence
of the repetition.
For example:
3 [-> 3]
is the same as
...=>3...=>3...=>3
where the dots (...) represent any transition that does not contain the value
3.
A goto repetition followed by an additional value is represented as
follows:
1 => 3 [ -> 3] => 5
is the same as
1...=>3...=>3...=>3 =>5
program main;
bit [0:3] y;
bit [0:2] values[$]= '{1,6,3,6,3,6,3,5};
covergroup cg;
cover_point_y : coverpoint y {
bins trans_3 = (1=>3[->3]=>5); }
endgroup
cg cg_inst = new();
initial
foreach(values[i])
begin
y = values[i];
cg_inst.sample();
end endprogram
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 1
Covered : 1
Percent: 100.00
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 1
Covered : 1
Percent: 100.00
Non Consecutive Repetition
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 1
Covered : 1
Percent: 100.00
WILDCARD BINS
covergroup cg;
cover_point_y : coverpoint y {
wildcard bins trans = (2'b0X => 2'b1X );
}
endgroup
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 1
Covered : 1
Percent: 100.00
Covered bin
---------------
trans
Number of times trans hit : 1 (01 => 10)
IGNORE BINS
program main;
bit [0:2] y;
bit [0:2] values[$]= '{1,6,3,7,3,4,3,5};
covergroup cg;
cover_point_y : coverpoint y {
ignore_bins ig = {1,2,3,4,5};
}
endgroup
Coverage report:
--------------------
VARIABLE : cover_point_y
Expected : 3
Covered : 2
Percent: 66.66
Uncovered bins
------------------
auto[0]
Excluded/Illegal bins
-------------------------
ig
auto[1]
auto[2]
auto[3]
auto[4]
auto[5]
Covered bins
----------------
auto[6]
auto[7]
ILLEGAL BINS
program main;
bit [0:2] y;
bit [0:2] values[$]= '{1,6,3,7,3,4,3,5};
covergroup cg;
cover_point_y : coverpoint y {
illegal_bins ib = {7};
}
endgroup
Result:
------------
** ERROR **
Illegal state bin ib of coverpoint cover_point_y in
covergroup cg got hit with value 0x7
CROSS COVERAGE
bit [0:1] z;
bit [0:1] z_values[$]= '{1,2};
covergroup cg;
cover_point_y : coverpoint y ;
cover_point_z : coverpoint z ;
cross_yz : cross cover_point_y,cover_point_z
;
endgroup
cg cg_inst = new();
initial
foreach(y_values[i])
begin
y = y_values[i];
z = z_values[i];
cg_inst.sample();
end
endprogram
In the above program, y has can have 4 values 0,1,2 and 3 and
similarly z can have 4 values 0,1,2 and 3. The cross product of the y
and z will be 16 values
(00),(01),(02),(03),(10),(11)........(yz)......(32)(33) .
Only combinations (11) and (32) are generated.
Covered bins
-----------------
cover_point_y cover_point_z
auto[3] auto[2]
auto[1] auto[1]
Example:
module test();
logic [2:0] addr;
logic [1:0] cmd;
reg ce;
covergroup address_cov () @ (posedge ce);
ADDRESS : coverpoint addr {
bins addr0 = {0};
bins addr1 = {1};
bins addr2 = {2};
bins addr3 = {3};
} CMD :
coverpoint cmd {
bins READ = {0};
bins WRITE = {1};
bins IDLE = {2};
};
CRS_ADDR_CMD : cross ADDRESS, CMD;
endgroup
address_cov my_cov = new();
initial begin
ce <= 0;
$monitor("ce %b addr 8'h%x cmd %x",ce,addr,cmd);
repeat (10)
begin ce <= 1;
addr <= $urandom_range(0,5);
cmd <= $urandom_range(0,2);
#10;
ce <= 0;
#10;
end
end
endmodule
ce 1 addr 8'h2 cmd 2
ce 0 addr 8'h2 cmd 2
ce 1 addr 8'h1 cmd 0
ce 0 addr 8'h1 cmd 0
ce 1 addr 8'h1 cmd 2
ce 0 addr 8'h1 cmd 2
ce 1 addr 8'h4 cmd 0
ce 0 addr 8'h4 cmd 0
ce 1 addr 8'h0 cmd 2
ce 0 addr 8'h0 cmd 2
ce 1 addr 8'h5 cmd 2
ce 0 addr 8'h5 cmd 2
ce 1 addr 8'h2 cmd 2
ce 0 addr 8'h2 cmd 2
ce 1 addr 8'h5 cmd 0
ce 0 addr 8'h5 cmd 0
ce 1 addr 8'h2 cmd 2
ce 0 addr 8'h2 cmd 2
ce 1 addr 8'h4 cmd 2
ce 0 addr 8'h4 cmd 2
User-Defined Cross Bins
User-defined bins for cross coverage are defined using bin select expressions.
Consider the following example code:
int A,B;
coverpoint A { a[] ={[0:27]};}
coverpoint B { b[] = {[0:27]};}
cross_A_B cross a,b;
int A,B;
coverpoint A { a[] ={[0:27]};}
coverpoint B { b[] = {[0:27]};}
cross_A_B cross a,b;
Instead of
coverpoint A { a[] ={[0:27]};}
coverpoint B { b[] = {[0:27]};}
Do write:
coverpoint A { bins a1 = {[2:5]};
bins a2 = {[2:8]};
bins a3 = {[9:15]};
bins a4 = {[16:27]};
} coverpoint B
{ bins b1 = {[3:6]};
bins b2 = {[7:10]};
bins b3 = {[11:15]};
bins b4 = {[16:27]}; }
SYSTEM TASKS
SystemVerilog provides the following system tasks and functions to help manage
coverage data collection.
$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 the overall coverage of all coverage
group types.
SYSTEM TASKS
There are tasks and functions that are used to generate input
and output during simulation. Their names begin with a
dollar sign ($). The synthesis tools parse and ignore system
functions, and hence can be included even in synthesizable
models
$strobe:
$strobe displays the parameters at the very end of the current
simulation time unit.
$display
when it is executed it will be displayed
$monitor
$monitor displays every time one of its parameters changes
$time, $stime, $realtime
These return the current simulation time as a 64-bit integer, a 32-
bit integer, and a real number, respectively.
Books :
1. Writing Testbenches using SystemVerilog
- Janick Bergeron
2. Verification Methodology Manual
- Janick Bergeron
3. SystemVerilog For Verification
- Chris Spear
183
Thank you