Sva FV Tutorial HVC2013
Sva FV Tutorial HVC2013
ASSERTIONS FOR
FORMAL VERIFICATION
Dmitry Korchemny, Intel Corp.
November 4, 2013
HVC2013
November 4, 2013
HVC2013
Agenda
Introduction
Formal verification model. LTL properties
Assertion statements
Sequences and properties
Clocks and resets
Assertion system functions
Metalanguage and checkers
Local variables
Recursive properties
Efficiency and methodology tips
Future directions and challenges
November 4, 2013
HVC2013
INTRODUCTION
November 4, 2013
HVC2013
DUT
(RTL)
November 4, 2013
HVC2013
November 4, 2013
HVC2013
November 4, 2013
HVC2013
November 4, 2013
HVC2013
FORMAL VERIFICATION
MODEL. LTL PROPERTIES
November 4, 2013
HVC2013
10
[Pnu77]
November 4, 2013
HVC2013
11
Default clocking
defines the
default clock for
assertions
endmodule : m
$global_clock
is explicit
designation of
global clock
November 4, 2013
HVC2013
12
[Kr63]
November 4, 2013
HVC2013
13
= ,
= , , , ,
=
November 4, 2013
HVC2013
Symbolic Representation
Each variable is represented as a pair:
Current value (its value at the current time moment):
Next value (its value at the next time moment):
Each set and relation is represented by its characteristic
function
E.g., =
14
November 4, 2013
15
HVC2013
traces
Specification language describes the properties of these
traces module m(input logic clk, i, output logic o);
global clocking @(posedge clk); endclocking
default clocking @$global_clock; endclocking
always @(posedge clk) o <= !i;
assert property (i |=> !o);
endmodule : m
Feasible
traces
Infeasible
trace
November 4, 2013
HVC2013
16
false
Properties have a starting point (t), but no end point
Boolean property: e
0
e
2
p
t+1
November 4, 2013
17
HVC2013
November 4, 2013
18
HVC2013
Compound Properties
True from next moment: nexttime always p
p
November 4, 2013
Boolean Connectives
Negation: not p
Conjunction: p and q
Disjunction: p or q
Implication: p implies q
Equivalence: p iff q
Condition: if (e) p else q
Case
HVC2013
19
November 4, 2013
HVC2013
20
Counterexample
Counterexample trace witnessing a property failure
In general case infinite
May be finite
Meaning that any infinite extension of this finite trace is a
counterexample
November 4, 2013
21
HVC2013
[AS87, KV01]
Safety properties
All their counterexample are finite
E.g., always e
!e
t
Liveness properties
All their counterexamples are infinite
E.g., s_eventually e
!e
!e
!e
!e
!e
!e
!e
!e
!e
!e
!e
November 4, 2013
22
HVC2013
Safety
(General)
liveness
Overlapping until
p until_with q if q does not happen, p holds forever
p s_until_with q q must eventually happen
p
0
p
p and q
Safety
(General)
liveness
November 4, 2013
HVC2013
23
Bounded Versions
Property
Semantics
[s_]nexttime [m] p
[s_]nexttime [s_]nexttime p
[s_]eventually [m:n] p
s_eventually [m:$] p
[s_]always [m:n] p
always [m:$] p
November 4, 2013
HVC2013
24
ASSERTION STATEMENTS
November 4, 2013
HVC2013
25
Assertion Kinds
Assertions
Clocked
Concurrent
Unclocked
Immediate
Deferred
2009
Final
2012
November 4, 2013
HVC2013
26
November 4, 2013
27
HVC2013
Assertion Placement
Inside initial procedure execute only once
Outside of initial procedure execute continuously
Once
initial
assert property(p);
Expresses pure
semantics, but
rarely used
assert property(p);
Implicit always
p is always true
assert property(ok);
Every clock
tick
always p is true at time 0
ok is always high
November 4, 2013
HVC2013
Assertions
Specify requirements from DUT
FV
Mathematically proves assertion correctness
DV
Checks assertion correctness for given simulation trace
28
November 4, 2013
HVC2013
29
Assumptions
Specify requirements from environment
FV
Restricts the set of feasible traces in the model
DV
Checks assertion correctness for given simulation trace
assume property (in == !inv_in)
else $error(Inputs in and inv_in are expected to be inverse);
November 4, 2013
HVC2013
Restrictions
Specify condition for which FV has been performed
FV
Restricts the model
Same as assumption
DV
Completely ignored
30
November 4, 2013
HVC2013
31
Cover
Specify scenario you wish to observe
FV
Mathematically prove that the property holds on some feasible
trace
DV
Capture scenario in simulation trace
cover property (read[*2]);
passes
fails
November 4, 2013
HVC2013
32
November 4, 2013
HVC2013
33
Sampling
Signal values are sampled at the beginning of simulation
tick
Time Step
sample here
sig
clock
November 4, 2013
HVC2013
SEQUENCES AND
PROPERTIES
34
November 4, 2013
HVC2013
35
Sequence
Informal definition
Sequence is a rule defining a series of values in time
A sequence does not have a truth value, it has one initial
November 4, 2013
HVC2013
36
Example
Read is followed by write in one or two clock ticks
read ##[1:2] write
Let starting point of this sequence be t = 2
No match
Single match at 3
Single match at 4
2
November 4, 2013
HVC2013
37
Boolean Sequence
Boolean expression e defines the simplest sequence a
Boolean sequence
This sequence has a match at its initial point if e is true
Otherwise, it does not have any satisfaction points at all
November 4, 2013
HVC2013
38
Sequence Concatenation
Sequence concatenation: r ##1 s
There is a match of sequence r ##1 s if there is a match of
sequence r and there is a match of sequence s starting from the
clock tick immediately following the match of r
In other words, a finite trace matches r ##1 s iff it can be split into two
adjacent fragments, the first one matching r, and the second one
matching s.
November 4, 2013
HVC2013
39
Sequence Fusion
Sequence fusion r ##0 s is an overlapping concatenation
The fusion of sequences r and s, is matched iff for some match of
sequence r there is a match of sequence s starting from the clock
tick where the match of r happened
November 4, 2013
HVC2013
40
clock ticks)
November 4, 2013
HVC2013
41
Sequence Disjunction
Sequence disjunction r or s is a sequence which has a
November 4, 2013
HVC2013
Consecutive Repetition
Repetition
r[*0] is an empty sequence
If n > 0 (const.)
r[*n] r[*n-1] ##1 r
<n
42
November 4, 2013
HVC2013
43
November 4, 2013
HVC2013
44
November 4, 2013
HVC2013
45
Delay Ranges
r ##[0:0] s r ##0 s
r ##[m:n] s (r ##1 1[*m-1:n-1] ##1 s), where n m > 0
r ##[0:n] s (r ##0 s) or (r ##[1:n] s), where n > 0
r ##[m:$] s (r ##1 1[*m-1:$] ##1 s), where m > 0
r ##[0:$] s (r ##0 s) or (r ##[1:$] s), where n > 0
##[m:n] s 1 ##[m:n] s, where n m 0
##[m:$] s 1 ##[m:$] s, where m 0
Shortcuts (SVA 2009)
##[*] ##[*0:$]
##[+] ##[*1:$]
November 4, 2013
HVC2013
46
November 4, 2013
HVC2013
47
Sequential Property
Strong sequential property
strong(s) is true in clock tick i iff sequence s with initial point i has
a match
Sequence s should not admit an empty match
Weak sequential property
weak(s) is true in clock tick i iff there is no finite trace fragment i : j
witnessing inability of sequence s with the initial point i to have a
match.
Sequence s should not admit an empty match
In assertions, assumptions and restrictions weak may be
omitted
In cover statements strong may be omitted
November 4, 2013
HVC2013
(strong(rst[*2]));
48
November 4, 2013
HVC2013
49
Suffix Implication
A suffix implication is a property built from a sequence (s)
November 4, 2013
HVC2013
Examples
Request must be granted
1. assert property (req |-> s_eventually gnt);
2. assert property (req |=> s_eventually gnt);
Both assertions allow sending one grant to multiple requests
Request must be granted in 3 cycles
1. assert property (req |-> ##3 gnt); or
2. assert property (req |=> ##2 gnt);
Request must be active until grant is asserted
1. assert property(req |-> req until grant);
2. assert property(req |-> req until_with grant);
3. assert property(req |-> req s_until grant);
4. assert property(req |-> req s_until_with grant);
Two consecutive alerts must be followed by reset
assert property (alert[*2] |=> reset);
50
November 4, 2013
HVC2013
51
Vacuity
What do we check in previous assertions if requests
[Ar03]
November 4, 2013
HVC2013
52
Suffix Conjunction
A suffix conjunction is a property built from a sequence (s)
always high
Fails if rst is
always high
November 4, 2013
CLOCKS
HVC2013
53
November 4, 2013
HVC2013
54
Clocks
Assertion clock should be explicitly written or inferred from
November 4, 2013
HVC2013
55
Clock Rewriting
Unless clock is not inferred as a system clock (=global
November 4, 2013
HVC2013
56
Clock Fairness
Clock is fair if it ticks infinitely many times
Without any preliminary knowledge clock fairness is not
guaranteed
Clock may stop ticking at some moment
November 4, 2013
HVC2013
57
November 4, 2013
HVC2013
58
November 4, 2013
HVC2013
59
November 4, 2013
HVC2013
60
Example
s_nexttime always p
Clock should tick at least twice and p should true at each clock tick
November 4, 2013
HVC2013
61
November 4, 2013
RESETS
HVC2013
62
November 4, 2013
HVC2013
63
Synchronous
sync_accept_on
sync_reject_on
November 4, 2013
HVC2013
64
Aborts
Asynchronous aborts
Ignore the actual clock
Checked at each time step
Synchronous aborts
Checked at clock ticks only
Informal semantics
accept_on (cond) p, sync_accept_on (cond) p
True if there is no evidence of the failure of p before the abort condition
November 4, 2013
HVC2013
65
November 4, 2013
HVC2013
66
November 4, 2013
HVC2013
67
November 4, 2013
HVC2013
68
Disable Clause
Syntax
disable iff (expression)
Specifies top-level assertion reset
At most one in the entire assertion
In FV may be regarded as accept_on in assertions and
sampled
November 4, 2013
HVC2013
69
disable condition
module m (input logic reset, rst, req, gnt, clk, );
default disable iff reset;
a1: assert property (@(posedge clk) req |=> gnt);
a2: cover property (@(posedge clk) req ##1 gnt);
a3: assert property (@(posedge clk) disable iff (1b0) a |=> b);
a4: assert property (@(posedge clk) disable iff (rst) a |=> b);
endmodule : m
November 4, 2013
HVC2013
ASSERTION SYSTEM
FUNCTIONS
70
November 4, 2013
71
HVC2013
Description
$onehot0
$onehot
$countones
$countbits
$isunknown
November 4, 2013
HVC2013
Description
$sampled
$past
$rose
$fell
$changed
$stable
72
November 4, 2013
HVC2013
73
November 4, 2013
HVC2013
74
November 4, 2013
HVC2013
75
$past(e,,,@clk)!== $sampled(e)
$stable(e, @clk)
$past(e,,,@clk)=== $sampled(e)
November 4, 2013
HVC2013
76
November 4, 2013
HVC2013
METALANGUAGE
77
November 4, 2013
HVC2013
78
Let Declaration
let identifier [(port, port, )] = expression;
Typical usage
Templates for Boolean assertions
Instrumental code
Does not introduce new variables
Visible to debuggers
November 4, 2013
HVC2013
Let Example
module m (input logic clk, rst, );
logic mod1, mod2;
logic req1, req2;
logic rsp;
let req = mod1 & req1 | mod2 & req2;
let gnt = $changed(rsp);
a: assert property (@(posedge clk) disable iff (rst) req |=> gnt);
endmodule : check
79
November 4, 2013
HVC2013
80
November 4, 2013
CHECKERS
HVC2013
81
November 4, 2013
HVC2013
Checkers
Checkers are SystemVerilog containers to package
verification code
Both assertions and modeling
assertion
May contain (almost) the same constructs as a module
Is instantiated as a property (in place)
Placed as an assertion
Acts as an assertion with complex internal implementation
82
November 4, 2013
83
HVC2013
If start is high, then start must be low in the next cycle and remain low until after the next strictly
complete may not be high unless start was high in a preceding cycle and complete was not high in any of
start
complete
dataIn
dataOut
November 4, 2013
HVC2013
84
November 4, 2013
HVC2013
85
Checker Binding
module top;
logic clock, snda, sndb, sndc, rcva, rcvb, rcvc;
...
trans ta (clock, snda, rcva);
trans tb (clock, sndb, rcvb);
trans #(2) tc (clock, sndc, rcvc);
endmodule : top
checker eventually_granted (req, gnt, );
endchecker : eventually_granted
checker request_granted (req, gnt, n, );
endchecker : request_granted
module trans #(DEL=1) (input logic clock, in, output logic out);
if (DEL == 1) begin : b
always @(posedge clock) out <= in;
end
else begin : b
logic [DEL - 2: 0] tmp;
always @(posedge clock) begin
tmp[0] <= in;
for (int i = 1; i < DEL - 1; i++) tmp[i] <= tmp[i-1];
out <= tmp[DEL - 2];
end
end
endmodule : trans
November 4, 2013
HVC2013
86
Free Variables
Checker may have free variables
Behave non-deterministically (like free or constrained inputs)
FV: consider all possible values imposed by assumptions and
assignments
Simulation: their values are randomized
Free variable values are never sampled
Limitations
Continuous and blocking assignments to free variables are illegal
rand bit r;
bit [2:0] x;
rand bit a;
always_ff @clk a <= !a;
November 4, 2013
HVC2013
Rigid Variables
Rigid variables = constant free variables
Rigid
variable
87
November 6, 2013
Intel Confidential
88
November 6, 2013
Intel Confidential
89
In simulation module
input signals are
randomized remaining
mutually exclusive
endmodule : m
module top();
logic clock, n1, n2;
November 4, 2013
HVC2013
LOCAL VARIABLES
90
November 4, 2013
HVC2013
91
Informal Definition
Local variable is a variable associated with an evaluation attempt
Local variables are not sampled
November 4, 2013
HVC2013
92
Example
Check that the value of dataIn when start is high
If n is not const
property data_check;
var type(n) ctr;
(start, ctr = n - 1) ##1 (ctr > 0, ctr--)[*] ##1 (ctr == 0)
|-> dataOut = dataIn;
endproperty : data_check
assert property (data_check);
November 4, 2013
HVC2013
93
are not
Rigid variables are FV friendly their implementation is
straightforward
Efficient implementation of local variables in FV is challenging
November 4, 2013
HVC2013
94
RECURSIVE PROPERTIES
November 4, 2013
HVC2013
95
Recursive Properties
Properties may be recursive
property prop_always (p) ;
p and nexttime prop_always (p);
endproperty
initial assert property (@(posedge clk) prop_always (ok));
property prop_weak_until (p, q);
q or (p and nexttime prop_weak_until (p, q));
endproperty
initial assert property (@(posedge clk) prop_weak_until (req, gnt));
November 4, 2013
HVC2013
EFFICIENCY AND
METHODOLOGY TIPS
96
November 4, 2013
HVC2013
97
November 4, 2013
HVC2013
98
!c
true
a
true
a
!c
!c
November 4, 2013
HVC2013
99
November 4, 2013
HVC2013
100
Clock is fair
Strong operators
have clumsier
syntax to prevent
inadvertent
usage
Liveness assertion
is usually better
than a safety
assertion with a
large time window
November 4, 2013
101
HVC2013
s_nexttime always p
nexttime s_eventually p
nexttime always p
s_nexttime s_eventually p
always s_eventually p
November 4, 2013
HVC2013
102
November 4, 2013
103
HVC2013
Intersection Family
Sequence operators from intersection family (intersect, and, within)
are expensive
These operators are not inefficient by themselves, but allow to concisely
Each transaction should contain two read requests and three write requests
Common case
expensive
This is rather
efficient
November 4, 2013
HVC2013
104
Assertion Clock
Assertions governed by a global clock are more efficient
true
!c
!@clk
a & @clk
!@clk
b & @clk
!c & @clk
FV tools may automatically infer the global clock from a singly clocked design
November 4, 2013
HVC2013
105
FV
Implementing local variables is tricky
Important advantage of local variables
Allow checking assertions in simulation
November 4, 2013
HVC2013
106
November 4, 2013
HVC2013
107
deterministically
Overlapping transactions usually require nondeterministic
modeling
E.g., local or rigid variables
Compare:
Sequential protocol vs.
property p_data_check;
var type(dataIn) data;
(start, data = dataIn) ##1 complete[->1] |->
dataOut == data;
endproperty : p_data_check
November 4, 2013
HVC2013
108
Be More Specific
Being more specific usually pays off. Check only what you
really need
Dont check for eventuality unless this is essential
If events are ordered in a sequence specify this order explicitly
If you know that transactions do not overlap model this fact
explicitly
November 4, 2013
HVC2013
109
inconsistent
Especially when assertion simulation has a transaction-based
implementation
E.g.
Infinite ranges and repetitions are efficient in FV, but not in
simulation
Sequence intersection is efficient in simulation, but not in FV
Liveness does not cost in simulation
Future value functions are more efficient than past value functions
in FV. The situation with simulation is opposite
Local variables are rather efficient in simulation, but not in FV
November 4, 2013
HVC2013
110
November 4, 2013
HVC2013
111
November 4, 2013
HVC2013
112
Standard Packages
SVA provides basic assertion capabilities and some
sugaring
There are many useful properties and functions that could be
November 4, 2013
HVC2013
113
Assertion Libraries
Using SVA checker mechanism it is possible to create a
November 4, 2013
HVC2013
114
AMS Assertions
AMS = Analog and Mixed Signals
The intention is to merge SystemVerilog and Verilog-AMS
This includes development of AMS assertions and including them
into SVA
The initial step was done in SV2012: real type support in SVA
No continuous time support yet
November 4, 2013
HVC2013
TLM Assertions
SVA covers RTL assertions
TLM assertions are different
Unclocked or approximately clocked
SVA is too low level for TLM
Need to extend SVA to cover TLM needs
115
November 4, 2013
HVC2013
116
correctness
Part of TB
Uses completely different mechanism, does not explore the
strength of assertions
Implemented as class methods
Challenge
Checkers currently cannot be instantiated in classes
Need to enhance them to allow their usage in UVM
November 4, 2013
HVC2013
BIBLIOGRAPHY
117
November 4, 2013
HVC2013
118