System Verilog Interview Questions
System Verilog Interview Questions
Q1. What is the difference between logic and bit in System Verilog?
Q5. What is the difference between System Verilog packed and unpacked array?
Q12. Explain the difference between deep copy and shallow copy?
Q14. What is the difference between data types logic and reg?
1
SYSTEM VERILOG INTERVIEW QUESTIONS
Q22. What is the difference between logic[7:0] and byte variable in System Verilog?
Q23. What is the difference between “case”, “casex” and “casez” in System Verilog?
Q24. What is the difference between new () and new [ ] in System Verilog?
Q25. What are the main regions inside a System Verilog simulation time step?
Q27. What is the difference between fork join, fork join_any and fork join_none?
2
SYSTEM VERILOG INTERVIEW QUESTIONS
3
SYSTEM VERILOG INTERVIEW QUESTIONS
join_any
$display($time,"Process-5");
a)5
b) 0
c)10
d)25
8. System verilog tasks allows:
a) defaults arguments type is logic if no type has been specified.
b) multiple statements within task without requiring a begin ..end or fork..join.
c) to declare automatic variable in static task and static variable in automatic task.
d) All of the above.
9. System verilog functions allows:
a) function output an inout ports
b) Any expression can be used as function call argument.
c) A function without a range or return type declaration return a one bit value.
d) All of the above
10. Modport is used to
a) to declare input and output skew
b) declare directions of signals
c) to synchronize signals
d) make interface complex
11. Which of the following satisfies repetition operator in system verilog assertions?
a) property p;
@(posedge clk) a|->##1 b ##1 b ##1 b;
endproperty
a:assert property(p);
b) property p;
@(posedge clk) a|->##1 b[*3];
endproperty
a:assert property(p);
c) property p;
@(posedge clk) a|->##1 b[->3] ##1 c;
endproperty
a:assert property(p);
d) Both a and b
12. What will be randomizing result of following code?
class packet;
rand bit[3:0] addr;
endclass
class packet2 extends packet;
constraint addr_range{addr <5;}
endclass
module const_inhe;
4
SYSTEM VERILOG INTERVIEW QUESTIONS
intial begin
packet pkt1;
packet2 pkt2;
pkt1=new();
pkt2=new();
repeat(2) begin
pkt1.randomize();
$display("\tpkt2 :: addr=%0d",pkt2.addr);
end
end
endmodule
a)pkt2=4,
pkt2=3
b)pkt2=x,
pkt2=x
c)pkt2=0,
pkt2=0
d)runtime error
13. What will be the output of following code?
class packet;
bit[31:0] addr;
static bit[31:0] id;
function display(bit[31:0]a,b);
$display("values are %0d %0d",a,b);
endfunction
endclass
module sro_class;
int id=10;
initial begin
packet p;
p=new();
packet::id=20;
p.display(packet ::id,id);
end
endmodule
a)20,10
b)10,20
c) Syntax error
d)Uninitialized arguments.
14. What will be the output of following code?
initial begin
function void current_time;
$display("\tcurrent simulation is %0d",$time);
5
SYSTEM VERILOG INTERVIEW QUESTIONS
endfunction
#10;
current_time();
end
a) message will get printed after 10ns
b) compile error
c) run time error
d) None of the above
15. In associative array, how to check if elements exists at specified index?
a) Using array querying method.
b) Using array ordering method.
c) Using queue
d) None of the above
16. How to increase the size of dynamic array by retaining its old values?
int d_array[];
d_array=new[5];
a) d_array=new[10] d_array;
b)d_array=new[10];
c) Both a and b
d) None of the above
17. Which of the following statement is true?
a) In case of unique if,there will be error if more than one condition is true.
b) In case of unique if,there will be error if no condition is true.
c) In case of priority if,there will be error if no condition is true.
d) All of the above
18. Wire can be driven by multiple drivers.
a) True
b)False
19. Which of the following is the declaration for a queue?
a) int a[$];
b) int a[];
c) int a;
d) None of the above
20. How to disable randomization of particular variable in a class?
a) by setting rand_mode of particular variable to '0'
b) by setting constraint_mode to '0'
c) by avoiding randomization
d) by constraining particular variable to '0'
Answers: 1.a 2.d 3.a 4.d 5.c 6.d 7.a 8.d 9.d 10.b 11.d
12.c 13.a 14.b 15.d 16.a 17.d 18.a 19.a 20.a
6
SYSTEM VERILOG INTERVIEW QUESTIONS
7
SYSTEM VERILOG INTERVIEW QUESTIONS
8
SYSTEM VERILOG INTERVIEW QUESTIONS
18. Which blocking statement can be used to ensure blocking until all child threads of
fork-join_none are done?
a) wait fork
b) #0 ns
c) #100 ns
d) None of the above
These type of questions asked in written test of product and service based companies like
synopsys,nvidia,cadence,nxp,mentor graphics,qualcomm,xilinx,amd and intel etc.
Answers: 1.b 2.d 3.a 4.b 5.b 6.c 7.a 8.c 9.b 10.c 11.d 12.a 13.a 14.c 15.c 16. b
17.b 18.a
9
SYSTEM VERILOG INTERVIEW QUESTIONS
1. How will you test the functionality of interrupts using functional coverage?
2. What is the use of scope resolution operator?
3. How do you implement randc in SystemVerilog?
4. What is inheritance?
5. What is DPI? Explain DPI export and import.
6. What is semaphore and in what scenario is it used?
7. Difference between fork-join, fork-join_any, and fork-join_none
8. Difference between static and automatic variables
9. Difference between module and program block?
10. Difference between dynamic and associative arrays
How will you test the functionality of interrupts using functional coverage?
Testing the functionality of interrupts using functional coverage involves the following steps:
1. Define functional coverage goals: First, you need to define your functional coverage
goals. These goals should be specific to the interrupts you want to test. For example,
you might define goals for interrupt latency, interrupt frequency, or interrupt priority
handling.
2. Create a testbench for interrupts: Next, you need to create a testbench that generates
interrupts with different characteristics. This testbench should also monitor the
behavior of the design under test (DUT) in response to the interrupts.
3. Implement functional coverage: You can then implement functional coverage in your
testbench to track how often each of the defined functional goals is achieved. You can
use standard SystemVerilog constructs like covergroups, coverpoints, and bins to
define and track the functional coverage.
4. Analyze the functional coverage results: Finally, you can analyze the functional
coverage results to determine how well your testbench tests the desired interrupt
functionality. Based on the results, you can make adjustments to your testbench to
improve the tests.
The scope resolution operator in SystemVerilog is denoted by the double colon '::' symbol. The
basic purpose of this operator is to specify the scope in which an identifier is defined or should
be searched for.
10
SYSTEM VERILOG INTERVIEW QUESTIONS
is defined in a top-level module and is used in a lower-level module, then we use the
scope resolution operator to specify the scope of 'clk'.
2. Resolving naming conflicts: When a design has two or more variables or modules with
the same name, the scope resolution operator can be used to differentiate the variables
or modules by specifying their scope.
package ahb_pkg;
typedef enum {READ, WRITE} e_access;
endpackage
package wishbone_pkg;
typedef enum {WRITE, READ} e_access;
endpackage
3. Accessing static variables and functions: The scope resolution operator is also used
to access static properties and methods in a class.
4. Accessing items in package: Elements in a package can be imported
using import with scope resolution operator.
The randc keyword in SystemVerilog will first exhaust all combinations possible before
repeating a value. This is different from rand keyword where the same value may repeat even
before all combinations are exercised.
Here's an example :
class ABC;
rand bit [1:0] x; // randomization can give x = 3, 1, 1, 0, 3, 0,
2, 2
randc bit [1:0] y; // randomization can give y = 1, 3, 0, 2, 3, 1,
2, 0
endclass
11
SYSTEM VERILOG INTERVIEW QUESTIONS
What is inheritance?
DPI stands for Direct Programming Interface, which is a mechanism in SystemVerilog for
integrating SystemVerilog design and verification code with external C/C++ code. It enables
interoperability between SystemVerilog and other high-level programming languages, which
is not possible with traditional Verilog.
DPI export is used to export C/C++ functions to SystemVerilog. This means that a C/C++
function can be used as a task or function in SystemVerilog by creating an import task or import
function.
And here's an example of how to import this function in SystemVerilog using DPI import:
12
SYSTEM VERILOG INTERVIEW QUESTIONS
The main difference is that a static variable gets initialized once before time 0 at some memory
location and future accesses to this variable from different threads or processes access the same
memory location. However, an automatic variable gets initialized every time the scope where
it is declared gets executed and stored in a different location every time.
A module is the primary container for all RTL design code and allows hierarchical structuring
of design intent. A program block on the other hand is a verification container introduced in
SystemVerilog to avoid race conditions in the testbench by executing its contents at the end of
the time step.
A dynamic array is an array whose size can be changed during runtime. Elements of the array
are stored in a contiguous block of memory, and the size is determined when the array is
created. An associative array, on the other hand, is also known as a dictionary or a map. It is a
collection of key-value pairs where each key has a corresponding value.
In a dynamic array, the elements are accessed using an index, which refers to the position of
the element in the array. In an associative array, elements are accessed using the key.
13
SYSTEM VERILOG INTERVIEW QUESTIONS
A deep copy is one where nested class object contents are also entirely copied over into the
new class object. A shallow copy is one where nested class objects are not copied but instead
handles are simply assigned. So, if the original class object changes its contents, then
the copied class also see the same contents.
All constraints are by default enabled and will be considered by the SystemVerilog constraint
solver during randomization. A disabled constraint is not considered during randomization.
Constraints can be enabled or disabled by constraint_mode() .
class ABC;
rand bit [3:0] data;
In Verilog/SystemVerilog, code coverage and functional coverage are two types of verification
metrics used to measure the completeness of a testbench.
14
SYSTEM VERILOG INTERVIEW QUESTIONS
Code coverage measures the extent to which the testbench has exercised the RTL code being
verified. It tracks which lines of the code were executed during simulation, which branches of
conditional statements were taken, and which blocks of code were repeated in loops. Code
coverage is often measured in terms of statement coverage, branch coverage, and condition
coverage.
Functional coverage, on the other hand, measures the completeness of the functional
requirements being verified. It tracks how many and which functional scenarios were exercised
during simulation. Functional coverage is defined based on functional coverage points, which
are specific items or aspects of the functional specification that need to be tested. For example,
a functional coverage point could be the number of packets transmitted and received correctly
by a network interface block.
The key differences between code coverage and functional coverage are:
1. Purpose: Code coverage is used to ensure that every line of code in the design has been
tested while functional coverage is used to ensure that all functional requirements of
the design have been tested.
2. Measurement: Code coverage is measured based on the number of lines of code
executed, branches explored, and conditions evaluated during simulation, while
functional coverage is measured based on the number of functional coverage points
exercised during simulation.
3. Scope: Code coverage provides insight into the completeness of the implementation of
the design, while functional coverage provides insight into the completeness of the
specifications of the design.
What is ignore_bins?
Ignoring bins can be useful when there are some bins that are not meaningful for the verification
objectives, or if it is not feasible to cover some of the bins. By ignoring some bins, the coverage
report can focus on the meaningful and feasible coverage points.
To ignore bins in a functional coverage point, the ignore_bins attribute can be used. Here's an
example:
covergroup my_covergroup;
// Coverage points definitions
15
SYSTEM VERILOG INTERVIEW QUESTIONS
coverpoint my_var {
bins zero = {0};
ignore_bins unused = {10};
}
endgroup
Two-state variables have only two possible values: 0 and 1. In two-state variables, there is no
distinction between "unknown" and "floating" values. Two-state variables are commonly used
in simple designs, or where the value of a variable is either known or unknown, but not floating.
Four-state variables, on the other hand, have four possible values: 0, 1, X, and Z. Four-state
variables are used to model the behavior of digital circuits, where the signal can either be a
known logic value, or a floating or unknown value.
To make sure that address ranges from 0x2000 to 0x9000 are covered in
Verilog/SystemVerilog, we can use a covergroup to define coverage points for each address
value within the range. Here's an example:
Within the "addr_coverage" point, we declare three bins to cover the address range. The bin
"addr_0x2000" covers the value 0x2000, while the bin "addr_0x2001_0x8FFF" covers the
range from 0x2001 to 0x8FFF. Finally, the bin "addr_0x9000" covers the value 0x9000.
16
SYSTEM VERILOG INTERVIEW QUESTIONS
1. Testbench layer: This is the top layer of the verification architecture, which contains
test scenarios that stimulate the design under test (DUT) and verify its functionality.
The testbench layer is responsible for test management, collecting and analyzing
results, and reporting errors and warnings.
2. Verification IP (VIP) layer: The VIP layer provides hardware and software
components that are reusable and pre-verified, such as memory models, bus functional
models (BFMs), and protocol checkers. The VIP layer abstracts the DUT interface and
behavior, allowing the testbench layer to focus on DUT functionality.
3. Functional block layer: This is the lowest layer of the verification architecture, which
contains individual blocks of the design. The functional block layer specifies the
behavior and function of the DUT at the RTL level. The functional block layer includes
RTL code, gate-level models, and timing models.
The layered architecture approach promotes reusability and scalability of the verification
environment. Each layer can be independently designed and tested, facilitating incremental
verification of the DUT. It allows efficient and thorough testing for complex designs with
multiple blocks, interfaces, and protocols. By separating concerns and providing abstraction,
layered architecture makes verification more manageable and improves the quality of the
design.
In the context of digital design verification, the verification cycle refers to the iterative process
of designing, developing, running tests, and debugging to ensure the design meets the
functional and performance requirements. The verification cycle generally consists of design
verification plan, testbench development, test execution and verification closure.
A dynamic array is a collection of similar data elements whose sizes and memory locations are
allocated dynamically during the runtime of the program. The size of the array can be changed
at runtime, making it more flexible than a static array.
17
SYSTEM VERILOG INTERVIEW QUESTIONS
A queue is also a collection of similar data elements, but its primary function is to store and
retrieve data elements in a specific order, FIFO (First in First out), or LILO (Last in Last out).
It is a sequential data structure that stores and retrieves elements in a specific order.
It follows the FIFO (First In First Out) or LILO (Last In Last Out) rule to maintain the
order of elements.
It has two main functions of adding elements to the rear and removing elements from
the front.
In object-oriented programming, both structures and classes can be used to define custom data
types with properties and functions, but there are some differences in their behavior and usage.
Access Modifiers: Classes have private, public, and protected access modifiers for data
members and member functions. Structures only support public access modifiers.
Inheritance: Classes support inheritance, where a new class can be derived from a base
class. Structures do not support inheritance.
Constructors and Destructors: Classes have constructors and destructors that get
called when objects are created and destroyed, respectively. On the other hand,
structures do not have constructors or destructors.
Methods: Classes can have functions and tasks that operate on its members, but
structures do not have them.
18
SYSTEM VERILOG INTERVIEW QUESTIONS
In SystemVerilog, a virtual function is a type of function that allows a base class to define a
function signature which can be overwritten in a derived class. This means that a virtual
function can be customized by a subclass to perform a different function than the base class.
Virtual functions are an important aspect of object-oriented programming (OOP) and are used
heavily in verification methodologies such as the Universal Verification Methodology (UVM).
In UVM, virtual functions are used to customize the behavior of verification components and
facilitate the reuse of code across different testbenches.
Static and dynamic casting are type conversion operations used to convert between different
data types.
Static casting is a compile-time operation in which the compiler converts a given data type into
another data type. It is called static casting because the conversion is determined and enforced
by the compiler at the time of compilation. Static casting is a simple and efficient process, but
it can lead to errors or loss of information if the conversion is not compatible.
Dynamic casting, on the other hand, is a run-time operation in which the type of an object is
determined at run-time and then explicitly converted to a different type. Dynamic casting is
more complex and less efficient than static casting, but it is safer as it can detect and handle
errors during runtime.
19
SYSTEM VERILOG INTERVIEW QUESTIONS
In Verilog and SystemVerilog, virtual and pure virtual functions are used in polymorphism and
inheritance.
A virtual function is a function declared in a base class that can be overwritten in a derived
class, enabling runtime polymorphism. When the function is called on an object of the derived
class, the derived class's implementation of the function is executed. If there is no
implementation in the derived class, the base class's implementation is executed. The syntax
for a virtual function is declared by using the keyword virtual in the base class.
A pure virtual function, on the other hand, is a virtual function that has no implementation in
the base class. This means that derived classes must provide an implementation for the
function. If a derived class doesn't overwrite the pure virtual function, it will remain abstract
and cannot be instantiated. Pure virtual functions are used to create abstract classes that act as
a blueprint for derived classes.
In programming languages, the while loop and do-while loop are used for repetitive execution
of a code block based on certain conditions. Here are the differences between while and do-
while loops:
1. Execution: In the while loop, the condition is checked first, and if it is true, then the
code block is executed. However, in the do-while loop, the code block is executed first,
20
SYSTEM VERILOG INTERVIEW QUESTIONS
and then the condition is checked. This means that the code block will be executed at
least once in the do-while loop, even if the condition is initially false.
2. Loop condition: In the while loop, the loop condition is checked at the beginning of
each iteration. If the condition is false, the loop is terminated, and the control goes to
the next statement after the loop. However, in the do-while loop, the loop condition is
checked at the end of each iteration. This means that the code block is executed at least
once, even if the condition is false.
3. Initialization: In the while loop, the initialization of the loop variable or counter
happens outside of the loop. This makes it possible to create an infinite loop if the
initialization is incorrect. However, in the do-while loop the initialization of the loop
variable or counter can be done within the loop.
4. Use Cases: The while loop is used in cases where the condition is unknown, and the
loop should not execute if the condition is false. In contrast, the do-while loop is used
when we want the loop to execute at least once, even if the condition is false.
Bidirectional constraints are used to specify a relationship between two or more variables or
signals, such that the value of one variable is dependent on the value of the other variable(s).
In SystemVerilog, constraints are solved bidirectionally.
For example, if we have two signals, data_valid and data_ready we can specify the constraint
that when data_valid is asserted data_ready must be asserted, using the following conditional
constraint:
integer is a 4-state data type where as int is a 2-state data type. Both can hold 32-bit signed
numbers.
21
SYSTEM VERILOG INTERVIEW QUESTIONS
Here, the modulo operator % is used to retrieve the remainder of a division operation, and the
constraint ensures that the remainder of the division of my_variable by 5 is equal to zero,
which means my_variable is divisible by 5.
Parameterized classes in object-oriented programming (OOP) are classes that are defined with
one or more parameters, allowing them to be customized or specialized during their
instantiation or creation.
22
SYSTEM VERILOG INTERVIEW QUESTIONS
Yes, it's possible to override existing constraints in SystemVerilog using inline constraints or
inheritance.
class ABC;
rand bit [3:0] data;
module tb;
initial begin
ABC abc = new;
module tb;
initial begin
DEF def = new;
23
SYSTEM VERILOG INTERVIEW QUESTIONS
def.randomize();
end
endmodule
What will be your approach if functional coverage is 100% but code coverage is too low
?
If the functional coverage is 100% but the code coverage is too low, it typically means that
there are parts of the code that are never executed and therefore not covered by the test cases.
Here are some possible approaches to improve code coverage:
1. Review the code and identify the uncovered areas: You can go through the code
manually or use a code coverage tool to identify the parts of the code that are not
covered by the tests. This will help you to focus on the areas that need to be tested more
thoroughly.
2. Add new test cases: Once you have identified the uncovered areas, you can add new
test cases to cover them. You can use different techniques such as random testing,
directed testing or assertion-based testing to create new test cases.
3. Modify existing test cases: You can also modify the existing test cases to cover the
uncovered areas. For example, you can change the parameters or stimuli of the test
cases to target specific areas of the code.
4. Use code coverage metrics: You can use code coverage metrics as a guide to track
your progress and ensure that you are improving overall coverage. You can set targets
for specific types of coverage, such as branch or statement coverage, and monitor your
progress as you add new test cases or modify existing ones.
5. Use techniques like coverage-driven verification and constrained-random testing:
These techniques focus on generating test cases to cover specific portions of the design,
which can help you achieve better code coverage.
Assertions are statements that specify a particular relationship between two or more signals or
variables. There are two main types of assertions, which are as follows:
24
SYSTEM VERILOG INTERVIEW QUESTIONS
Array manipulation functions can be used to query indices and values in SystemVerilog arrays.
module tb;
int fruit_hash [string];
string idx_q [$];
initial begin
fruit_hash["apple"] = 5;
fruit_hash["pear"] = 3;
fruit_hash["mango"] = 9;
// Output
// idx_q= '{"apple", "mango", "pear"}
The function must return a value that can be used in the constraint expression. Here's an
example:
class ABC;
rand bit my_val;
constraint my_val_c {
my_val == rand_range(a, b);
}
endmodule
25
SYSTEM VERILOG INTERVIEW QUESTIONS
In pass-by-value method, a copy of the value of the argument is passed to the function or
method. Any change made to the value inside the function or method does not affect the
original value of the argument.
The initial block is executed at the start of simulation, i.e. at time 0 units. This is useful for
initializing variables and stting up initial configurations. This is the very basic procedural
construct supported since the first version of Verilog.
However, the final block was introduced in SystemVerilog and is executed just before the
simulation ends. This does not consume any time and hence is very ideal to do last minute
housekeeping tasks and print reports.
The default value of all 2-state variables are zero, and 4-state variables are X. Inputs that are
not connected are Z.
1. Code reusability: Polymorphism enables code reuse, as objects of different classes can
be treated as if they are objects of the same class. This means that common behaviors
and methods can be defined in a superclass and inherited by multiple subclasses.
2. Flexibility and extensibility: Polymorphism allows objects to behave differently based
on the context in which they are called, improving the flexibility of the code. It also
26
SYSTEM VERILOG INTERVIEW QUESTIONS
The this keyword is used to explicity reference the current class object. This is mostly used
within class definitions to be able to specifically reference variables and methods belonging to
the same class.
27
SYSTEM VERILOG INTERVIEW QUESTIONS
Both reg and logic are used to store 4-state logic values that can be referenced later. The
main difference is that logic signals can be used in both procedural and continuous
assignments whereas reg can only be used in procedural code.
Both operators are used in distribution constraints to assign weightage to different values in the
distribution.
28
SYSTEM VERILOG INTERVIEW QUESTIONS
The :/ operator assigns the specified weight to the item, or if the item is a range, then the
weight of each value is divided by N. The := operator assigns the specified weight to the item
or if the item is a range, then to every value value in the range.
class ABC;
rand bit [3:0] data;
endclass
module tb;
initial begin
ABC m_abc = new;
m_abc.data.rand_mode(0); // Disable randomization
Code coverage is a metric used to measure how well tests have exercised the design under test.
It typically reports on the percentage of execution achieved across various dimensions of the
design, such as statements, branches, and expressions, toggle, assertions and FSM.
Here's an example constraint that detects odd numbers of ones in an 8-bit sequence:
class ABC;
rand bit [7:0] data;
module tb;
initial begin
29
SYSTEM VERILOG INTERVIEW QUESTIONS
A class member declared as local is available only to methods inside the class and are not
visible within subclasses.
A class member declared as protected is available to methods inside the class and also to
methods within subclasses.
An interface is a collection of signals that allow connections to the DUT from the testbench.
The handle to this interface is made available in classes by making it virtual . Hence
a virtual interface is nothing but a handle that can hold a reference to the actual interface.
Remember that an interface is declared at the testbench top level so that it can be passed to the
DUT. So, rest of the components get access to this interface via a virtual interface.
30
SYSTEM VERILOG INTERVIEW QUESTIONS
class wishbone_monitor;
virtual wishbone_if m_vif; // A virtual interface handle
logic is a new SystemVerilog data type, when compared to Verilog which can be used in place
of reg and wire in both procedural blocks and continuous assignments. It removes the hassle
of having to redefine an existing signal as reg or wire depending on where it is used.
31
SYSTEM VERILOG INTERVIEW QUESTIONS
function random();
bit [7:0] array[$];
Assume memory region from 0x0 to 0x100. There is a small region in between from 0x20 to
0xE0 that is reserved. Write system verilog constraints to choose a block of memory of size 16
bytes that is outside the reserved region and inside the entire memory range. The starting
address of the block should be 4-byte aligned.
constraint c_addr { addr inside {[0:'h100]}; // Ensure its within memory region
32
SYSTEM VERILOG INTERVIEW QUESTIONS
Assume a memory region exists from 0x2000 to 0x4000 that is byte addressable. Write SV
constraints to randomly pick an address within this memory region that is aligned to 4-byte
boundary.
Assume a class called "ABC" has been used throughout in a project. In a derivative project,
you had to extend "ABC" to form "DEF" and add some more variables and functions within it.
What will happen if you try to use an object of "ABC" that was created in the legacy testbench
to access these new variables or functions ?
It will result in a compilation error because the new variables do not exist in the base class.
Instead you need to declare a local variable of type "DEF" and perform a dynamic cast if
required to access the new variables and functions.
Randomly generate 8, 16, 32, 64 with equal probability using SystemVerilog constructs.
module tb;
initial begin
bit [31:0] result;
33
SYSTEM VERILOG INTERVIEW QUESTIONS
A queue is a variable size ordered collection of elements of the same type. Read more
on SystemVerilog Queues
rand randomizes the variable and can have repetitive values before the entire set of allowable
values are used. For example, a 2-bit variable when used with rand can give values 1, 3, 3, 2,
1, 3, 0
randc randomizes the variable and repeats a value only after the entire set of allowable values
are used. For example, a 2-bit variable when used with randc can give values [1, 3, 2, 0], [0,
3, 1, 2], 1 ... The values in the square brackets show a set.
How can we reference variables and methods defined in the parent class from a child
class ?
The super keyword is used to access variables and methods of the parent class and is a very
basic construct of OOP.
An extern keyword is used to define methods and constraints outside the class definition. For
example, we could have the declaration of functions and constraints within the class body, but
do the complete definition later on outside the class body.
34
SYSTEM VERILOG INTERVIEW QUESTIONS
Give one way to avoid race conditions between DUT and testbench in a verification
environment
Clock edges are the most probable points for a race condition to arise. The DUT may sample
one value but the testbench may sample something else.
Although race conditions may arise from improper coding practices, use of SystemVerilog
Clocking Blocks allows the testbench to sample DUT appropriately and drive inputs to the
DUT with a small skew. Also, this allows the skews to be changed later on with minimal code
change.
Race condition can also be avoided by the use of program blocks and the use of non-blocking
assigments.
35
SYSTEM VERILOG INTERVIEW QUESTIONS
In SystemVerilog, a bit is a single binary digit that can have a value of 0 or 1, while logic is a
data type used for representing a single wire or net that can have multiple states such as 0, 1, Z
(high-impedance), X (unknown), or L (weakly driven low) and H (weakly driven high).
// To check if signal is X
if ($isunknown(xyz)) begin
$display("xyz is unknown or has value X");
end
Assume two base classes A and B, and two derived classes C and D where this relation between
classes is unknown to end user. How do you find base class for each derived class?
class A;
36
SYSTEM VERILOG INTERVIEW QUESTIONS
class B;
module tb;
initial begin
A m_a = new();
B m_b = new();
C m_c = new();
D m_d = new();
// Successful cast implies that the second arg is a child of first arg
if ($cast(m_a, m_c))
$display("C is a child of A");
if ($cast(m_a, m_d))
$display("D is a child of A");
if ($cast(m_b, m_c))
$display("C is a child of B");
if ($cast(m_b, m_d)
$display("D is a child of B");
end
endmodule
Write SV code to wait for a random delay in range 100 to 500 ns.
Delays are indicated by the # construct and a random delay can be written as follows.
`timescale 1ns/1ps
module tb;
initial begin
int delay;
37
SYSTEM VERILOG INTERVIEW QUESTIONS
end
endmodule
parameter is used to define compile-time constants used within modules, which are values
that can be evaluated and assigned before the simulation starts. It can be used to specify
parameters such as width, depth, or delay of modules.
typedef is used to define custom data types that can be reused throughout the design. It can be
used to define complex data types such as structures, arrays, and enumerated types. It is used
to make the code more readable and easier to understand by encapsulating complex data types
within a single type name.
typedef struct {
logic [7:0] addr;
logic [31:0] data;
} request_t;
request_t my_req;
my_req.addr = 8'h22;
my_req.data = 32'h12345678;
What is an alias?
38
SYSTEM VERILOG INTERVIEW QUESTIONS
alias is a keyword used to declare an alternate name for a variable or net. It allows access to
the same object through multiple names. The new name created using the alias keyword refers
to the same variable or memory location as the original variable.
module tb;
bit [7:0] q [$];
bit [7:0] tmp [$];
initial begin
repeat (9) q.push_back($random);
endmodule
A clocking block is used to model clock and reset signals and their associated timing control
signals. It provides a way of defining a set of timing signals as well as their phases and signal
transitions.
A modport is used to group a set of port declarations into a named entity. It allows designers
to specify multiple port configurations and to limit access to specific module interfaces.
$random returns signed integer values, whereas $urandom returns an unsigned integer value.
int data1;
bit [31:0] data2;
39
SYSTEM VERILOG INTERVIEW QUESTIONS
An always block is a concurrent process that runs forever and gets triggered based on changes
to signals in the sensitivity list. A program block is intended to be a testcase that applies
stimulus to the DUT and finish at some point in time. Having an always block will stall the
program from coming to an end and hence it doesn't make sense to include it in a program
block.
Better coverage granularity: Cross-coverage allows the user to define more specific
coverage goals that combine multiple variables, instead of relying on individual
coverage points. This provides better visibility into the overall behavior of the design,
and helps to identify corner cases or unexpected interactions.
Reduced verification effort: By combining coverage data for multiple variables or
conditions, cross-coverage reduces the number of individual coverage points that need
40
SYSTEM VERILOG INTERVIEW QUESTIONS
to be tested. This can save verification time and effort, especially for complex designs
with many variables or conditions.
Improved result analysis: Cross-coverage generates more detailed coverage reports
that show the correlation between different variables or conditions. This helps the user
to identify patterns or trends in the data, and to perform more targeted verification
activities.
SystemVerilog constraints are used to control the values that are randomized for variables
during simulation. Constraints provide a way to specify the valid range of values for a variable,
as well as any relationships or conditions between variables.
constraint myConstraint {
data inside {[0:10]};
}
$display format specifier can have %h or %H , and quite intuitively we assume that the latter
is used to display it in uppercase. However, that is not the case and we need a workaround.
str.hextoa(y);
$display(str.toupper);
Constrain a dynamic array such that it does not pick values from another array.
module tb;
bit [3:0] da [];
bit [3:0] myq [$];
initial begin
repeat (10) myq.push_back($random);
41
SYSTEM VERILOG INTERVIEW QUESTIONS
initial begin
byte loop = 5;
The repeat loop iterates a fixed number of times and the iteration count cannot be changed
once in the loop. The output will be:
hello
hello
hello
hello
hello
Overriding refers to the process of providing a new implementation for an inherited method in
a subclass. In other words, if a superclass defines a method, a subclass can override that method
by providing its own implementation. When the subclass object calls the overridden method,
the new implementation in the subclass is executed instead of the original implementation in
superclass. The signature (name, return type, and parameters) of the method remains the same.
The main purpose of method overriding is to implement a different behavior of the same
method in a subclass.
On the other hand, overloading refers to defining multiple methods within the same class that
have the same name but different parameters. This allows the same method name to be used
for different operations. When the method is called, the system automatically selects the
appropriate version of the method based on the parameters passed. The signature of the method
is different in each overload due to the differing number or types of arguments.
42
SYSTEM VERILOG INTERVIEW QUESTIONS
There are multiple types of verification approaches like simulation based verification, formal
verification, emulation or FPGA prototyping.
43
SYSTEM VERILOG INTERVIEW QUESTIONS
1. What is `timescale?
2. What are the basic testbench components?
3. What is circular dependency?
4. What are the advantages of a SystemVerilog program block?
5. What is scope randomization?
6. What is the input skew and output skew in the clocking block?
7. Explain the different stages a simulator goes through to run a simulation.
8. What is casting?
9. How to generate array without randomization?
10. Write randomization constraints for the following requirements on an array.
What is `timescale?
The `timescale directive is used to set the time units and precision for a design. It specifies the
time scale used in the simulation and the unit of time for delays and times associated with signal
assignments and other operations.
`timescale timeunit/precision
Stimulus generation: Stimulus generation involves creating test vectors or other input
signals that will be applied to the inputs of the design under test (DUT).
Interface: The interface provides the communication between the testbench and the
DUT. It includes input and output ports, which are connected to the corresponding
signals in the DUT.
Driver: The driver is responsible for converting stimulus into pin toggles appropriate
to the bus protocol used by the DUT.
Monitor: The monitor observes the output signals of the DUT and produces a stream
of data that the testbench can analyze.
Scoreboard: The scoreboard compares the output of the DUT with the expected output,
and generates an error message or other notification if there is a mismatch.
Coverage analysis: Coverage analysis measures how much of the design has been
exercised during simulation, and helps identify parts of the design that may not have
been tested thoroughly.
44
SYSTEM VERILOG INTERVIEW QUESTIONS
class A;
B b;
...
endclass
endclass
Statements inside a program block are executed in the reactive region which is executed the
last in a Verilog simulator event scheduler and hence can react on final state of design signals.
It acts as an entry point for test stimulus to be executed by the testbench. It can contain
functions, tasks and other supported constructs that enable user to create meaningful test
stimulus.
Scope randomization allows to define different randomization constraints for different parts or
scopes of the design hierarchy.
45
SYSTEM VERILOG INTERVIEW QUESTIONS
module tb;
byte data;
initial begin
randomize(data) with { data > 0 };
$display("data = 0x%0h", data);
end
endmodule
Note that std:: is required if you need to call from within a class method to distinguish it from
the class's built-in randomize method.
What is the input skew and output skew in the clocking block?
A clocking block is a feature in SystemVerilog used to manage clock signals in a design. Input
skew refers to when a signal defined as input to the clocking block should be sampled relative
to the given edge of the clock. Output skew refers to when a signal declared as an output to the
clocking block should be driven relative to the given edge of the clock.
1. Compilation Phase: This phase involves compiling the design and testbench files and
checks the syntax, semantics, and hierarchy of the design, including all modules and
interfaces.
2. Elaboration Phase: During this phase, the SystemVerilog compiler parses the design
files and creates an internal representation of the design in memory. It reads the
testbench code, generates object files, and links them together to create an executable
file. It also includes the loading of any libraries, linking with external modules, and
optimizing the executable file. Any issues found during elaboration must be resolved
before simulation can proceed.
46
SYSTEM VERILOG INTERVIEW QUESTIONS
3. Simulation Phase: This is the actual running of the simulation. The simulation takes
the compiled executable file and simulates the hardware design under test. The
simulation initializes the testbench and DUT, applies stimulus to the DUT, and checks
the expected output. The SystemVerilog simulation engine checks for timing, race
conditions, and other errors and generates a log file during the simulation.
What is casting?
Casting is a fundamental concept in programming and refers to the process of converting one
data type into another data type. In SystemVerilog, casting is mainly used for type conversion
between numeric and non-numeric data types.
real pi = 3.14;
int a = int'(pi) * 10; // Cast real into an integer number
This solution does not generate fully random numbers, however it does give unique values.
module tb;
byte data_q [10];
initial begin
// Store numbers 0 through 10
foreach (data_q [i])
data_q[i] = i;
An array of size 9 should contain any value from 1 to 9. Two values should be the same between
indices 0 and 7.
module tb;
47
SYSTEM VERILOG INTERVIEW QUESTIONS
initial begin
bit [2:0] idx_q [2];
unique { idx_q };
foreach (data_q[i]) {
if (i == idx_q[1]) {
data_q[i] == data_q[idx_q[0]];
} else {
};
endmodule
48
SYSTEM VERILOG INTERVIEW QUESTIONS
1. What is SVA?
2. When you will say that verification is completed?
3. What are system tasks?
4. In SystemVerilog which array type is preferred for memory declaration and why?
5. What is the advantage of seed in randomization?
6. Is it possible to write assertions in a class ?
7. What is a clocking block?
8. What is an abstract class?
9. How to disable a coverpoint ?
10. What is super keyword ?
What is SVA?
SVA or SystemVerilog Assertions provides a syntax for expressing assertions that describe the
expected behavior of a design, allowing for direct verification of its correctness.
Assertions expressed using SVA can be used to verify various types of design properties, such
as proper data flow, correct timing constraints, and correct synchronization between different
parts of the design. SVA can be used as a standalone language or in conjunction with other
formal verification techniques such as model checking and theorem proving. It is an important
tool for ensuring the correctness and reliability of digital designs in VLSI and other fields.
Verification is typically considered complete when all the specified verification goals and
requirements have been met and demonstrated through testing and analysis of the design. This
means that all of the verification tests have been run and that the design has passed all of the
necessary functional and performance requirements. Verification is a continuous process that
starts early in the design cycle and continues until the final stages of the design and
development process. Throughout this process, different verification techniques and
methodologies are used to ensure that the design is free from errors.
Verification completeness is typically determined using a set of predefined metrics and criteria
that are used to evaluate the overall quality and reliability of the design. Such metrics may
include functional coverage, code coverage, and timing analysis. Ultimately, the decision to
declare verification complete is based on the verification team's confidence in the design's
functionality and reliability to be used in the intended application and environment.
49
SYSTEM VERILOG INTERVIEW QUESTIONS
System tasks are pre-defined functions or built-in functions in SystemVerilog that are used to
execute certain tasks related to the simulation and verification of a design. Some common
system tasks in SystemVerilog include:
In SystemVerilog which array type is preferred for memory declaration and why?
The preferred array type for memory declaration is an associative array because it is more
efficient in storing data at random address locations. It does not require all addresses in memory
to be pre-allocated before usage unlike a dynamic array.
In SystemVerilog, seed is used as a starting point or initial value for the random number
generator. The advantage of using the seed in randomization is that it allows for a more
deterministic and reproducible behavior of the randomized simulation.
By setting a seed, a specific set of randomized values can be generated consistently, making it
easier to replicate specific test scenarios and debug issues that arise during simulation. It also
allows for better verification of the design as specific tests can be rerun with the same seed to
ensure that issues have been resolved and that the behavior of the design is as expected.
Yes, assertions using assert and assume are used to check the correctness of the design, and
they can be written in any of the SystemVerilog constructs including modules, interfaces,
programs or classes.
In SystemVerilog, assertions can be written using the assert and assume keywords. These
keywords can be used directly inside a SystemVerilog class, with the assertion check being
triggered when the appropriate method of the class is called.
50
SYSTEM VERILOG INTERVIEW QUESTIONS
Covergroups and coverpoint weight can be disabled by setting its weight to zero.
The super keyword in SystemVerilog or even any OOP language refers to the superclass of a
class. It is used to access methods and variables of the superclass from within a subclass.
51
SYSTEM VERILOG INTERVIEW QUESTIONS
52
SYSTEM VERILOG INTERVIEW QUESTIONS
53
SYSTEM VERILOG INTERVIEW QUESTIONS
1. What is the difference between an initial and final block of the systemverilog?
2. Explain the simulation phases of SystemVerilog verification?
3. What is the Difference between SystemVerilog packed and unpacked array?
4. What is “This ” keyword in the systemverilog?
5. What is alias in SystemVerilog?
6. randomized in the systemverilog test bench?
7. in SystemVerilog which array type is preferred for memory declaration and why?
8. How to avoid race round condition between DUT and test bench in SystemVerilog
verification?
9. What are the advantages of the systemverilog program block?
10. What is the difference between logic and bit in SystemVerilog?
11. What is the difference between datatype logic and wire?
12. What is a virtual interface?
13. What is an abstract class?
14. What is the difference between $random and $urandom?
15. What is the expect statements in assertions?
16. What is DPI?
17. What is the difference between == and === ?
18. What are the system tasks?
19. What is SystemVerilog assertion binding and advantages of it?
20. What are parameterized classes?
21. How to generate array without randomization?
22. What is the difference between always_comb() and always@(*)?
23. What is the difference between overriding and overloading?
24. Explain the difference between deep copy and shallow copy?
25. What is interface and advantages over the normal way?
26. What is modport and explain the usage of it?
27. What is a clocking block?
28. What is the difference between the clocking block and modport?
29. System Verilog Interview Questions, Below are the most frequently asked questions.
30. What are the different types of verification approaches?
31. What are the basic testbench components?
32. What are the different layers of layered architecture?
33. What is the difference between a $rose and @ (posedge)?
54
SYSTEM VERILOG INTERVIEW QUESTIONS
55
S Y S T E M V E R I LO G I N T E R V I E W Q U E S T I O N S M AV E N - S I L I C O N . C O M
05 Why do we use create method in uvm rather than using new constructor?
06 Why are we using mailboxes to establish the communication between the TB components
instead of queues?
C O P Y R I G H T 2 0 2 3 M AV E N S I L I C O N , A L L R I G H T S R E S E R V E D