Verilog 2internals
Verilog 2internals
3.1 Introduction
As you verify your design, you need to write a great deal of code, most of
which is in tasks and functions. System Verilog introduces many incremental
improvements to make this easier by making the language look more like C,
especially around argument passing. If you have a background in software
engineering, these additions should be very familiar.
3.2 Procedural Statements
System Verilog adopts many operators and statements from C and C+t.
You can declare a loop variable inside a £or loop that then restricts the scope
of the loop variable and can prevent some coding bugs. The increment ++ and
decrement -- operators are available in both pre- and post- form. If you have
a label on a begin or fork statement, you can put the same label on the
matching end or join statement. This makes it easier to match the start and
finish of a block. You can also put label on other System Verilog end
statements such as endmodule, endtask, endfunction, and others that
you will learn in this book. Example 3-1 demonstrates some of the new
constructs.
Two new statements help with loops. First, if you are in a loop, but want to
skip over rest of the statements and do the next ileration, use cont inue. If
you want to leave the loop immediately, use break.
The following loop reads commands from a file using the amazing file VO
code that is part of Verilog-2001. If the command is just a blank line, the code
just doesa continue and skips any further processing of thecommand. If the
command is "done," the code does a break to terminate the loop.
Example 3-2 Using break and continue while readinga file
initial begin
logic [127 :0] cmd;
integer £ile, C;
In Example 3-11, the initial block can access the data from memory as
soon as bus.enable is asserted, even though the bus_read task does not
return until the bus transaction completes, which could be several cycles later.
Since the data argument is passed as ref, the edata statement triggers as
soon as data changes in the task. If you had declared data as output, the
edata statement would not trigger until the end of the bus transaction.
Example 6-57 shows a simple PRNG, not the one used by SystemVerilog.
The PRNG has a 32-bit state. To caleulate the next random value, Kquare the
stale to produce a 64-bit value, take the middle 32 bits, then add the original
value.
Exumple6-57 Smple pseudarandon number generator
reg (3l:0) state 32"hl2345678;
Eunction reg [31:0) y_ randomp
reg [63 10) 641
tate:
te te64 >> 16) Btate
my _random state;
endfunction
You can see how this simple code produces a stream of values thal seem
random, but can be repeated by using the same seed value. SystemVerilog
calls its PRNG for a new values for randoad se and randcase.
The following task looks at the bus after five cycles and then creates a
local variable and attempts to initialize it to the current value of the address
bus,
even more time aware by using the classic Verilog $timeformat and
$realtime routines.
Example 3-22 Time literals and Stime format
module tining:
timeunit lns
timeprecision lps
initial begin
$timefornat (-9, 3, "ns", 8);
$display( "@tt", $realtime) I/ 1.00Ons
W2ns $display( "@%t", $realtine) ; I7 3.000ns
#0.lns $display ("@tt", $realtine ) 17 3.100ns
W41ps $display("tt, $realtina ) 17 3.14lns
end
endmodule
Chapter 6.: Randomization 157
function does not return a value, but, because il is not a task, does not con
sume time. If you wunt to call a debug routine from pre_randoize or
Post randomize, it must be a function.
Sum isa
Left bathtub Right
Exponentlal Exponential
Values WLDIT
Example 6-24 Building a bathtuh distribution
class Bathtub
int value; /I Random variable with bathtub dist
int WIDTH 50, DEPTH=4, seedel
183/326
Every time this object is randomized. the variable value gets updated.
Across many rundomizations. you will see the desired nonlinear distribution.
You can use all the Verilog-1995 distribution functions this way. plus sev
eral that are new for SystemVerilog. Some of the useful functions include the
following.
Sum isa
bathtub Right
&Exponential
Left Exponential
WPLDNH
lo Values
Example 6-24 Huilding a bathtub distr1bution
class Bathtub dist
Lnt value ; I| Randam variable writh bathtub
seedul
int WIDTH = 50, DEPTH=4,
tunction void pre_randomize()p
culate the left curve of the tub
value $dist exponential(seed,, DEPTH)
WIDTH) value WIDTH)
if (value
left or right curve
17 RaDdomly put this point on the
if ($urandom range (1))
value WIDTH - value;
endfunction
ondclass
People also ask
https://www.tutorialspoint.com » wh...
What is Strobe Control? - Tutorialspoint
MORE RESULTS
UPSC Fever X
Data bus
Source Destination
unit Strobe unit
Strobe
Share Save
Data
Dnta Bus
Strobe
Buck Dagta
(Beck dagrun
Des ha
Computer Organisation A.
Computer Organisation ..
te us
Data Vald
* Q
Discover Search Saved
8:45 49" l 70%
< 50
with thousands or millions of elements, which can cause the random solver to
take an excessive amount of time.
You can send a random array of data into a design, but you can also use it
to control the flow. Perhaps you have an interface that has to transfer four data
words. The words can be sent consecutively or over many cycles. A strobe
signal tells when the data is valid. Here are some legitimate strobe pattems.
sending four values over ten cycles.
62 Randam strube wavelams
You can create these putterns using a random urray. Constrain it to have
four bils enabled out of the entire range using the sun function.
Example 6-36 Random strobe pattem class
paraneter NAX_TRANSPER_LEN = 10;
class StrobePati
rand bit utrobe [AX TRANSP
traint C se {Btrobe.f
endglasg
In general, a routine definition or call with no arguments does not need the empty parentheses (). This
book leaves them out except as heeded for clarity
requires you to declare some arguments twice, once for the direction, and
once for the type.
Example 3-6 Verilog-1995 routine arguments
task mytask2;
output [31:0) x
reg (31:0) x;
input Y;
endtask
With System Verilog. you can use the less verbose C-style. Note that you
should use the universal input type of logic.
Example 3-7 C-style routine arguments
task mytaskl (output logic [3l:0) x,
input logic y):
endtask
endtask
The arguments a and b are input logic, Ibit wide. The arguments u and v
are 16-bit output bit types.
k.
This approuch changes the values used not only by Genl, but also by
Gen2.
In SystemVerilog, there is a separate PRNG for every object and thread.
Changes to one object don't affect the random values seen by others.
Figure 6-5 Separate random generaton pet object
PRNG 1 PRNG 2
a,b
O.p
e,
class denl; class Gen2
Transaction tra, trb Transaetion trl, tr2,
trb.randonise()
endclass
tr2.rAndomise()
andclas
Every object und thread huve its own PRNG and unique seed. When a new
object or thread is started, its PRNG is seeded frum its purent's PRNG. Thus a
205/326
single seed specified ut the start of simulation can create many streans of ran
dom stimulus, euch distinct.