Assertins
Assertins
1) In SV,source code is very compact.No need to write too many lines of codes.
2) No need to write own $display() statement.In case of verilog checker we have to write
$display() statement.
In SV,whenever assertion failed it will automatically print an error message,no need to
write own $display statement.
3) In Verilog,we cant have separate RTL and checker.But in SV ,we can separate them.
Action Blocks :
The system verilog language has been developed in such a way that,every time an
assertions check fails,the simulator is expected to print out an error message by
default.
A user can also print custom error or success message using the “action block” in the
assert statement.
The syntax:
assert property(ppt)
<success message>
1|Page
@shraddha_pawankar Date:25/04/2024
else
<fail_message>
Assertions improves both observability and controllability so that we can trace the cause of
the bug very quickly.
//cover
cover property (@(posedge clk) $rose(start) |-> start[*4:$]);
Types of Assertions :
1) Immediate Assertions
2) Deferred Immediate assertions
3) Concurrent assertions
2|Page
@shraddha_pawankar Date:25/04/2024
Immediate Assertions:
Defined in a procedural block
Immediate assertions check for a condition at the current simulation time.
An immediate assertion is the same as an if..else statement with assertion control.
These are evaluated immediately.
Used only with dynamic simulation.
Unexpected multiple executions(because of glitches in signals)
Examples:
always_comb
begin
a_ia : assert (a && b);
end
The above assertion will be checking for the values a & b if there is an event in either a or b.
The assertion will be failes if a & b are not high at the same time.
3|Page
@shraddha_pawankar Date:25/04/2024
Can be defined inside and outside of a procedural block.
Are a type of Immediate Assertions
Introduced in IEEE 1800-2009 versions of SV.
Better than immediate assertions and avoids multiple execution of assertions in the
same time slot.
Can be defined with ‘#0’ of the keyword ‘final’
Unexpected multiple executions(glitches) in Immediate assertions to avoid this we can
use Deffered Immediate assertions.
Concurrent assertion:
Can be defined in a procedural block or a module or an interface or a program block.
Based on clock cycles
Test expression is evaluated at clock edges based on the sampled values of the variables
involved.
Sampling of variables is done in the preponed region and
Evaluation of expression is done in the observed region of the scheduler.
Can be used with both static(formal) and dynamic verification(simulation) tools.
The keyword that differentiates the immediate assertion from the concurrent assertion
is “ Property”.
Ex:
The above assertion will be checking for the values of a & b,if there is a posedge in the clk.
The assertion will be failed if a and b are high at the same times
4|Page
@shraddha_pawankar Date:25/04/2024
Boolean Expression:
The functionality is represented by the combination of multiple logical events. These
events could be simple Boolean expressions.
Ex:
The above assertion will be checking for the values of a & b,if there is a posedge in the clk.
The assertion will be failed if a and b are high at the same times.
Sequence :
In any design model,the functionality is represented by the combination of multiple
logical events.
These events could be simple Boolean expression that get evaluated on the same clock
edge or could be events that evaluate over a period of time involving multiple clock
cycles.
5|Page
@shraddha_pawankar Date:25/04/2024
SVA provides a key word to represent these events called “sequence”.
The syntax:
sequence <name_of_sequence>;
……
endsequence
Property :
A number of sequences can be combined logically or sequentially to create more
complex sequences.
SVA provides a keyword to represent these complex sequential behaviors called
“property”.
The syntax:
property name_of_property;
endproperty
Assert:
The property is the one that is verified during a simulation. It has to be asserted to take
effect during a simulation.
SVA provides a keyword called “assert” to check the property.
The Syntax:
SVA Sequence :
Boolean expression events that evaluate over a period of time involving single/multiple
clock cycles.
SVA provides a keyword to represent these events called “sequence”.
6|Page
@shraddha_pawankar Date:25/04/2024
sequence seq;
endsequence
In above example a==1 means a is high on every positive edge of the clock.
If the signal is not high on any positive clock edge,the assertion will fail.
Code :
module asertion_ex;
bit clk,a;
//generating 'a'
initial begin
a=1;
#10 a=0;
#15 a=1;
#15 a=0;
#15 a=1;
#10;
$finish;
end
7|Page
@shraddha_pawankar Date:25/04/2024
//assertion sequence
sequence seq_1;
endsequence
//wave dump
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
Waveform:
Ex:
8|Page
@shraddha_pawankar Date:25/04/2024
sequence seq;
@(posedge clk) a || b;
endsequence
Code :
module tb;
bit clk,a,b;
initial begin
a=1; b=1;
#15 a=0;b=0;
#10 a=1; b=0;
#10 a=0; b=0;
#10 a=1; b=1;
#10;
$finish;
end
sequence seq;
@(posedge clk) a||b;
endsequence
a_1:assert property(seq);
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
Sequence seq(a,b);
a && b;
endsequence
The generic sequence seq can be re-used on any two signals as shown below.
sequence sig_34
seq(sig_3,sig_4);
endsequence
sequence sig_12;
seq(sig_1,sig_2);
endsequence
These kind of sequences can be used in one hot state machine checks,parity checks etc.
Since these kind of checks are common in most of the designs.
So far,we have seen simple checks that will be evaluated foe each clock cycle.
But in most of scenarios,we may have to check the events that takes several clock
cycles to complete.
In SVA,clock cycle delays are represented by “##” sign.
For example,##3 means 3 clock cycles.
Example:
sequence seq;
@(posedge clk) a ##2 b;
endsequence
Code:
module tb;
bit clk,a,b;
initial begin
a=1; b=1;
#15 a=0; b=0;
#10 a=1; b=0;
#10 a=0;b=0;
#10 a=1; b=1;
#10;
$finish;
end
sequence seq;
@(posedge clk) a ##2 b;
endsequence
assert property(seq);
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
Waveform:
Note:: sequence begins when signal “a” is high on a positive edge of the clock.
11 | P a g e
@shraddha_pawankar Date:25/04/2024
sequence seq;
@(posedge clk) a ##2 b;
endsequence
Property ppt;
Seq;
Endproperty
Sequence seq;
a ##2 b;
endsequence
property ppt;
@(posedge clk) seq; //best way as we can reuse sequences with other clocks as well.
endproperty
12 | P a g e
@shraddha_pawankar Date:25/04/2024
A1:assert property(ppt);
In general, it is a good idea to define the clocks in property definitions and keep the
sequences independent of the clocks.
This will help increase the re-use of the basic sequence definitions.
sequence seq;
a ##2 b;
endsequence
This the best way as we can reuse sequences with other clocks as well.
Example: Clock defined in assert statement when we define sequence and property
separately.
sequence seq;
a ## 2 b;
endsequence
property ppt;
seq;
endproperty
Default clocking :
Painful to specify clock operator for every assertions
Default clocking block applies to every assertion in the same steps without a
specific clock.
Only 1 default clock per scope allowed.
assert property(cb.p);
property p;
a ##2 b;
endproperty
Implication operator:
Example:
sequence seq;
@(posedge clk) a ##2 b;
endsequence
The implication construct can be used only with property definitions.It cannot be used in
sequences.
Syntax
sequence_exp |-> property_exp
sequence_exp |=> property_exp
The LHS operand sequence_exp is called an antecedent
The RHS operand property_exp is called a consequent
Types of Implication:
1) Overlapped Implication
2) Non-overlapped Implication
14 | P a g e
@shraddha_pawankar Date:25/04/2024
Overlapped Implication:
The overlapped implication operator is denoted by the |-> symbol.
The evaluation of the consequent starts immediately on the same clock cycle if the
antecedent holds true.
The consequent is not evaluated if the antecedent is not true.
Also called as same cycle implication.
The antecedent is the gating condition.
The antecedent succeeds then the consequent is evaluated.
If the antecedent does not succeed,then the property is assumed to succeed by
default.This is called a “Vacuous success”.
Implication is equivalent to an if-then structure.
Code:
module tb;
bit clk,a,b;
initial begin
a=1; b=1;
#10;
$finish;
end
property p;
endproperty
15 | P a g e
@shraddha_pawankar Date:25/04/2024
a1: assert property(p);
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
Code:
module tb;
bit clk,a,b;
16 | P a g e
@shraddha_pawankar Date:25/04/2024
initial begin
a=1; b=1;
#15 a=0; b=0;
#10 a=1; b=0;
#10 a=0; b=0;
#10 a=1; b=1;
#10;
$finish;
end
property p;
@(posedge clk) a |=> b;
endproperty
initial begin
$dumpfile("dump.vcd");
$dumpvars();
end
endmodule
From the above property checks that,if signal “a” is high on a given positive clock edge,then
signal “b” should be high after 2 clock cycles.
17 | P a g e
@shraddha_pawankar Date:25/04/2024
Code:
module tb;
bit clk,a,b;
initial begin
a=1; b=1;
#15 a=0; b=0;
#10 a=1; b=0;
#10 a=0; b=0;
#10 a=1; b=1;
#10;
$finish;
property p;
@(posedge clk) a |-> ##2 b;
endproperty
Above property checks that,if signal “a” is high on given positive clock edge,then within 1 yo 4
clock cycles,the signal “b” should be high.
Code :
module tb;
bit clk,a,b;
initial begin
a=1; b=1;
#15 a=0; b=0;
#10 a=1;b=0;
#10 a=0; b=0;
#10 a=1; b=1;
#10;
$finish;
end
property p;
@(posedge clk) a |-> ##[1:4] b;
endproperty
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
19 | P a g e
@shraddha_pawankar Date:25/04/2024
From the above property checks that, if signal “a” is high on a given positive clock edge,then
signal “b” should be high in the same clock cycle or within 4 clock cycles.
Code:
module tb;
bit clk,a,b;
initial begin
a=1; b=1;
property p;
@(posedge clk) a|-> ##[0:4] b;
endproperty
20 | P a g e
@shraddha_pawankar Date:25/04/2024
A1:assert property(p);
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
Example:
property p;
@(posedge clk) a |-> ##[1:5] b;
endproperty
a1: assert property(p);
From above property checks that,if signal “a” is high on a given positive clock edge,then signal
“b” will be high eventually starting from the next clock cycle.
Code:
module tb;
bit clk,a,b;
initial begin
a=1; b=1;
#15 a=0; b=0;
#10 a=1;b=0;
#10 a=0; b=0;
21 | P a g e
@shraddha_pawankar Date:25/04/2024
#10 a=1;b=1;
#10;
$finish;
end
property p;
@(posedge clk) a |-> ##[1:$] b;
endproperty
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
Operators in Assertions:
Clock delays:
## : represents cycle delay
2. ##n – represents “n” clock cycles
3. ##0 – represents same clock cycle
4. ## [min:max] represents a range of clock cycles. Where min and max must be 0 or
greater than 0.
Example 1:
sequence seq;
@(posedge clk) a ##[2:6] b;
endsequence
The sequence will be matched if a is true when within clock cycle delay of range 2 to 6,b should
be high.
Example 2:
22 | P a g e
@shraddha_pawankar Date:25/04/2024
sequence seq;
@(posedge clk) a ## [2:$] b;
endsequence
The sequence will be matched if a is true then b can be high at any time before simulation
ends.
Repetition Operator:
If the sequence of events happens repeatedly for n times and it is represented as [*n]
Where “n”>0
“n” can not be $.
Example:
sequence seq;
@(posedge clk) req1 ##1 req2[*3];
endsequence
In this example,if req1 is true then after 1 clock cycle,req2 must be true for 3
consecutive clock cycles.
Req1 ##1 req[*3] = req1 ##1 req2 ##1 req2 ##1 req2.
Waveform:
23 | P a g e
@shraddha_pawankar Date:25/04/2024
Example 2:
sequence seq;
@(posedge clk) req1 ##1 req2[*2:4];
endsequence
The repetition operator can also be used in a certain range using [*m:n]
Where “m” and “n” >0.
And n cannot be $.
In this example,if req1 is true then after 1 clock cycle,req2 must be true for a minimum of 2
and maximum of 4 consecutive clock cycles.
In the above example,once req1 holds true after one clock cycle req2 must be true for 4 clock
cycles but it is not mandatory to consecutive clock cycles.
Example :
sequence seq;
@(posedge clk) req1 ##1 req2[=2:4];
endsequence
24 | P a g e
@shraddha_pawankar Date:25/04/2024
In above example,once req1 holds true after one clock cycle ,req2 must be true for a minimum
of 2 and a maximum of 4 clock cycles but it is not mandatory to be consecutive clock cycles.
SVA Methods:
Sequence with edge Detection:
SVA also has built-in edge detection mechanism that allows the user monitor the
transition of signal value from one clock cycle to the next.
The system functions available for detecting edges are
$rose
$fell
$stable
$rose :
This returns true if LSB of signal/expression is changed to 1 and remains 1 in the current
evaluation point.
The system task $rose is used to detect a positive edge of the given signal.
Syntax:
$rose(Boolean expression or signal name);
Example:
sequence s1;
@(posedge clk) $rose(a);
endsequence
Code:
module tb;
bit a;
bit clk;
25 | P a g e
@shraddha_pawankar Date:25/04/2024
always #5 clk=~clk;
initial begin
a=1;
#15 a=1;
#10 a=1;
#10 a=1;
#10 a=1;
#10 a=1;
#15 a=0;
#10 a=1;
#10;
$finish;
end
sequence seq;
endsequence
assert property(seq);
initial begin
$dumpfile("dump.vcd");
26 | P a g e
@shraddha_pawankar Date:25/04/2024
$dumpvars;
end
endmodule
Waveform:
$fell :
This returns true if LSB of signal/expression is changed to 0 and remains 0 in the current
evaluation time.
The system task $fell is used to detect negative edge of the given signal.
Syntax:
$fell(Boolean expression or signal name)
Returns true if the LSB of the expression changed to 0.otherwise,it returns false
Example:
sequence seq;
@(posedge clk) $fell(a);
endsequence
always #5 clk=~clk;
27 | P a g e
@shraddha_pawankar Date:25/04/2024
initial begin
a=1;
#15 a=1;
#10 a=1;
#10 a=1;
#10 a=1;
#10 a=1;
#15 a=0;
#10 a=1;
#10;
$finish;
end
sequence seq;
@(posedge clk) $fell(a);
endsequence
assert property(seq);
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
$stable:
This returns true if the value of the expression did not change in the current evaluation
point and previous evaluation point.
28 | P a g e
@shraddha_pawankar Date:25/04/2024
Syntax:
$stable(Boolean expression or signal name)
Returns true if the value of the expression did not change.otherwise,it returns false.
Example:
sequence seq;
@(posedge clk) $stable(a);
endsequence
Sequence seq checks that the signal “a” is stable on every positive edge of the clock.
If there is any transition occurs,the assertion will fail.
Code:
module tb;
bit a;
bit clk;
always #5 clk=~clk;
initial begin
a=1;
#15 a=1;
#10 a=1;
#10 a=1;
#10 a=1;
#10 a=1;
#15 a=0;
#10 a=1;
#10;
$finish;
end
sequence seq;
29 | P a g e
@shraddha_pawankar Date:25/04/2024
@(posedge clk) $stable(a);
endsequence
assert property(seq);
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
$past
It is capable of getting values of signals from previous clock cycles.
Syntax:
$past(signal_name,number of clock cycles)
Provides the value of the signal from the previous clock cycle.
Example:
property p;
@(posedge clk) b |-> ($past(a,2) == 1);
endproperty
A1: assert property(p);
Below property checks that,in the given positive clock edge,if the “b” is high,then 2 cycles
before that,a was high.
Code:
module tb;
30 | P a g e
@shraddha_pawankar Date:25/04/2024
bit clk,a,b;
initial begin
a=1; b=1;
#15 a=0; b=0;
#10 a=1; b=0;
#10 a=0; b=0;
#10 a=1; b=1;
#10;
$finish;
end
property p;
@(posedge clk) b |-> ($past(a,2) == 1);
endproperty
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
31 | P a g e
@shraddha_pawankar Date:25/04/2024
Syntax:
$past(signal_name,number of clock cycles,gating signal)
Example:
property p;
@(posedge clk) b|->($past(a,2,c) == 1);
endproperty
a1:assert property(p);
Above the property checks that,in the given positive clock edge,if the “b” is high,then 2 cycles
before that, a was high only if the gating signal “c” is valid on any given positive edge of the
clock.
Code:
module tb;
bit clk,a,b,c;
//generating 'a'
initial begin
a=1; b=1;
#15 a=0; b=0;
#10 a=1; b=0;
#10 a=0; b=0;
#10 a=1; b=1;
#10;
$finish;
end
property p;
@(posedge clk) b |-> ($past(a,2,c) == 1);
endproperty
32 | P a g e
@shraddha_pawankar Date:25/04/2024
//wave dump
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
Syntax:
$countones(expression)
Example:
sequence seq;
@(posedge clk) $countones(a);
endsequence
$isunknown:
Checks if any bit of the expression is X or Z.
Syntax:
$isunknown(expression)
Example:
33 | P a g e
@shraddha_pawankar Date:25/04/2024
sequence seq;
@(posedge clk) $isunknown(a);
endsequence
Checks whether the vector has a bit with value ‘X’ or ‘Z’.
Returns a Boolean true if any bit in the argument passed is X or Z.
$onehot:
Returns 1 if only one bit is high in an expression.
Syntax:
$onehot(expression);
$onehot0:
Returns 1 if all the bits are zero or only one bit is 1 in an expression.
Syntax:
$onehot0(expression);
Disable iff:
If certain design condition,we don’t want to proceed with the check if some condition is
true,this can be achieved by using disable iff.
Disables the checker if certain condition is met.
Example:
property p;
@(posedge clk)
disable iff(rst) a |-> ##1 b[->3] ##1 c;
endproperty
a1:assert property(p);
Code:
34 | P a g e
@shraddha_pawankar Date:25/04/2024
module tb;
bit clk,a,b,c,reset;
//generating 'a'
initial begin
a=1; b=1;
#15 a=0; b=0;
#10 a=1; b=0;
#10 a=0; b=0;
#10 a=1; b=1;
#10;
$finish;
end
property p;
@(posedge clk) disable iff (reset) a |-> ##1 b[->3] ##1 c;
endproperty
a: assert property(p);
//wave dump
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
Sequence Composition:
There are some binary operators,that can be used to combine two sequences logically.
a) And
b) Or
c) Intersect
d) Throughout
e) Within
f) First_match
Syntax:
<seq_exp> and <seq_exp>;
Note:
The two operand sequences need not be matched at the same number of clock ticks.
Syntax:
<seq_exp> or <seq_exp>
The requirement for ‘or’ operation match:
1. Starting Together: Both sequences must start at the same time.
2. At Least One Match: The combined sequence matches if either of the two sequences
(seq1 or seq2) matches.
3. End Time: The end time of the combined sequence is determined by the sequence that
finishes last.
Syntax:
36 | P a g e
@shraddha_pawankar Date:25/04/2024
<seq_exp> intersect <seq_exp>
Example:
sequence seq;
@(posedge clk) $rose(en) ##0
(en) throughout (##2 (req && valid)) [*5];
endsequence
37 | P a g e
@shraddha_pawankar Date:25/04/2024
Syntax:
Seq1 within seq2;
Syntax:
first_match(<seq_exp>)
Example:
sequence seq;
first_match(req1 ## [1:4] req2);
endsequence
This sequence seq looks for the earliest occurrence of req1 followed by req2 within a range
of 1 to 4 clock cycles..
Inline :
Assertions can be embedded anywhere in a module definition.
Sometimes unnecessary change in the design in required..
Code:
module tb;
bit clk,a,b,c,reset;
38 | P a g e
@shraddha_pawankar Date:25/04/2024
//generating 'a'
initial begin
a=1; b=1;
#15 a=0; b=0;
#10 a=1; b=0;
#10 a=0; b=0;
#10 a=1; b=1;
#10;
$finish;
end
property p;
//------
endproperty
//wave dump
initial begin
$dumpfile("dump.vcd");
$dumpvars;
end
endmodule
Binding:
In SystemVerilog, the bind directive is used to associate or bind assertions written
in separate testbench files with specific modules or interfaces in the design code.
This allows verification engineers to write assertions independently from the
design code, enhancing modularity and flexibility in the verification process.
By defining assertions separately,re-usability can be increased.
The assertion can be bound to any module or instance in the design.
39 | P a g e
@shraddha_pawankar Date:25/04/2024
Assertions are typically written in separate files within the testbench
environment,independent of the design code.
2) Bind directive:
Using the ‘bind’ directive,you specify the association between assertion files and the
design modules or interfaces.
3) Flexibility :
This approach provides flexibility, as verification engineers can modify and update
assertions without altering the design code.it also allows for easy reuse of assertions
across different test scenarios.
4) Modularity:
By separating assertions from the design code and binding them as needed,the
verification environment becomes more modular and maintainable,facilitating
efficient verification processes.
Overall,the ‘bind’ directive in system verilog enables seamless integration of
assertions with the design code,promoting better organization,flexibility and
scalability in the verification methodology.
Syntax:
To bind with specific instance
Bind <dut_specific_instance_path><assertion_module><instance>
Design Unit:
module dut(input logic clk,req,output logic ack);
//dut logic
endmodule
Assertion Module:
module asser_mod(input clk,a,b);
property p1;
@(posedge clk) $rose(a) |=>b;
endproperty
a1:assert property(p1);
endmodule
module top;
41 | P a g e