Professional Documents
Culture Documents
1. Fundamentals of Verification
2. SystemVerilog Basics
3. Class based Verification using SystemVerilog
Cracking Digital VLSI Verification Interviews: [Discussion Group]
4. SystemVerilog Assertions
5. SystemVerilog Coverage
6. SystemVerilog based UVM Methodology
1
9/17/2017
What is OOP?
2
9/17/2017
Class Instantiation
Constructor
3
9/17/2017
▪ Deep Copy
▪ If member of a class is another class/object
▪ Explicit copy function needs to be implemented to
copy all members of the object
4
9/17/2017
www.verificationexcellence.in 9/17/2017 26
9/17/2017 www.verificationexcellence.in 25
5
9/17/2017
▪ Within a “same” class - even local variables of ▪ The const keyword may be used to make class
another object of “same” class can be accessed properties unchangeable (or read only).
▪ One initialization while declaration or in constructor OK
6
9/17/2017
Overloading vs Overriding
Virtual methods
Examples Examples
▪ Virtual method can override a non-virtual method ▪ A Base class pointer can be assigned values of any
sub-classes handles
▪ Virtual keyword may or may not be used in sub
classes ▪ A sub-class (derived class) pointer cannot be assigned
values of a super class handle directly
▪ Walk through an example in edaplayground
▪ https://www.edaplayground.com/x/3L2f ▪ If a super class (base class) points to a derived class
object, then another derived class object pointer can
be assigned this value with casting
7
9/17/2017
▪ Base class (Superclass) pointer can be used to reference ▪ Used to specify an identifier in a class scope – Use “::”
objects of derived class (subclass)
▪ Useful for referencing static members, nested classes,
referencing enums or constants from outside
▪ Instances of various derived class objects can be
reference using above array
8
9/17/2017
Parameterized Class
Out of block declaration
▪ Method definitions can be placed outside class using ▪ Allows Generic Class to be Instantiated as Objects of
“extern” keyword Different Types
▪ To create specialized classes use “typedef” along ▪ Parameters of Class need to have a value during declaration
with parameters
9
9/17/2017
▪ Classes cannot have modules or interfaces, need a ▪ Virtual interface variable can point to a physical
specialized mechanism interface instance
▪ Why? ▪ Can be passed as argument to tasks/functions
▪ Virtual interfaces provide a way to connect dynamic ▪ Can reference clocking blocks and modports using
classes to static world of modules dot operator
▪ Virtual interfaces provide a mechanism for separating test
programs/BFM models from the actual signals.
task req_bus();
Randomization
dut dut1 (infc_b, clk);
@(posedge bus.clk);
// class instance
bus.req <= 1'b1;
BFM mybfm = new (infc_b);
$display("Req = %b @ %0t",
Ramdas
bus.req, $time);
endtask: req_bus
endclass: BFM
▪ $urandom system tasks ▪ Constraints are built onto the Class system
▪ $urandom() is SV, thread stable, deterministic ▪ Random variables use special modifier:
▪ rand –random variable
▪ $urandom returns unsigned 32-bit integers ▪ randc –random cyclic variable
▪ Procedural call can be inserted wherever needed
▪ Object is randomized by calling randomize( )method
▪ Automatically available for classes with random variables.
▪ User-definable methods
▪ pre_randomize()
▪ post_randomize()
www.verificationexcellence.in 9/17/2017 59 www.verificationexcellence.in 9/17/2017 60
10
9/17/2017
▪ Do not use randc on data types that can have lot of values .
E.g “randc int” can go about 2^32 values and consumes lot
of memory to track internally
▪ A constraint in a derived class with same name as in ▪ Additional constraints can be specified when
super/base class will override the functionality randomize() method is called
▪ Abstract class can have a pure constraint prototype
11
9/17/2017
Conflicting constraints
Enable/Disable rand/constraints
▪ What happens when you impose constraints that conflict
in some way? ▪ rand_mode() – method to toggle the “rand”
attribute off on a class variable
▪ If turned off, those behave like normal variables
▪ constraint_mode() – method to enable/disable a
constraint
▪ Useful for generating negative/error cases
▪ Selectively enabling constraints added in a set of classes in a
▪ No compile error – Solver errors are run time inheritance hierarchy
▪ Good practice – Put an assertion on randomize() to catch
solver errors
www.verificationexcellence.in 9/17/2017 67 www.verificationexcellence.in 9/17/2017 68
Constraint_mode rand_mode()
pre_randomize()
post_randomize() Constraint operators
▪ Built in functions that can be overridden to perform any ▪ Any Verilog boolean expression
operations immediately before or after randomization
i.e. x < y+b-c*10>>20
12
9/17/2017
▪ “inside “ construct – All values will have equal probability ▪ Specifies Weightage per Value in the set
▪ Two operators
▪ := operator assigns the specified weight to the item
or, if the item is a range, to every value in the
range.
▪ :/ operator assigns the specified weight to the item
or, if the item is a range, to the range as a whole
▪ A dist operation shall not be applied to randc variables.
▪ Why ?
▪ Group of values can be constrained to have unique ▪ Uses one boolean to decide if another constraint must
values hold
▪ e.g – Generate an array with all elements as unique
13
9/17/2017
▪ Array reduction methods can be use in constraints ▪ All constraints are determined by
▪ E.g – Generate a byte array of size ==5 and the sum of all solver simultaneously
elements less than 1000
▪ In this example
▪ S can be 1 or 0 with a ½
probability
▪ D values have 2^32 values
▪ If one of D is picked first, then the
chance of S being picked as 1 is
very very less
▪ In above example, it makes sense to first solve S to have ▪ A constraint that is applicable to all instance of class
equal probability of both values generated.
▪ Has to be a separate constraint block
14
9/17/2017
▪ Functions can be used in constraints - but comes with ▪ By default constraints are “hard”
a lot of restrictions (Refer LRM before usage) ▪ Solver fails if it cannot satisfy all constraints
▪ Sometimes certain constrains need not be “hard”
▪ Some default constraints can be soft to be within a
guideline, but an actual implementation can
overwrite it
▪ In case of multiple soft constraints, priority applies. ▪ Procedural invocation of constraint solver within a scope
▪ See LRM for detailed rules ▪ Randomize any variables not part of a class
▪ Can also optionally have inline constraints ▪ Case statement with weightage based random
selection of a statement
15
9/17/2017
Test
Monitors Monitors
Packet
Generator Driver DUT
▪ A packet class that defines packet properties Step1: Implement a packet class with reference to below
framework and directions
▪ A random packet generator that can generate packets as
per our specification
▪ A driver that can take a packet at a time and drive as per
the protocol defined in the specification
▪ A monitor that can be instantiated on both input and
output ports which samples signals and creates a packet
class
▪ A scoreboard that can look at input packet and check if the
packet at output was received properly
Step2: Implement a packet monitor class with reference to Step3: Implement a packet checker class with reference to
below framework and directions below framework and directions
16
9/17/2017
▪ In this exercise - build remaining components that Step1: Implement a Packet Generator class with a
was not done in previous exercise template as below and directions specified in comments
▪ Packet Generator on what to implement
▪ Packet Driver
▪ Add mailboxes to Packet Checker implemented
in previous exercise
▪ Add mailboxes to Packet monitor implemented
in previous exercise
Step2: Implement a Packet Driver class with a template Step3: Extend the Packet monitor class that was
as below and directions specified in comments on what implemented in previous exercise by adding a mailbox
to implement to put the monitored packets
17
9/17/2017
▪ In this exercise - build remaining components that •Step1: Implement a top level module as templated
was not done in previous exercise below. Follow directions to instantiate components
▪ Packet Generator
▪ Packet Driver
▪ Add mailboxes to Packet Checker implemented
in previous exercise
▪ Add mailboxes to Packet monitor implemented
in previous exercise
Thank You
Ramdas M
18