System Verilog Interview Questions
System Verilog Interview Questions
System Verilog Interview Questions
The basic difference between these two are evident from the nomenclature, i.e,
Initial block starts getting executed during simulation time t=0 while the Final block
gets executed when the simulation is completed.
Before getting into details, there is one similarity between these two sequential block
of codes, both of them gets executed only once during the simulation
Now getting back to the difference between Initial and Final blocks, Initial blocks can
contain some # delays or wait statements or some wait for events, but the Final
block should not contains any such things.
Final block should get executed with 0 simulation time. Ideally this is used for test
case status reporting or some display statements that have to be printed after the
test case execution is completed
As one uses systemverilog as a verification language, one needs to understand how to setup and
control the simulation environment to get maximum reporting without generating erroneous
reports.
Here are some pointers from “Systemverilog for Verification” by Chris Spear that will enhance
your understanding of the simulation phases for systemverilog.
Build Phase
– Generate configuration : Randomize the configuration of the DUT and surrounding environment
– Build environment : Allocate and connect the testbench components based on the
configuration.
A testbench component is one that only exists in the testbench, as opposed to physical
components in the design that are built with RTL.
– Reset the DUT
– Configure the DUT : Based on the generated configuration from the first step, load the DUT
command registers
Run Phase
– Start environment : Run the testbench components such as BFMs and stimulus generators
– Run the test : Start the test and then wait for it to complete. It is easy to tell when a directed
test has completed, but doing so can be complex for a random test. You can use the testbench
layers as a guide. Starting from the top, wait for layer to drain all the inputs from the previous
layer (if any), wait for the current layer to become idle, and wait for the next lower layer. You
should use time-out checkers to make sure the DUT or testbench does not lock up.
Wrap-up Phase
– Sweep : After the lowest layer completes, you need to wait for the final transactions to drain
out of the DUT.
– Report : Once DUT is idle, sweep the testbench for lost data. Sometimes the scoreboard holds
the transactions which never came out, perhaps because they were dropped by the DUT. Armed
with this information, you can create the final report on whether the test passed or failed. If it
failed, be sure to delete any functional coverage results, as they may not be correct.
Packed arrays can be made of only the single bit data types (bit, logic, reg),
enumerated types, and other packed arrays and packed structures. This also
means you cannot have packed arrays of integer types with predefined widths
(e.g. a packed array of byte).
Unpacked arrays
Unpacked arrays can be made of any data type. Each fixed-size dimension is
represented by an address range, such as [0:1023], or a single positive number
to specify the size of a fixed-size unpacked array, such as [1024]. The notation
[size] is equivalent to [0:size-1].
When an array has multiple dimensions that can be logically grouped, it is a good
idea to use typedef to define the multidimensional array in stages to enhance
readability.
+: and -: Notation
SystemVerilog arrays support many more operations than Verilog arrays. The
following operations can be performed on both packed and unpacked arrays.
1A = B; // reading and writing the array
4 if (!rst_n) begin
6 end
7 else begin
1 logic [7:0] a, b, c;
9 if (!rst_n) begin
11 end
12 else begin
20 end
Conclusion
This article described the two new types of SystemVerilog arrays—
packed and unpacked—as well as the many new features that can be used to
manipulate SystemVerilog arrays. The features described in this article are all
synthesizable, so you can safely use them in SystemVerilog based RTL designs
to simplify coding. In the next part of the SystemVerilog arrays article, I will
discuss more usages of SystemVerilog arrays that can make your SystemVerilog
design code even more efficient. Stay tuned!
this keyword is used to refer to class properties. this keyword is used to unambiguously
refer to class properties or methods of the current instance. this is a pre-defined class
handle referring to the object from which it is used,
calling this.variable means object.variable.
The addr, data, write and pkt_type are the property of both class and an argument to the
function new, as the name in both are same.this will lead to an ambiguity in assignment and
values will not be assigned properly.
class packet;
//class properties
bit write;
string pkt_type;
//constructor
addr = addr;
data = data;
write = write;
pkt_type = pkt_type;
endfunction
$display("---------------------------------------------------------");
$display("---------------------------------------------------------");
endfunction
endclass
module sv_constructor;
packet pkt;
initial begin
pkt = new(32'h10,32'hFF,1,"GOOD_PKT");
pkt.display();
end
endmodule
Simulator Output
addr = 0
data = 0
write = 0
pkt_type =