21EC71 Advanced VLSI Notes Module 5
21EC71 Advanced VLSI Notes Module 5
Advanced VLSI
(21EC71)
SEMESTER – VII
Module 5
Randomization: Introduction, What to randomize? , Randomization in System
Verilog, Random number functions, Common randomization problems, Random Number
Generators.
Text Book 2
Vijaykumar Sajjanar
[email protected],
vjkr.github.io
www.bldeacet.ac.in Page | 1
21EC71 Advanced VLSI
TABLE OF CONTENTS
Randomization ......................................................................................................................................................................................... 4
What to Randomize ................................................................................................................................................................................ 4
Randomization in SystemVerilog ..................................................................................................................................................... 6
Simple class with random variables .......................................................................................................................................... 6
Checking the result from randomize ......................................................................................................................................... 6
The constraint solver ........................................................................................................................................................................ 6
Random System Functions .................................................................................................................................................................. 7
Common Randomization Problems ................................................................................................................................................ 8
Use care with signed variables ..................................................................................................................................................... 8
Random Generators ............................................................................................................................................................................... 9
Pseudorandom number generators ........................................................................................................................................... 9
Random Stability — multiple generators ................................................................................................................................ 9
Random Stability — hierarchical seeding ............................................................................................................................... 9
Functional Coverage ........................................................................................................................................................................... 10
Coverage Types ................................................................................................................................................................................ 10
Code coverage .............................................................................................................................................................................. 10
Functional coverage .................................................................................................................................................................. 11
Bug rate ........................................................................................................................................................................................... 11
Assertion Coverage .................................................................................................................................................................... 11
Functional Coverage Strategies ..................................................................................................................................................... 12
Gather information, not data ...................................................................................................................................................... 12
Only measure what you are going to use .............................................................................................................................. 12
Measuring completeness ............................................................................................................................................................. 12
Simple Functional Coverage Example ......................................................................................................................................... 13
Anatomy of a Cover Group ............................................................................................................................................................... 14
Defining a cover group in a class .............................................................................................................................................. 14
Triggering a Cover Group ................................................................................................................................................................. 15
Sampling using a callback ............................................................................................................................................................ 15
Cover group with an event trigger ........................................................................................................................................... 16
Triggering on a SystemVerilog Assertion ............................................................................................................................. 16
Data Sampling ........................................................................................................................................................................................ 17
Individual bins and total coverage .......................................................................................................................................... 17
Creating bins automatically ........................................................................................................................................................ 17
Limiting the number of automatic bins created ................................................................................................................ 17
Sampling expressions .................................................................................................................................................................... 18
Naming the cover point bins ...................................................................................................................................................... 18
Conditional coverage ..................................................................................................................................................................... 18
www.bldeacet.ac.in Page | 2
21EC71 Advanced VLSI
Transition coverage........................................................................................................................................................................ 19
Wildcard states and transitions ................................................................................................................................................ 19
Ignoring values ................................................................................................................................................................................. 19
Illegal bins ........................................................................................................................................................................................... 19
Cross Coverage ...................................................................................................................................................................................... 20
Coverage Options ................................................................................................................................................................................. 21
Cover group comment ................................................................................................................................................................... 21
Per-instance coverage ................................................................................................................................................................... 21
Coverage threshold using at_least ........................................................................................................................................... 21
Printing the empty bins ................................................................................................................................................................ 21
Coverage goal .................................................................................................................................................................................... 22
Analyzing Coverage Data .................................................................................................................................................................. 23
Measuring Coverage Statistics During Simulation ................................................................................................................ 24
www.bldeacet.ac.in Page | 3
21EC71 Advanced VLSI
RANDOMIZATION
As designs grow larger, it becomes more difficult to create a complete set of stimuli
needed to check their functionality. You can write a directed testcase to check a certain set of
features, but you cannot write enough directed testcases when the number of features keeps
doubling on each project.
1. the test code that uses a stream of random values to create input to the DUT,
WHAT TO RANDOMIZE
When you think of randomizing the stimulus to a design, the first thing that you might
think of is the data fields. This stimulus is the easiest to create – just call $random. The
problem is that this gives a very low payback in terms of bugs found. The primary types of
bugs found with random data are data path errors, perhaps with bit-level mistakes. You need
to find bugs in the control logic.
You need to think broadly about all design input such as the following.
�Device configuration
�Environment configuration
�Protocol exceptions
�Delays
�Transaction status
Device and environment configuration: What is the most common reason why bugs
are missed during testing of the RTL design? Not enough different configurations are tried.
Most tests just use the design as it comes out of reset, or apply a fixed set of initialization
vectors to put it into a known state. You should randomize the entire environment
www.bldeacet.ac.in Page | 4
21EC71 Advanced VLSI
configuration, including the length of the simulation, number of devices, and how they are
configured. Of course you need to create constraints to make sure the configuration is legal.
Input data: When you read about random stimulus, you probably thought of taking a
transaction such as a bus write or ATM cell and filling the data fields with random values.
You need to anticipate any layered protocols and error injection, plus scoreboarding and
functional coverage.
Protocol exceptions, errors, and violations: Look at all the errors that can occur.
What happens if a bus transaction does not complete? If an invalid operation is encountered?
Does the design specification state that two signals are mutually exclusive? Drive them both
and make sure the device continues to operate. It is frustrating to spend hours tracking back
through code trying to find the root of a malfunction, especially when you could have caught
it close to the source with a simple assertion.
Delays and synchronization: How fast should your testbench send in stimulus?
Always use constrained random delays to help catch protocol bugs. Try to coordinate the
various drivers so they can communicate at different relative timing.
Parallel random testing : You need to plan how to organize your files to handle
multiple simulations. Each job creates a set of output files such as log files and functional
coverage data. You can run each job in a different directory, or you can try to give a unique
name to each file.
www.bldeacet.ac.in Page | 5
21EC71 Advanced VLSI
RANDOMIZATION IN SYSTEMVERILOG
The random stimulus generation in SystemVerilog is most useful when used with
OOP. You first create a class to hold a group of related random variables, and then have the
random-solver fill them with random values. Note that you can randomize individual
variables, but this case is the least interesting. True constrained-random stimuli is created
at the transaction level, not one value at a time.
Note that the constraint expression is grouped using curly braces: {}. This is because
this code is declarative, not procedural, which uses begin...end.
www.bldeacet.ac.in Page | 6
21EC71 Advanced VLSI
variable = $urandom(seed);
The seed is an optional argument that determines the sequence of random numbers
generated. The seed can be an integral expression. for a particular seed, the same value will
get generated.
Example
addr1 = $urandom();
addr2 = $urandom(89);
addr3 = {$urandom(),$urandom()};
data = $urandom * 6;
Example:
addr1 = $urandom_range(30,20);
addr3 = $urandom_range(20,30); //considers max value as '30' and min value as '20'
www.bldeacet.ac.in Page | 7
21EC71 Advanced VLSI
Obviously, you could get pairs of values such as (32, 32) and (2, 62). But you could
also see (-64, 128), as this is a legitimate solution of the equation, even though it may not be
what you wanted. To avoid meaningless values such as negative lengths, use only unsigned
random variables.
Even this version causes problems, as large values of pkt1_len and pkt2_len, such as
32’h80000040 and 32’h80000000, wrap around when added together and give 32’d64 /
32’h40. You might think of adding another pair of constraints to restrict the values of these
two variables, but the best approach is to make them only as wide as needed, and to avoid
using 32- bit variables in constraints.
www.bldeacet.ac.in Page | 8
21EC71 Advanced VLSI
RANDOM GENERATORS
How random is SystemVerilog? On the one hand, your testbench depends on an
uncorrelated stream of random values to create stimulus patterns that go beyond any
directed test. On the other hand, you need to repeat the patterns over and over during debug
of a particular test, even if the design and testbench make minor changes.
The PRNG has a 32-bit state. To calculate the next random value, square the state to
produce a 64-bit value, take the middle 32 bits, then add the original value. You can see how
this simple code produces a stream of values that seem random, but can be repeated by
using the same seed value. SystemVerilog calls its PRNG for a new values for randomize
and randcase.
www.bldeacet.ac.in Page | 9
21EC71 Advanced VLSI
FUNCTIONAL COVERAGE
As designs become more complex, the only effective way to verify them thoroughly is
with constrained-random testing (CRT). Use a feedback loop to analyze the coverage results
and decide on which actions to take in order to converge on 100% coverage. Your first
choice is to run existing tests with more seeds; the second is to build new constraints. Only
resort to creating directed tests if absolutely necessary.
COVERAGE TYPES
Coverage is a generic term for measuring progress to complete design verification.
Your simulations slowly paint the canvas of the design, as you try to cover all of the legal
combinations.
Coverage
CODE COVERAGE
The easiest way to measure verification progress is with code coverage. Here you are
measuring how many lines of code have been executed (linecoverage), which paths through
the code and expressions have been executed (path coverage), which single-bit variables
have had the values 0 or 1 (toggle coverage), and which states and transitions in a state
machine have been visited (FSM coverage).
The reset logic was accidently left out. A code coverage tool would report that every
line had been exercised, yet the model was not implemented correctly.
www.bldeacet.ac.in Page | 10
21EC71 Advanced VLSI
FUNCTIONAL COVERAGE
The goal of verification is to ensure that a design behaves correctly in its real
environment, be that an MP3 player, network router, or cell phone. The design specification
details how the device should operate, while the verification plan lists how that functionality
is to be stimulated, verified, and measured. Consider what happens if a block of code is
missing from the design. Code coverage cannot catch this mistake, but functional coverage
can.
BUG RATE
An indirect way to measure coverage is to look at the rate at which fresh bugs are
found. You should keep track of how many bugs you found each week, over the life of a
project. The bug rate drops, hopefully to zero, as the design nears tape-out. However, just
because the bug rates approaches zero, you are not yet done. Every time the rate sags, it is
time to find different ways to create corner cases.
ASSERTION COVERAGE
Assertions are pieces of declarative code that check the relationships between design
signals, either once or over a period of time. These can be simulated along with the design
and testbench, or proven by formal tools.
Sometimes you can write the equivalent check using SystemVerilog procedural code,
but many assertions are more easily expressed using SystemVerilog Assertions (SVA).
www.bldeacet.ac.in Page | 11
21EC71 Advanced VLSI
MEASURING COMPLETENESS
Your manager constantly asks you, ―Are we there yet?‖ How can you tell if you have
fully tested a design? You need to look at all coverage measurements and consider the bug
rate to see if you have reached your destination.
At the start of a project, both code and functional coverage are low. As you develop
tests, run them over and over with different random seeds until you no longer see increasing
values of functional coverage.
www.bldeacet.ac.in Page | 12
21EC71 Advanced VLSI
The following design has a transaction that comes in eight flavors. The testbench
generates the port variable randomly, and the verification plan requires that every value be
tried. As you can see, the testbench generated the values 1, 2, 3, 4, 5, 6, and 7, but never
generated a port of 0. For this example, the very next random transaction (#33) has a port
value of 0, giving 100% coverage.
www.bldeacet.ac.in Page | 13
21EC71 Advanced VLSI
A cover group can be defined in a class or at the program or module level. It can
sample any visible variable such as program/module variables, signals from an interface, or
any signal in the design (using a hierarchical reference).
Example 9-5 is very similar to the first example of this chapter except that it embeds a
cover group in a transactor class, and thus does not need a separate instance name.
www.bldeacet.ac.in Page | 14
21EC71 Advanced VLSI
This can be done directly with the sample task, as shown in Example 9-5, or by using
a blocking expression in the covergroup definition. The blocking expression can use a wait or
@ to block on signals or events.
www.bldeacet.ac.in Page | 15
21EC71 Advanced VLSI
www.bldeacet.ac.in Page | 16
21EC71 Advanced VLSI
DATA SAMPLING
How is coverage information gathered? When you specify a variable or expression in
a cover point, SystemVerilog creates a number of ―bins‖ to record how many times each
value has been seen. These bins are the basic units of measurement for functional coverage.
If you sample a one-bit variable, a maximum of two bins are created.
A cover point that is a 3-bit variable has the domain 0:7 and is normally divided
into eight bins. If, during simulation, values belonging to seven bins are sampled, the
report will show 7/8 or 87.5% coverage for this point.
The following code takes the chapter’s first example and adds a cover point option
that sets auto_bin_max to two bins. The sampled variable is still port, which is three bits
wide, for a domain of eight possible values. The first bin holds the lower half of the range,
0–3, and the other hold the upper values, 4–7.
www.bldeacet.ac.in Page | 17
21EC71 Advanced VLSI
SAMPLING EXPRESSIONS
You can sample expressions, but always check the coverage report to be sure you are
getting the values you expect. You may have to adjust the width of the computed expression,
as shown in section 2.15. For example, sampling a 3-bit header length (0:7) plus a 4-bit
payload length (0:15) creates only 24 or 16 bins, which may not be enough if your
transactions can actually be 0:23 bytes long.
CONDITIONAL COVERAGE
You can use the iff keyword to add a condition to a cover point.
www.bldeacet.ac.in Page | 18
21EC71 Advanced VLSI
TRANSITION COVERAGE
You can specify state transitions for a cover point. In this way, you can tell not only
what interesting values were seen but also the sequences. For example, you can check if port
ever went from 0 to 1, 2, or 3.
IGNORING VALUES
With some cover points, you never get all possible values. For instance, a 3-bit
variable may be used to store just six values, 0–5. If you use automatic bin creation, you
never get beyond 75% coverage. There are two ways to solve this problem. You can explicitly
define the bins that you want to cover. Alternatively, you can let SystemVerilog automatically
create bins, and then use ignore_bins to tell which values to exclude from functional
coverage calculation.
ILLEGAL BINS
Some sampled values not only should be ignored, but also should cause an error if
they are seen. This is best done in the testbench’s monitor code, but can also be done by
labeling a bin with illegal_bins.
www.bldeacet.ac.in Page | 19
21EC71 Advanced VLSI
CROSS COVERAGE
A cover point records the observed values of a single variable or expression. You may
want to know not only what bus transactions occurred but also what errors happened during
those transactions, and their source and destination.
For this you need cross coverage that measures what values were seen for two or
more cover points at the same time. Note that when you measure cross coverage of a variable
with N values, and of another with M values, SystemVerilog needs NxM cross bins to store
all the combinations.
The cross construct in SystemVerilog records the combined values of two or more
cover points in a group.
Example 9-28 creates cover points for tr.kind and tr.port. Then the two points are
crossed to show all combinations. SystemVerilog creates a total of 128 (8 x 16) bins. Even a
simple cross can result in a very large number of bins.
www.bldeacet.ac.in Page | 20
21EC71 Advanced VLSI
COVERAGE OPTIONS
You can specify additional information in the cover group using options. Options can
be placed in the cover group so that they apply to all cover points in the group, or they can
be put inside a single cover point for finer control. You have already seen the auto_bin_max
option. Here are several more.
PER-INSTANCE COVERAGE
If your testbench instantiates a coverage group multiple times, by default
SystemVerilog groups together all the coverage data from all the instances. But you may
have several generators, each creating very different streams of transactions, so you may
want to see separate reports.
www.bldeacet.ac.in Page | 21
21EC71 Advanced VLSI
COVERAGE GOAL
The goal for a cover group or point is the level at which the group or point is
considered fully covered. The default is 100% coverage.12 If you set this level below 100%,
you are requesting less than complete coverage, which is probably not desirable. This option
affects only the coverage report.
www.bldeacet.ac.in Page | 22
21EC71 Advanced VLSI
If your cover point has only zero or one sample, your constraints are probably not
targeting these areas at all. You need to add constraints that ―pull‖ the solver into new
areas. In Example 9-15, the transaction length had an uneven distribution. This situation is
similar to the distribution seen when you roll two dice and look at the total value.
The problem with this class is that len is not evenly weighted. If you want to make
total length be evenly distributed, use a solve...before constraint.
The alternative to solve...before is the dist constraint. But it is not effective, as len is
also being constrained by the sum of the two lengths.
www.bldeacet.ac.in Page | 23
21EC71 Advanced VLSI
The most practical use for these functions is to monitor coverage over a long test. If
the coverage level does not advance after a given number of transactions or cycles, the test
should stop. Hopefully, another seed or test will increase the coverage.
www.bldeacet.ac.in Page | 24