Professional Documents
Culture Documents
Assertions
by
Pankaj Badhe
12/19/2011
Pankaj Badhe
AGENDA
Introduction to SVA
Immediate and Concurrent Assertions
Building blocks
SVA Coverage
Binding
SVA Examples
12/19/2011
Pankaj Badhe
SVA Introduction
Assertions are primarily used to validate the
behaviour of a design. ("Is it working correctly?")
They may also be used to provide functional
coverage information for a design ("How good is
the test?").
Assertions can be checked dynamically by
simulation.
12/19/2011
Pankaj Badhe
Examples of Assertions
Captures
Correct/Illegal behaviours
Assumptions/Constraints
Coverage Targets
Examples
Combo
An event should never/always occur.
A FSM State is always onehot encoded.
Temporal expressions
Event A is followed by event B
While ABC is true, sequence P->Q->R should never occur.
12/19/2011
Pankaj Badhe
For whom
Design Engineers
Capture design assumptions
Record intentions/error conditions
Behaviour (mutex, one-hot, never, always etc.)
Verification engineers
Interface, cross block, higher level behaviour.
12/19/2011
Pankaj Badhe
Interfaces.
Inside RTL modules.
Inside Testbenches.
Inside Protocol Monitors.
12/19/2011
Pankaj Badhe
Pankaj Badhe
12/19/2011
Pankaj Badhe
// SVA
SVA Checker
Checker
a_to_b_chk:
assert property
@ (posedge clk)
$rose(a) |-> ##[1:3] $rose(b) );
Pankaj Badhe
Results
SUCCESS: b arrived in time 127
vtosva.a_to_b_chk:
started at 125s succeeded at 175s
SUCCESS: b arrived in time 427
vtosva.a_to_b_chk:
started at 325s succeeded at 475s
ERROR: b did not arrive in time 775
vtosva.a_to_b_chk:
started at 625s failed at 775s
Offending '$rose(b)'
12/19/2011
Pankaj Badhe
10
SystemVerilog Scheduling
Preponed - Values are sampled for the assertion
variables in this region. In this region, a net or
variable cannot change its state. This allows the
sampling of the most stable value at the beginning
of the time slot.
Observed - All the property expressions are
evaluated in this region.
Reactive - The pass/fail code from the evaluation of
the properties are scheduled in this region.
12/19/2011
Pankaj Badhe
11
12/19/2011
Pankaj Badhe
12
Immediate Assertions
Immediate assertions are procedural statements and
are mainly used in simulation. An assertion is
basically a statement that something must be true,
similar to the if statement. The difference is that an
if statement does not assert that an expression is
true, it simply checks that it is true, e.g.:
if (A == B) ... // Simply checks if A equals B
assert (A == B);
// Asserts that A equals B; if
not, an error is generated
12/19/2011
Pankaj Badhe
13
assert (A == B)
$display ("OK. A equals B");
else $error("It's gone wrong");
Note that you can omit the pass statement and still
have a fail statement:
assert (A == B)
else $error("It's gone wrong");
12/19/2011
Pankaj Badhe
14
AeqB: assert (a == b)
else
begin
error_count++;
$error("A should equal B");
end
12/19/2011
Pankaj Badhe
15
Another example
The always block executes
if either signal "a" or
signal "b" changes.
12/19/2011
Pankaj Badhe
16
Building Blocks
Properties and Sequences
The properties being asserted are specified in the
assert property statements themselves. Properties
may also be declared separately, for example:
property not_read_and_write;
not (Read && Write);
endproperty
assert property (not_read_and_write);
12/19/2011
Pankaj Badhe
17
sequence acknowledge
##[1:2] Ack;
endsequence
12/19/2011
Pankaj Badhe
18
property handshake;
@(posedge Clock) request |-> acknowledge;
endproperty
assert property (handshake);
12/19/2011
Pankaj Badhe
19
12/19/2011
Pankaj Badhe
20
Concurrent Assertions
12/19/2011
Pankaj Badhe
21
Another example
a_cc: assert property ( @ (posedge clk) not (a && b));
All successes are shown with an up arrow and all failures
are shown with a down arrow. The key concept in this
example is that the property is being verified on every
positive edge of the clock irrespective of whether or not
signal "a" and signal "b" changes.
12/19/2011
Pankaj Badhe
22
Implication
The implication construct (|->) allows a user to
monitor sequences based on satisfying some
criteria, e.g. attach a precondition to a sequence
and evaluate the sequence only if the condition is
successful. The left-hand side operand of the
implication is called the antecedent sequence
expression, while the right-hand side is called the
consequent sequence expression.
12/19/2011
Pankaj Badhe
23
Implication
If there is no match of the antecedent sequence
expression, implication succeeds vacuously by
returning true. If there is a match, for each
successful match of the antecedent sequence
expression, the consequent sequence expression is
separately evaluated, beginning at the end point of
the match.
12/19/2011
Pankaj Badhe
24
Implication
There are two forms of implication: overlapped
using operator |->, and non-overlapped using
operator |=>.
For overlapped implication, if there is a match for
the antecedent sequence expression, then the first
element of the consequent sequence expression is
evaluated on the same clock tick.
s1 |-> s2;
In the example above, if the sequence s1 matches,
then sequence s2 must also match. If sequence s1
does not match, then the result is true.
12/19/2011
Pankaj Badhe
25
Pankaj Badhe
26
12/19/2011
Pankaj Badhe
27
12/19/2011
Pankaj Badhe
28
Pankaj Badhe
29
12/19/2011
Pankaj Badhe
30
12/19/2011
Pankaj Badhe
31
Sequence Expressions
12/19/2011
Pankaj Badhe
32
12/19/2011
Pankaj Badhe
33
Assertion Clocking
Concurrent assertions (assert property and cover
property statements) use a generalised model of a
clock and are only evaluated when a clock tick
occurs.
A clock tick is an atomic moment in time and a clock
ticks only once at any simulation time. The clock
can actually be a single signal, a gated clock (e.g.
(clk && GatingSig))
The clock for a property can be specified in several
ways:
12/19/2011
Pankaj Badhe
34
12/19/2011
Pankaj Badhe
35
12/19/2011
Pankaj Badhe
36
12/19/2011
Pankaj Badhe
37
12/19/2011
Pankaj Badhe
38
Forbidding a property
12/19/2011
Pankaj Badhe
39
12/19/2011
Pankaj Badhe
40
The ## operator delays execution by the specified number of clocking events, or clock
cycles.
a ##1 b // a must be true on the current clock tick
// and b on the next clock tick
a ##N b // Check b on the Nth clock tick after a
12/19/2011
Pankaj Badhe
41
12/19/2011
Pankaj Badhe
42
12/19/2011
Pankaj Badhe
43
Repetition
The * operator is used to specify a consecutive
repetition of the left-hand side operand.
a ##1 b [*3] ##1 c // Equiv. to a ##1 b ##1 b ##1 b ##1 c
(a ##2 b) [*2]
// Equiv. to (a ##2 b ##1 a ##2 b)
(a ##2 b)[*1:3]
// Equiv. to (a ##2 b)// or (a ##2 b ##1 a
##2 b)
// or (a ##2 b ##1 a ##2 b ##1 a ##2 b)
12/19/2011
Pankaj Badhe
44
12/19/2011
Pankaj Badhe
45
Pankaj Badhe
46
Pankaj Badhe
47
12/19/2011
Pankaj Badhe
48
Pankaj Badhe
49
Pankaj Badhe
50
Pankaj Badhe
51
12/19/2011
Pankaj Badhe
52
12/19/2011
Pankaj Badhe
53
12/19/2011
Pankaj Badhe
54
Combining Sequences
s1 and s2 // Succeeds if s1 and s2 succeed. The end time is the
// end time of the sequence that terminates last.
If s1 and s2 are sampled booleans and not sequences, the
expression above succeeds if both s1 and s2 are evaluated
to be true.
s1 intersect s2 // Succeeds if s1 and s2 succeed and if end
// time of s1 is the same with the end time of
// s2
12/19/2011
Pankaj Badhe
55
Pankaj Badhe
56
12/19/2011
Pankaj Badhe
57
Pankaj Badhe
58
Pankaj Badhe
59
When the property p30 gets evaluated, the first one to match
will be kept and every other match will be discarded.
sequence s30a;
@ (posedge clk) a ##[1:3] b;
endseguence
sequence s3 0b;
@ (posedge clk) c ##[2:3] d;
endsequence
property p3 0;
@(posedge clk) first_match(s3 0a or s3 0b);
Endproperty
a30: assert property(p30) ;
12/19/2011
Pankaj Badhe
60
Pankaj Badhe
61
12/19/2011
Pankaj Badhe
62
12/19/2011
Pankaj Badhe
63
Pankaj Badhe
64
12/19/2011
Pankaj Badhe
65
property p_lvar_accum;
int Ivar;
@(posedge clk) $rose(start)|=>
(enablel ##2 enable2, Ivar = Ivar +aa) [*4]
##1 (stop && (aout == Ivar));
endproperty
a_lvar_accum : assert property(p_lvar_accum);
12/19/2011
Pankaj Badhe
66
12/19/2011
Pankaj Badhe
67
Pankaj Badhe
68
12/19/2011
Pankaj Badhe
69
Pankaj Badhe
70
Pankaj Badhe
71
12/19/2011
Pankaj Badhe
72
This assertion,
assert property (@(posedge clk) enable == 0 |=> $stable(data));
12/19/2011
Pankaj Badhe
73
Deferred assertions
Deferred assertions are an improvement over
immediate assertions. They are similar to
immediate assertions in that they are nontemporal
and unrestricted in their use.
Two important differences make them useful over
immediate assertions: they do not produce
spurious failures, and they can be placed both
inside and outside procedural code.
12/19/2011
Pankaj Badhe
74
12/19/2011
Pankaj Badhe
75
Pankaj Badhe
76
Using let
logic a, b, c, d, cond, clk;
let onecold(sig) = $onehot(sig);
// ...
always_comb begin
// ...
a1: assert (onecold({a, b, c}) || d);
end
a2: assert #0 (onecold({a, b, c}) -> d);
a3: assert property (@(posedge clk) cond |=>
onecold({a, b, c}));
12/19/2011
Pankaj Badhe
77
Pankaj Badhe
78
Nested implication
define f r e e (a && b && c && d)
property p_nest;
@ (posedge clk) $fell(a) |->
##1 (!b && Ic && !d) I->
##[6:10] "free;
endproperty
a_nest: assert property(p_nest);
12/19/2011
Pankaj Badhe
79
Pankaj Badhe
80
Pankaj Badhe
81
12/19/2011
Pankaj Badhe
82
12/19/2011
Pankaj Badhe
83
Coverage Statements
module Amod2(input bit clk);
bit X, Y;
sequence s1;
@(posedge clk) X ##1 Y;
endsequence
Pankaj Badhe
84
Results
The results of the cover statement will provide the following
information:
1. Number of times the property was attempted.
2. Number of times the property succeeded.
3. Number of times the property failed.
4. Number of times the property succeeded vacuously.
A sample coverage log from a simulation for the checker "mutexchk" is
shown below.
Pankaj Badhe
85
12/19/2011
Pankaj Badhe
86
property p_mutex;
(posedge clk) not (a && b);
endproperty
a_mutex: assert property(p_mutex);
endmodule
12/19/2011
Pankaj Badhe
87
If the user decides to keep the SVA checkers separate from the design,
then he has to create a separate checker module. By defining a
separate checker module, the re-usability of the checker increases.
The following code shows a checker module.
module mutex chk(a, b, clk);
input logic a, b, clk;
property p_mutex;
(posedge clk) not (a && b);
endproperty
a_mutex: assert property(p_mutex);
endmodule
Note that when a checker module is defined, it is an independent entity.
The checker is written for a generic set of signals. The checker can be
bound to any module or instance in the design.
12/19/2011
Pankaj Badhe
88
Binding
module M (...);
// The design is modelled here
endmodule
program M_assertions(...);
// sequences, properties, assertions for M go here
endprogram
bind M M_assertions M_assertions_inst (...);
12/19/2011
Pankaj Badhe
89
For the example checker shown above, the binding can be done as
follows.
bind inline mutex_chk i2 (a, b, clk);
When the binding is done, the actual design signal names are used.
Let's say we have a top-level module as follows.
module t o p (. . ) ;
inline ul (clk, a, b, inl, in2, outl);
inline u2 (clk, c, d, in3, in4, out2);
endmodule
The checker mutexchk can be bound to the two instances of the module "inline" in
the top-level module as follows.
bind top.ul mutex_ehk il(a, b, clk);
bind top.u2 mutex_ehk i2(c, d, clk);
The design signals that are bound can contain cross module reference
to any signal within the scope of the bound instance.
12/19/2011
Pankaj Badhe
90
12/19/2011
Pankaj Badhe
91
12/19/2011
Pankaj Badhe
92
12/19/2011
Pankaj Badhe
93
12/19/2011
Pankaj Badhe
94
12/19/2011
Pankaj Badhe
95
12/19/2011
Pankaj Badhe
96
12/19/2011
Pankaj Badhe
97
12/19/2011
Pankaj Badhe
98
12/19/2011
Pankaj Badhe
99