EE5530 Lecture7 Data Types
EE5530 Lecture7 Data Types
Systemverilog 2
logic8_array example;
They can be used to model packets, frames, instructions, commands, floating-point numbers etc
Whenever you declare a variable of a struct type, the necessary number of bits is automatically
allocated. If you assign a struct variable to another, or pass a struct as an argument to a function
or task, as shown in Sample 4-24, all of the bits are copied.
• If a struct is declared packed, as shown in the code snippet, the bits of the struct
fields are laid out consecutively in memory, as shown in Figure.
• This allows the struct to be transparently converted to and from bit vectors or integer
values.
initial begin
i=int'(10.0-0.1);
$display("i = 0d%0d", i); # i = 0d10
r=real'(42);
$display("r = %f", r); # r = 42.000000
b=byte'(256);
$display("b = 0d%0d", b); # b = 0d0
end
• Enumerations (enum)
– Give names to states in a FSM or op-codes in an instruction set
– Can be used instead of parameter or ‘define
Choosing a data structure?
Network packets . Properties: fixed size, accessed sequentially. Use a fixed-size or
dynamic array for fixed- or variable-size packets.
Scoreboard of expected values. Properties: array size not known until run time,
accessed by value, and a constantly changing size. In general, use a queue, as you are
continually adding and deleting elements during simulation. If you can give every
transaction a fixed ID, such as 1, 2, 3, ..., you could use this as an index into the
queue. If your transaction is filled with random values, you can just push them into a
queue and search for unique values. If the scoreboard may have hundreds of
elements and you are often inserting and deleting them from the middle, an
associative array may be faster.
Choosing a data structure?
• Sorted structures . Use a queue if the data comes out in a predictable order or an
associative array if the order is unspecified.
• Modeling very large memories, greater than a million entries . If you do not need
every location, use an associative array as a sparse memory. If you do plan on
accessing every location, try a different approach where you do not need so much
live data. Be sure to use 2-state values packed into 32-bits to conserve simulation
memory.
int i; int i;
logic [7:0] a; wire [7:0] a;
m u1(.itf(i.master));
s u2(.itf(i.slave));
endmodule: top
Modport: Example
interface arb_if(input bit clk);
logic [1:0] grant, request;
logic rst;
module monitor (arb_if.MONITOR arbif);
modport TEST (output request, rst,input grant, clk);
always @(posedge arbif.request[0]) begin
modport DUT (input request, rst, clk, output grant); $display("@%0t: request[0] asserted", $time);
@(posedge arbif.grant[0]);
modport MONITOR (input request, grant, rst, clk); $display("@%0t: grant[0] asserted", $time);
end
endinterface
always @(posedge arbif.request[1]) begin
module arb (arb_if.DUT arbif); $display("@%0t: request[1] asserted", $time);
... @(posedge arbif.grant[1]);
endmodule $display("@%0t: grant[1] asserted", $time);
module test (arb_if.TEST arbif); end
...
endmodule endmodule
Interface : Advantages
An interface is ideal for design reuse. When two blocks communicate with
a specified protocol using more than two signals, consider using an
interface.
The interface takes the jumble of signals that you declare over and over
in every module or program and puts it in a central location, reducing the
possibility of misconnecting signals.
To add a new signal, you just have to declare it once in the interface, not
in higher-level modules, once again reducing errors.
You must now use the interface name in addition to the signal name, possibly
making the modules more verbose.
If you are connecting two design blocks with a unique protocol that will not be
reused, interfaces may be more work than just wiring together the ports.