Class 12 Topics
Class 12 Topics
Class 12 Topics
What is an assertion?
SystemVerilog assertions
Immediate assertions
Concurrent assertions
Collecting functional coverage with assertions
Properties
Sequences
What is an assertion?
SystemVerilog
Verilog 2001
Even VHDL
In RTL
In a testbench
For the testbench
For the RTL
testbench
assertions
assertions
RTL
assertions
Interface
Assertions
Structural
Assertions
Arbiter
PCI Bus
FIFO
Processor
FSM
AHB Bus
SystemVerilog Assertions
An assertion written in SVA requires less extra syntax to learn if
your testbench is in SystemVerilog
2 types of assertions
Immediate -> Operates in procedural code
Concurrent -> Operates outside procedural code
Property to check: If request is 1 on the positive edge of the
clock grant must be 1 on the next positive edge of the clock.
always @(posedge clk) begin
if (request) begin
@(posedge clk);
if (grant != 1)
$display("%t: Error, grant != 1", $time);
end
end
Class 12 Copyright 2009 Greg Tumbush
Immediate Assertions
Immediate assertions operate in procedural code
Syntax:
<assertion name> : assert(expression)
<action if true>;
else
<action if false>;
always @(posedge clk) begin
if (request) begin
repeat (1) @(posedge clk);
reg_grnt_assert: assert (grant == 1)
$display("%t: Passed", $time);
else
$display("%t: Failed", $time);
end
end
Class 12 Copyright 2009 Greg Tumbush
Exercise 1
Design an immediate assertion that:
1. If the signal branch_inst = 1 on the negative edge of the clock, the
signal jump_done must = 1 two cycles later on the negative edge of
the clock.
2. If a failure occurs specify the severity to be a warning.
3. If a failure does not occur specify the severity to be an info.
4. Name the assertion branch_done
10
Exercise 1
Design an immediate assertion that:
1.
If the signal branch_inst = 1 on the negative edge of the clock, the signal jump_done must = 1 two cycles later on the negative edge of the clock.
2.
If a failure occurs specify the severity to be a warning.
3.
If a failure does not occur specify the severity to be an info.
4.
Name the assertion branch_done
11
Concurrent Assertions
Immediate assertions are no more powerful than coding in Verilog
Concurrent assertions can describe behavior that spans time.
Concurrent assertions evaluate on a defined edge.
Defined outside procedural code.
Syntax:
<assertion name> : assert property (expression)
<action if true>;
grant evaluated one cycle later
else
Overlapping: sampled on same cycle
<action if false>;
reg_grnt_assert: assert property (@(posedge clk) (request |-> ##1 grant))
$display("%t: Passed", $time);
else
$display("%t: Failed", $time);
Equivalent to reg_grnt_assert: assert property (@(posedge clk) (request |=> grant));
Class 12 Copyright 2009 Greg Tumbush
12
Assertion inactive
Assertion begins
13
14
Exercise 2
Re-write the immediate assertion in exercise 1 so that:
1. It is a concurrent assertion
2. It is disabled if input testmode is asserted.
3. Remove the additional information on success or failure.
branch_done: assert property (@(negedge clk) disable iff (testmode) (branch_inst |-> ##2 jump_done));
15
16
Delay Expressions
A ## followed by a number or range specifies the delay from the
current clock to the beginning of the sequence that follows.
A_B_C_D: assert property (@(posedge clk)
(A ##1 B ##1 C ##1 D));
17
Implication
The implication construct specifies that the checking of a property
is performed conditionally
1. |-> Overlapped implication
2. |=> Non-overlapped implication
request |=> grant
equivalent
18
19
20
21
22
Exercise 3
Re-write the concurrent assertion in exercise 2 so that:
1. Coverage is collected
2. If you used an overlapped implication operator (|->) use a nonoverlapped implication operator (|=>) or vise versa.
3. Remove the disable
branch_done: cover property (@(negedge clk) (branch_inst |=> ##1 jump_done));
or
branch_done: cover property (@(negedge clk) (branch_inst |-> ##2 jump_done));
23
24
Properties
A property can be defined separate from an assertion.
req_grant: assert property (@(posedge clk) (request |=> grant));
property req_grant;
(request |=> grant);
endproperty
A property can be used in both an assertion and a cover directive
assert property (@(posedge) (req_grant));
cover property (@(posedge) (req_grant));
Class 12 Copyright 2009 Greg Tumbush
25
26
Sequences
Complex sequential behaviors can be described by a sequence
A sequence is part of a property.
property
sequence
sequence B_C_D;
(B ##1 C ##1 D);
endsequence // B_C_D
property A_B_C_D_prop;
@(posedge clk) (A |=>B_C_D);
endproperty
A_B_C_D_assert: assert property
(A_B_C_D_prop);
Class 12 Copyright 2009 Greg Tumbush
27
Exercise 4
Re-write the concurrent assertion in exercise 3 to:
1. Specify a default clock
2. Express the sequence, property and assertion separately.
default clocking cb @(negedge clk); endclocking
sequence jump_done_seq;
##2 jump_done; or ##1 jump_done if using |=> on property
endsequence
property branch_done_prop;
(branch_inst |-> jump_done_seq);
endproperty
branch_done: assert property (branch_done_prop);
28
Sequence Range
A sequence range can be expressed
sequence B_C_D;
(B ##1 C ##[1:3] D);
endsequence
A_B_C_D_assert: assert property (@(posedge clk) (A |=> B_C_D));
29
Sequence Repeat
A sequence repeat can be expressed
sequence B_C_D;
(B ##1 C ##1 D[*3]);
endsequence
A_B_C_D_assert: assert property (@(posedge clk) (A |=> B_C_D));
30
31
32
33
Exercise 5
Re-write the assertion in exercise 4 to:
1. Require that jump_done can assert from 2 to 4 cycles after
branch_done asserts for a
A. Non-overlapped (|=> property
B. An overlapped (|->) property
34
Exercise 4
Re-write the concurrent assertion in exercise 3 to:
1. Specify a default clock
2. Express the sequence, property and assertion separately.
default clocking cb @(negedge clk); endclocking
sequence jump_done_seq;
##2 jump_done; or ##1 jump_done if using |=> on property
endsequence
property branch_done_prop;
(branch_inst |-> jump_done_seq);
endproperty
branch_done: assert property (branch_done_prop);
35
Goto Repetition
The [ operator indicates that the sequence is consecutive
(B ##1 C[*3] ##1 D);
The [-> operator indicates that the sequence may not be consecutive
sequence B_C_D;
(B ##1 C[->3] ##1 D);
endsequence
A_B_C_D_assert: assert property (@(posedge clk) (A |=> B_C_D));
36
Non-Consecutive Repetition
[-> indicates that the sequence must continue on the last match
(B ##1 C[->3] ##1 D);
37
Sequences
SystemVerilog sequence operators
[* ] [= ] [-> ]
##
throughout
within
intersect
and
or
A sequence can be declared in
A module
An interface
A program
A clocking block
A package
A compilation-unit scope
Class 12 Copyright 2009 Greg Tumbush
38
39
Sequences (cont.)
within
One sequence can fully contain another sequence
40
Sequences (cont.)
intersect
Sequences must start at the same tie and end at the same
time. Match done at end time.
41
Sequences (cont.)
and
Sequences must start at same time and end at any time.
Match is done after last sequence has ended.
or
Sequence must start at the same time and can end at any
time. Match done at both sequences ends.
42
43