Professional Documents
Culture Documents
Austin TX
September 9, 2015
Agenda
Part 1: A short tutorial on SystemVerilog Assertions
Part 2: Who should write assertions?
Part 3: Planning where to use assertions
Part One:
A Short Tutorial On
SystemVerilog
Assertions
9-4
What Is
An Assertion?
req
ack
Design Specification:
After the request signal is asserted,
the acknowledge signal must arrive
1 to 3 clocks later
9-5
req
ack
Design Specification:
Each request must be
followed by an acknowledge
within 1 to 3 clock cycles
assert property (@(posedge clock) req |-> ##[1:3] ack) else $error;
Embedded Verification
Checking and Synthesis
9-6
if (critical_condition)
RTL code
// do true statements
else
//synthesis translate_off
if (critical_condition == 0)
checker code
//synthesis translate_on
// do the not true statements
RTL code
//synthesis translate_off
else
checker code
$display("critical_condition is bad");
//synthesis translate_on
9-7
SystemVerilog Has
Two Types of Assertions
An immediate assertion is the same as an ifelse statement, but with assertion controls
0
req
ack
5
multi-clock sequences
can be defined with very
concise code
a_reqack: assert property (@(posedge clock) data_ready |-> req ##[1:3] ack)
else $error;
concurrent assertions run as a
background process in parallel
always_ff @(posedge clock)
with the RTL code
if (data_ready) req <= 1; ... // RTL code
Concurrent assertions have an extensive set of operators to describe complex design conditions
9-8
Assertions in a UVM testbench should use the UVM message functions, such as
uvm_report_warning and uvm_report_error, so that the messages are tracked by UVM
9-9
9-10
Detecting Glitches
with Assertions
There are many reasons signals might change more than once
during a single clock cycle (a potential glitch)
Combinatorial decoding, clock domain crossing, async reset,
0
clk
opcode
ADD
SUB
XOR
You need an
immediate assertion!
ROL
ADD
You need a
concurrent assertion!
Immediate Assertions
Pros:
Easy to write simple syntax
Close to code being checked
Can check asynchronous
values between clock cycles
Self-documenting code
Cons:
Cannot use binding (later slide)
Difficult to disable during reset
or low-power
Must following good RTL
practices to prevent race
conditions (just like any
programming statement)
9-11
Youre the engineer
which of these pros and
cons are most important
in your project?
Concurrent Assertions
Pros:
Background task define it and it
just runs
Cycle based no glitches
between cycles
Can use binding (see later slide)
Works with simulation and formal
verification
Cons:
More difficult to define (and
debug)
Can be far from code being
checked
Cannot detect glitches
Concurrent Assertions
are Cycle Based
9-12
9-13
10ns
20ns
30ns
40ns
SF
clk
req
ack
apReqAck
An evaluation thread
starts at time 10
The fix for this gotcha is something called an implication operator (see next page)
9-14
clk
mem_en
req
ack
clk
mem_en
req
ack
The |=> (non-overlapped implication) is the same as |-> ##1 (overlapped plus 1 cycle)
9-15
Implication Terminology
9-16
10
20
30
40
50
clk
req
ack
property p_req_ack;
@(posedge clk)
req |-> ##2 ack ##1 !ack;
endproperty: p_req_ack
ap_req_ack: assert property (p_req_ack);
1
1
If there is an ack,
then req must be true
2 clock cycles later
clk
req
ack
1
S
9-17
9-18
Special functions test for a value change between adjacent clock cycles:
$rose(expression, cycle_definition);
Returns true if the LSB of the expression changed to 1
$fell(expression, cycle_definition);
Returns true if the LSB of the expression changed to 0
$changed(expression, cycle_definition);
Returns true if the value of the expression changed
$stable(expression, cycle_definition);
Returns true if the value of the expression did not change
The cycle_definition is optional and seldom needed (see notes below); It specifies what
clock to use for sampling the expression (e.g.: $rose(ack, @posedge master_clk) )
Design Spec: A req (request) should be followed two cycles later by a rising edge
of ack (acknowledge). The ack is only allowed to be high for one clock cycle.
property p_req_ack;
@(posedge clk)
req |-> ##2 $rose(ack) ##1 !ack;
endproperty: p_req_ack
ap_req_ack: assert property (p_req_ack);
clk
req
ack
9-19
Design Specification:
The FIFO almost_full flag is set when
there are 2 locations remaining in the FIFO
caFifoNearMax: cover sequence
(@(posedge clk)
almost_full ##1 push ##1 push);
Assertion
coverage is
discussed
in more
detail later
in the
course
Part Two:
Who Should Write
Assertions
9-21
Guideline for
Who Writes Assertions!
9-22
Example: The zero flag output of the ALU block should only be set if the
ALU result output is zero
Design Engineers
Should Add Assertions to RTL!
9-23
9-24
can be exceptions to this guideline you get paid the big money to figure
out which way of specifying assertions is best for your projects!
Pros:
Do not need RTL file access
permissions to add assertions
Adding assertions does not
impact RTL file time-stamps
Cons:
Assertions can be far from the
code being checked
RTL engineers must edit
multiple files to add assertions
while the RTL modes is being
developed
Cannot (easily) use immediate
assertions
9-26
Pros:
Close to the code being verified
Can use both concurrent and
immediate assertions
Document designers
assumptions and intentions
Assertion errors originate from
same file as the failure
Cons:
Adding/modifying an assertion
could trigger automated
regression or synthesis scripts
9-27
checking!
always_comb / always_ff
Part Three:
Planning Where to
Use Assertions
9-29
Developing An
Assertions Test Plan
9-30
Case Study:
Assertions for a Small DSP
ram
register
clock_gen
register
pc
alu
controller
decoder
status_reg
ram
iobuf
iobuf
Assertions Test
Plan: ALU
a [15:0]
opcode [2:0]
9-31
b [15:0]
alu
Functionality to Verify
The a, b and opcode inputs never have any bits that are X or Z
All opcode values are decoded
The zbit output must be set whenever result output is 0
Assertion Type
Assigned To
immediate
design team
unique case
design team
concurrent
verification team
What other assertions are needed? (Answering this question is part of the final project)
9-32
Exercise:
Assertions Test Plan for the ALU
a [15:0]
opcode [2:0]
b [15:0]
alu
ASSIGNMENT:
Plan some assertions for the DSP
blocks on this page and the next 3
pages. We will then discuss the test
plan ideas as a class
Assertion Type
Assigned To
immediate
design team
unique case
design team
concurrent
verification team
concurrent
verification team
concurrent
verification team
concurrent
verification team
concurrent
verification team
concurrent
verification team
The a, b and opcode inputs never have any bits that are X or Z
All opcode values are decoded
9-33
Exercise:
Assertions Test Plan for the RAM
ram
addr [11:0]
4k x 16
data [15:0]
rdN
wrN
Assertion Type
Assigned To
immediate
design team
addr never has X or Z bits when wrN is low (writing into RAM)
immediate
design team
data never has X or Z bits when wrN is low (writing into RAM)
immediate
design team
addr never has X or Z bits when rdN is low (reading from RAM)
immediate
design team
data never has X or Z bits when rdN is low (reading from RAM)
concurrent
verification team
9-34
pc
cnt [11:0]
>
rstN
Assertion Type
Assigned To
immediate
design team
immediate
design team
If load, then, after clk to cnt delay, cnt has the value of d
concurrent
verification team
concurrent
verification team
concurrent
verification team
9-35
controller
exception
zero_flag
branching
clk
>
rstN
load_s
load_b
load_f
load_pc
inc_pc
set_br
rslt_oeN (low true)
dout_oeN (low true)
dmem_rdN (low true)
dmem_wrN (low true)
halt
The controller is a 1-hot finite state machine that sets the control
lines for the various DSP blocks
rstN is asynchronous the controller resets to the RESET state
Functionality to Verify
Assertion Type
Assigned To
immediate
design team
concurrent
verification team
concurrent
verification team
concurrent
verification team
concurrent
verification team
9-36
9-37
Better design partitioning would put the ALU and its input and output
registers into one design block
Enumerated types should have explicit values defined for each label
After synthesis, labels disappear and only logic values exist
Assertions become invalid if the label does not have an explicit value
Summary
Do It!
9-38
Question?
Comments?
9-39
sutherland-hdl.com/papers.html