Testbench Overview
Testbench Overview
Testbench Overview
User Experience
Matt Maidment, Intel
User Experience
Faisal Haque, Verification Central
Lunch: 12:15 1:00pm
93
Arrays
Dynamic and associative
Event Variables
Can be used in assignments and as arguments
Class
Allows object-oriented programming
95 DAC2003 Accellera SystemVerilog Workshop
Dynamic Arrays
Declaration syntax
<type> <identifier> [ ]; bit[3:0] dyn[ ];
dyn
96
Dynamic Arrays
Declaration syntax
<type> <identifier> [ ]; bit[3:0] dyn[ ];
bit[3:0] fix[0:3];
Initialization syntax
<array> = new[<size>]; dyn = new[4];
dyn
A B C D
A B C D
Size method
function int size(); int j = dyn.size;//j=4
Resize syntax
<array> = new[<size>](<src_array>); dyn = new[j * 2](fix);
97
Dynamic Arrays
Declaration syntax
<type> <identifier> [ ]; bit[3:0] dyn[ ];
Initialization syntax
<array> = new[<size>]; dyn = new[4];
dyn
A B C D
Size method
function int size(); int j = dyn.size;//j=4
Resize syntax
<array> = new[<size>](<src_array>); dyn = new[j * 2](fix);
Delete method
function void delete(); dyn.delete; // dyn is now empty
98 DAC2003 Accellera SystemVerilog Workshop
Associative Arrays
Sparse Storage Elements Not Allocated Until Used Index Can Be of Any Packed Type, String or Class Declaration syntax
<type> <identifier> [<index_type>]; <type> <identifier> [*]; // arbitrary type
Example
struct packed {int a; logic[7:0] b} mystruct; int myArr [mystruct]; //Assoc array indexed by mystruct
Built-in Methods
num(), delete([index]), exists(index); first/last/prev/next(ref index); Ideal for Dealing with Sparse Data
99 DAC2003 Accellera SystemVerilog Workshop
a b c a b c a b c a b c
fork a;b;c; Maximize Stimulus Interactions join_any disable fork;// kill all child processes fork a;b;c; join_any wait fork;// wait for children to complete #10; $exit
DAC2003 Accellera SystemVerilog Workshop
100
Inter-Process Synchronization
Events enhanced from V2K
Events are variables can be copied, passed to tasks, etc. event.triggered; // persists throughout timeslice, avoids races wait_order(), wait_any(), wait_all(<events>);
// main program .. semaphore shrdBus =new; ... task go_cpu(id, ref event ev) begin ... @(ev) shrdBus.get () ...//access granted ...//activity on the cpu bus shrdBus.put() Cache ... endtask
shared bus
semaphores
CPU1
CPU2
Cache
// usage, forking parallel // threads for cpu access event ev1,ev2; ... fork go_cpu(cpu1,ev1); go_cpu(cpu2,ev2); ... join ...
Mailbox: communication
Mailbox features
FIFO message queue: passes data between threads Can suspend thread, used for data checking
Packet Stimulus
Packet 4
output
clock
Shoot
103 DAC2003 Accellera SystemVerilog Workshop
Skew Declaration
Specify Synchronous Sample / Drive Times
sample here
clock
drive here Input skew is for sampling Output skew is for driving
skew
input
output
104
Synchronous Interface
clocking bus @(posedge clk); default input #1ns output #2ns; input inout output output #6ns endclocking enable, full; data; empty; reset = top.u1.reset;
Clocking Event clock Default I/O skew Hierarchical signal Testbench Uses: bus.enable bus.data ...
Active
Inactive
NBA
Read-Only
107
Preponed
Inactive
Sample Stable Values
NBA
Evaluate Assertions
108
Program Block
Purpose: Identifies verification code A program differs from a module
Only initial blocks allowed Special semantics
Executes in Reactive region design clocking/assertions program program name (<port_list>); <declarations>;// type, func, class, clocking <continuous_assign> initial <statement_block> endprogram
110 DAC2003 Accellera SystemVerilog Workshop
Object-Oriented Programming
Organize programs in the same way that objects are organized in the real world Break program into blocks that work together to accomplish a task, each block has a well defined interface Focuses on the data and what you are trying to do with it rather than on procedural algorithms
111
Class Basics
Class Definitions Contain Data and Methods Classes Are Instantiated Dynamically to Create Objects
Static members create a single element shared by all objects of a particular class type
Classes Can Inherit Properties and Methods From Other Classes Classes Can Be Parameterized
112 DAC2003 Accellera SystemVerilog Workshop
Class Definition
Definition syntax
class name; <data_declarations>; <task/func_decls>; endclass
extern keyword allows for out-of-body method declaration class Packet; bit[3:0] cmd; int status; myStruct header; function int get_status(); return(status); endfunction extern task set_cmd(input bit[3:0] a); endclass
Class Instantiation
Objects Allocated and Initialized Via Call to the new Constructor Method
All objects have built-in new method
No args Allocates storage for all data properties
Packet myPkt = new;
myPkt
class Packet; ... function new(); cmd = IDLE; endfunction endclass Packet myPkt = new;
cmd status header
START IDLE 5
class Packet; ... function new(input int a); cmd = START; status = a; endfunction endclass Packet myPkt = new(5); // myPkt.status = 5
114
class ErrPkt extends Packet; bit[3:0] err; function bit[3:0] show_err(); return(err); endfunction task set_cmd(input bit[3:0] a); cmd = a+1; endtask // overrides Packet::set_cmd endclass
ErrPkt:
cmd status header err
get_status show_err set_cmd cmd = a+1;
Allows Customization Without Breaking or Rewriting Known-Good Functionality in the Base Class
115 DAC2003 Accellera SystemVerilog Workshop
Class Hierarchy
Class members can be hidden from external access
local members can only be referenced from within the class, not from a subclass protected members can be referenced from within a subclass
class Base; local int i; int a,d; protected task set_i(input int i); this.i = i; endtask function new();...endfunction endclass class Sub extends Base; int a; function new(); super.new();... endfunction task set_a(input int c); a = c; super.a = c+1; set_i(c); // inherited method endtask endclass
this pointer refers to current instance super pointer refers to parent class
116
Class Hierarchy
Class members can be hidden from external access
local members can only be referenced from within the class protected members can be referenced from within a subclass
class Base; local int i; int a,d; protected task set_i(input int i); this.i = i; endtask function new();...endfunction endclass class Sub extends Base; int a; function new(); super.new();... endfunction task set_a(input int c); a = c; super.a = c+1; set_i(c);// inherited endtask endclass
this pointer refers to current instance super pointer refers to parent class
Sub S = new; initial begin S.i = 4; // illegal i is local to Base S.set_i(4);// illegal set_i is protected S.a = 5; // legal Base::a is hidden by Sub::a S.set_a(5);// legal set_a is unprotected S.d = 3;// legal d is inherited from Base end 117 DAC2003 Accellera SystemVerilog Workshop
Parameterized Classes
Allows Generic Class to be Instantiated as Objects of Different Types
Uses modulelike parameter passing
class vector #(parameter int size = 1;); bit [size-1:0] a; endclass vector #(10) vten; // object with vector of size 10 vector #(.size(2)) vtwo; // object with vector of size 2 typedef vector#(4) Vfour; // Class with vector of size 4 class stack #(parameter type T = int;); local T items[]; task push( T a ); ... endtask task pop( ref T a ); ... endtask endclass stack i_s; // default: a stack of ints stack#(bit[1:10]) bs; // a stack of 10-bit vector stack#(real) rs; // a stack of real numbers stack#(Vfour) vs; // stack of classes
Input Space
Design
Valid
Random Constraints
Constraints are built onto the Class system Random variables use special modifier:
rand random variable randc random cyclic variable
User-definable methods
pre_randomize() post_randomize()
121
Basic Constraints
Constraints are Declarative
class Bus; rand bit[15:0] addr; rand bit[31:0] data; constraint word_align {addr[1:0] == 2b0;} endclass
Calling randomize selects values for all random variables in an object such that all constraints are satisfied
Generate 50 random data and word_aligned addr values
Bus bus = new; repeat (50) if ( bus.randomize() == 1 ) // 1=success,0=failure $display ("addr = %16h data = %h\n", bus.addr, bus.data); else $display ("Randomization failed.\n");
122 DAC2003 Accellera SystemVerilog Workshop
Layered Constraints
Constraints Inherited via Class Extension
Just like data and methods, constraints can be inherited or overridden
typedef enum { low, high, other } AddrType ;
type variable selects class MyBus extends Bus; rand AddrType type; address range constraint addr_rang { ( type == low ) => addr in { [ 0 : 15] }; ( type == high ) => addr in { [128 : 255] }; } endclass
In-Line Constraints
Additional Constraints In-line Via
obj.randomize()with <constraint_blk>
task exerBus(MyBus m); int r; r = m.randomize() with {type==small}; endtask
Force type to be small
124
125
Separate Verification Language: Have to Start Over From Scratch Separate tool = Bottleneck Different Language from Design