Professional Documents
Culture Documents
Copyright XtremeEDA Corporation 2007. All document files and content ("the data") are copyright XtremeEDA corporation or made available under license.
Data may not be reproduced, republished, stored, distributed, transmitted, altered or resold except as stated below: Documents may be downloaded and used for the purpose of review only Where specific authorization is given in connection with specific documents
The data is provided "AS IS" without warranty of any kind. XtremeEDA may make improvements or changes to data.
Agenda
SystemVerilog for Verification Primer Evolution of verification methodology and languages
Toward the SystemVerilog IEEE 1800 standard
Agenda (2)
Verification features of SystemVerilog cont'd
Constrained Random Stimulus Generation Intelligent Automated Self Checking Total Coverage Analysis Coverage Driven Verification (CDV)
Verification Methodology
Verification success is not based on language alone Methodology is key to effective verification An effective methodology must address the main
verification challenges:
Productivity Quality
for Verification
Copyright XtremeEDA Corp. 2007
Why SystemVerilog?
A variety of languages are available to implement a
HDL-Based Verification
HDLs like Verilog or VHDL were created for describing
verification environment
Hardware description languages (HDLs) Modern software programming languages
Notably Object Oriented Programming (OOP) languages
Hardware verification languages (HVLs) Let's briefly review each en route to SystemVerilog
OOP-Based Verification
Common programming languages like C++ or Java
HVL-Based Verification
HVLs like OpenVera or e incorporate the advantages of
More difficult to debug environment related problems Many engineers need to learn new language
Copyright XtremeEDA Corp. 2007
10
Data Types
SystemVerilog is somewhat strongly typed language Type checking of user-defined types such as enums, structs Flexibility of underlying bit-level representation of numerical values SystemVerilog also adds Two-state logic Strings (real ones !) Dynamic data types (classes) Different event types Several kinds of arrays (including queues)
Copyright XtremeEDA Corp. 2007
And more
Direct interface to foreign programming languages
11
12
Enumerations
Enumerated types represent distinct states or values Useful for example for defining FSM states Enumerations are (somewhat) type-safe Implicit conversion to underlying numeric type Cannot assign from numeric type to enumeration Static and dynamic casting available though
typedef enum {COLOUR_RED, COLOUR_GREEN, COLOUR_YELLOW} colour; typedef enum {COLOUR_RED, COLOUR_GREEN, COLOUR_YELLOW} colour; typedef enum {FRUIT_APPLE, FRUIT_ORANGE, FRUIT_BANANA} fruit; typedef enum {FRUIT_APPLE, FRUIT_ORANGE, FRUIT_BANANA} fruit; colour colour fruit fruit int int c = COLOUR_GREEN; c = COLOUR_GREEN; f = FRUIT_ORANGE; f = FRUIT_ORANGE; i = c + 1; i = c + 1; c = f; c = f; c = i; c = i; c = colour'(i); c = colour'(i); // OK, result is COLOUR_GREEN // OK, result is COLOUR_GREEN Must be of type // OK, result is 1+1 = 2 colour to assign // OK, result is 1+1 = 2 // ILLEGAL // ILLEGAL // ILLEGAL // ILLEGAL // OK: explicit cast to COLOUR_YELLOW // OK: explicit cast to COLOUR_YELLOW
14
Four-state
logic/reg integer time
Width
variable 32 64 16 8
New types except bit default to signed, but can be byte unsigned a; declared unsigned byte unsigned a;
Copyright XtremeEDA Corp. 2007
13
Enumerations (2)
Typically, use typedef to name the resulting type
typedef enum {COLOUR_RED, COLOUR_GREEN, COLOUR_YELLOW} colour; typedef enum {COLOUR_RED, COLOUR_GREEN, COLOUR_YELLOW} colour;
Structs
Similar to C structs and VHDL records Composite data type Can be used to enforce strong type-checking
typedef struct { typedef struct { byte address; byte address; } Address8; } Address8; typedef struct { typedef struct { bit [0:31] address; bit [0:31] address; } Address32; } Address32; byte smalladdress; byte smalladdress; bit [0:31] wideaddress; bit [0:31] wideaddress; Address8 narrow_addr; Address8 narrow_addr; Address32 wide_addr; Address32 wide_addr; wideaddress = smalladdress; // no error! wideaddress = smalladdress; // no error! wide_addr = narrow_addr; // compile error wide_addr = narrow_addr; // compile error
Several built-in methods for enumerations provided: To return the number of enum values, and their names To return the first, last, next or previous enum value
15
16
Classes
Used to represent dynamic data objects E.g. network packets, processor instructions Can be created and destroyed dynamically Can be parameterized like modules Encapsulate model behavior Properties hold data values Methods implement processing Provide an object-oriented inheritance paradigm Reuse = Encapsulation + Inheritance + Polymorphism Not the same as structs
design complexity
Verification environments required with the sophistication of a complex software system OOP originated in the software world to better enable Code reuse Modeling of large systems Verilog-95/2001 lacked OOP capabilities SystemVerilog introduces OOP to Verilog
17
18
Class Members
Class properties can be of any type, and can be
conveniently randomized within OOP framework Class methods implement behavior by operating on the properties
Are automatic by default (i.e. re-entrant) As in Verilog:
Functions return a value, and cannot block Tasks can include time consuming statements
Void functions give task-like calling syntax Can pass arguments by reference Can specify default argument values
Copyright XtremeEDA Corp. 2007
19
20
Class Constructors
SystemVerilog does not require complex memory
allocation/de-allocation Creation of an object is straightforward and garbage collection is implicit and automatic
Helps prevent memory leaks Constructors are a mechanism for creating and
21
22
Data Hiding
Allows separation of the public interface from private
implementation
Users only need to be concerned with how to use an object, not how it is implemented Promotes re-use Three categories: public Visible outside the class (default) protected Visible only to subclasses of the class local Visible only inside the class
23
24
Within the same class, references to local variables in other instances is permitted
// Error, cannot access field BB from outside the class // Error, cannot access field from outside the class
25
26
Arrays
Packed arrays packed refers to vector width dimension Accessed as single vector or as array elements
bit [3:0] vctr; bit [3:0] vctr; vctr == i[10:7]; vctr i[10:7]; // Packed array of bits // Packed array of bits // 4-bit part select // 4-bit part select
Multi-Dimensional Arrays
Multiple unpacked and packed dimensions allowed Can be declared in stages with user defined types Dimension indexing order:
Unpacked before packed Left before right
Unpacked arrays unpacked refers to actual array dimension Can be of any data type (incl. classes, events, ) Can slice multiple contiguous elements at once
byte foo1 [0:255]; byte foo1 [0:255]; byte foo2 [256]; byte foo2 [256]; foo2[20:10] == foo1[10:0]; foo2[20:10] foo1[10:0];
Copyright XtremeEDA Corp. 2007
//Multi Dimensional array of 20*10*5*4*8 bits //Multi Dimensional array of 20*10*5*4*8 bits
packed unpacked
// Unpacked array of bytes // Unpacked array of bytes // [size] is the same as [0:size1] // [size] is the same as [0:size1] // Copying slice of array // Copying slice of array
27
Copyright XtremeEDA Corp. 2007
28
Dynamic Arrays
Dynamic arrays are unpacked arrays that are
Associative Arrays
Associative arrays are unpacked arrays that
sized or re-sized only at run-time Use the new[]() operator to size or re-size
Each array element is initialized to
Corresponding value from optional array argument Its default value if an initial value is not so provided
int mem []; int mem []; mem == new[64]; mem new[64]; mem == new[128](mem); mem new[128](mem); mem == new[32](mem); mem new[32](mem); // Declare dynamic array // Declare dynamic array // Create dynamic array (of all 0s) // Create dynamic array (of all 0s) // Grow array preserving content // Grow array preserving content // Shrink array discarding surplus // Shrink array discarding surplus
implement look-up tables, sparse lists Array index type can be any integral data type
Serves as look-up key and imposes ordering More indexing options: classes, user defined types
int lu_table_int [int]; // Array of integers indexed by integer int lu_table_int [int]; // Array of integers indexed by integer int lu_table_string [string]; int lu_table_string [string]; // Array of integers indexed by string // Array of integers indexed by string event lu_table_class [MyClass]; // Array of events indexed by class MyClass event lu_table_class [MyClass]; // Array of events indexed by class MyClass
int mem_cpy []; int mem_cpy []; mem_cpy = new[mem.size()](mem); // Using built-in method size() mem_cpy = new[mem.size()](mem); // Using built-in method size() mem.delete(); // Using built-in method delete() mem.delete(); // Using built-in method delete()
Copyright XtremeEDA Corp. 2007
Variety of built-in associative array methods: To delete elements, to query index existence, or first/last/next/previous index, etc.
Copyright XtremeEDA Corp. 2007
29
30
Queues
Queues are variable-size unpacked arrays that
Array/Queue Utilities
More built-in methods for arrays and queues Locator (search) methods - return a queue
min, max, unique, find, find_first, find_last, unique_index, find_index, find_first_index, find_last_index
Ordering Methods
sort, rsort, reverse, shuffle
Reduction Methods
sum, product, and, or, xor
Variety of built-in queue methods: To insert/delete elements, to push/pop elements, to query size, etc.
31
32
Interfaces
Provide an abstract encapsulation of communication
Using Interfaces
A module can be declared using interfaces to
between blocks
In simple terms, a bundling of port signals
interface bus_a (input clock); interface bus_a (input clock); logic [7:0] address; logic [7:0] address; logic [31:0] data; logic [31:0] data; bit valid; bit valid; bit rd_wr; bit rd_wr; endinterface endinterface
bus_b
foo
clk
Can take ports just like modules (incl. interfaces!) Can be used with modports to specify signal direction Can be used with clocking blocks to specify timing
Copyright XtremeEDA Corp. 2007
bus_b
foo
clk top
33
34
Modports
An interface can have multiple (client) viewpoints Master/slave, transmitter/receiver, active/passive These can be specified using modports
All signal names in a interface bus_b (input clock); interface bus_b (input clock); modport must be logic [7:0] addr, data; logic [7:0] addr, data; declared in the interface bit bit [1:0] mode; [1:0] mode; bit ready; bit ready; modport master (input ready, output addr, data, mode); modport master (input ready, output addr, data, mode); modport slave (input addr, data, mode, output ready); modport slave (input addr, data, mode, output ready); endinterface endinterface
Modports (2)
Modports can easily stipulate signal directionality
between modules
module top; module top; bus_b bb(...); // instantiate the interface bus_b bb(...); // instantiate the interface foo foo1(.b1(bb.master)); foo foo1(.b1(bb.master)); bar bar1(.b1(bb.slave)); bar bar1(.b1(bb.slave)); endmodule endmodule Both foo and bar must have the appropriate interface types defined in their portlist
bus_b
master
35
slave
The I/O direction has arbitrarily been displayed with inputs pointing right
Copyright XtremeEDA Corp. 2007
bar
top
foo
b1
36
Clocking Blocks
Specify synchronization characteristics of the design
Encapsulate signals synchronous to a given clock Make their timing explicit Offer a clean way to drive and sample signals Decouple synchronization and timing aspects from structural and functional aspects of environment Features: Clock specification Input skew, output skew Cycle delay (##)
Copyright XtremeEDA Corp. 2007
Signals will be sampled 2ns before posedge ck Signals will be driven 3ns after posedge ck
37
38
Program Blocks
Intended to encapsulate testbench functionality Form the heart of the test flow Help decouple DUT from testbench code Cannot instantiate a module, interface or other program block
Are always leaves in the hierarchy
task new (( virtual bus_b bus_if ); task new virtual bus_b bus_if ); this.bus_if == bus_if; this.bus_if bus_if; ... ... endtask bus_b bb(...); endtask bus_b bb(...); ... ... ... initial begin ... initial begin endclass transactor = new( bb ); endclass transactor = new( bb ); ... ...
39
40
Stimulus Generation
Viewing the entire state space of a DUT
41
42
Random Generation
SystemVerilog enables automated generation of
random data
Productivity increase by automatically generating random values for variables Quality increase due to exploring outside of the expected failure scenarios of the DUT
using the $random function permits a reduction in tests. One test can be run with many seeds to try interesting combinations
43
44
Constrained-Random Generation
Random generation alone is not sufficient Need a mechanism to constrain generated values Constraints are essential to drive meaningful data
into a design
Input data objects:
Different packet sizes, valid address ranges,
Each test will produce different results for each seed used
Constraints can also guide tests to interesting DUT Issue: Lack of control over generated values Tests could be sending illegal or invalid data
Copyright XtremeEDA Corp. 2007
states
Copyright XtremeEDA Corp. 2007
45
46
Random Variables
Need to declare which variables can be randomly
generated before applying constraints Class variables can be declared random using the rand and randc type-modifier keywords
rand Each generated value is uniformly distributed over all possible combinations randc Cycles through all values in a random permutation of declared range (random cyclic)
class packet; class packet; rand byte src; rand byte src; // each value has 1/256 probability // each value has 1/256 probability randc byte dest; // each new value has 1/(256-n) probability randc byte dest; // each new value has 1/(256-n) probability // where nn is the ## times this field has // where is the times this field has // been generated. nn rolls over at 255 // been generated. rolls over at 255 endclass endclass
Copyright XtremeEDA Corp. 2007
//random value in range 100-200 //random value in range 100-200 //random value in range 201-255 //random value in range 201-255
47
48
Constraints
Values for random variables can be controlled
selected for all random variables in an object Function returns a success indication
class packet; class packet; rand byte src; rand byte src; rand byte dest; rand byte dest; rand byte payload [10]; rand byte payload [10]; endclass endclass packet p1 == new; packet p1 new; initial begin initial begin if (p1.randomize() == 1) $display("Success"); if (p1.randomize() == 1) $display("Success"); else $display("Randomize failed"); else $display("Randomize failed"); end end
49
50
Constraints: Iterative
Use foreach to constrain individual elements within
arrays or queues
class packet; class packet; ... ... rand logic [7:0] payload[8]; rand logic [7:0] payload[8]; constraint packet_payload {{ constraint packet_payload foreach (payload[i]) foreach (payload[i]) payload[i] inside {0,10,20,30}; payload[i] inside {0,10,20,30}; } } endclass endclass // iterate through each payload item // iterate through each payload item // constrain each item to aa list of // constrain each item to list of // values // values
In these constrainst the value of dest_type constrains the value of dest and the value of dest constrains the value of dest_type (bidirectional)
Copyright XtremeEDA Corp. 2007
51
52
In-line Constraints
Random variables can be further constrained in-line
// weighted ratio of 1/3-1/3-1/3 // weighted ratio of 1/3-1/3-1/3 // weighted ratio of 1/3-1/3-1/3 // weighted ratio of 1/3-1/3-1/3 // ordering constraint // ordering constraint // function call in constraint // function call in constraint
These constraints are applied in addition to dest_range constraint group within the packet
function byte fetch_src(); ... endfunction function byte fetch_src(); ... endfunction endclass endclass
Copyright XtremeEDA Corp. 2007
53
54
Random Stability
Highly desirable in verification Repeatable simulation results for any given seed Changes to one area of testbench have minimal overall impact on results Enforced by SystemVerilog standard: Every thread and object gets its own PRNG Sequence of random values returned by a thread or object is independent of other threads or objects Enables more precise control through manually
seeding of objects
Requires some form of seed management
Copyright XtremeEDA Corp. 2007
55
56
Data Checking
Established checking method is to compare expected
Scoreboarding
2.) The transfer function applies necessary transformations to the transaction and stores it in the scoreboard 1.) Transactions are driven into the design and passed to a transfer function (may or may not be part of the scoreboard)
DUT
stim
Transfer Function
Scoreboard
4.) Mismatches might be errored packets
3.) Monitor passes received transactions to the scoreboard to compare with expected results
Generator/Driver object
Monitor
DUT
object
57
58
A B
my_assertion clock occurrence
Thread spawned
60
59
Other rules: Only one of FS, LS and PX can be high at any time FS must be followed by LS, with no PX in between
61
62
Is a feedback mechanism only Cannot ensure completeness of verification (intent) Use to steer verification efforts to untested areas
Achieve verification closure more effectively
63
64
Coverage Feedback
Functional Coverage
Ties verification goals to design intent User-defined based on specification
No RTL code = no coverage vs. no RTL code = no errors Goal
rand byte a, b, c; rand byte a, b, c; covergroup cg; // Define the coverage group covergroup cg; // Define the coverage group coverpoint a { coverpoint a { bins corner_cases = { [0:63], 65, 66, 67 }; bins corner_cases = { [0:63], 65, 66, 67 }; bins high_values = { [161:$] }; // $ = max value of a bins high_values = { [161:$] }; // $ = max value of a bins others[] = default;} // catch-all bin bins others[] = default;} // catch-all bin coverpoint bb {{ coverpoint ignore_bins ignore_vals {{ [250:255] }; // ignore values 250..255 ignore_bins ignore_vals [250:255] }; // ignore values 250..255 illegal_bins bad_vals { 0,5,11,13 };} // run-time errors for 0,5 ... illegal_bins bad_vals { 0,5,11,13 };} // run-time errors for 0,5 ... coverpoint c { coverpoint c { bins fixed [10] = [0:10];} // bin 10 contains <9,10> bins fixed [10] = [0:10];} // bin 10 contains <9,10> endgroup endgroup cg == new(); cg new(); ... ... cg.sample(); cg.sample(); // create the coverage group // create the coverage group // trigger coverage collection // trigger coverage collection
66
% Coverage
Time
65
Add constraints
3. 4. 5. 6.
Create supporting verification environment Run simulations and generate coverage reports Review coverage reports Create new tests to target any coverage holes
coverage coverage reports reports Simulate constrained constrained random test random test
67
68
transactions
DUT
assertions top
Copyright XtremeEDA Corp. 2007
functional coverage
testcase
69
70
Summary
SystemVerilog for Verification Primer Evolution of verification methodology and languages Verification features of SystemVerilog
New Data Types Object Oriented Programming (OOP) Data Hiding Arrays and Queues Interfaces and Modports Clocking and Program Blocks
Summary (2)
Verification features of SystemVerilog cont'd
Constrained Random Stimulus Generation Intelligent Automated Self Checking Total Coverage Analysis Coverage Driven Verification (CDV)
71
72
specializing in
Verification Planning, Architecture and Implementation Design For Test (DFT) Training
Skilled in a wide range of languages and tools Strong focus on methodology, beyond language Consultants are methodology experts with ability to contrast various techniques and explain best practices Instructors are active consultants with years of verification and teaching experience
Copyright XtremeEDA Corp. 2007
73
74
75
76