SV Interview Questions
SV Interview Questions
SystemVerilog is a superset of Verilog that adds powerful design and 3. – indexed by non‑integer or sparse indices
verification features: (e.g. int, string), useful for look‑up tables.
● – class, inheritance, 4. –
polymorphism, virtual methods, dynamic objects.
● Queues
– covergroup, coverpoint, cross to measure
stimulus quality. ● A is a variable‑size, ordered collection that grows and
● – dynamic arrays, associative arrays, queues, shrinks dynamically.
packed/unpacked arrays.
● Declared using $ as index: data_type queue_name[$];
● – group related signals and protocol logic
together, simplify connections.
● Supports push/pop operations at front/back:
● – inter‑process communication and
synchronization between processes.
int q[$];
● – bit‑level modeling. q.push_back(10);
● – connect with C/C++ or q.push_front(5);
int x = q.pop_front(); // x = 5
other languages. int y = q.pop_back(); // y = 10
These features make SV suitable for building complex, reusable, and Queues are very useful for modeling FIFOs and transaction lists.
constrained‑random verification environments.
4. What is inheritance?
2. What is logic data type?
● is an OOP concept where a new class (child/derived
● logic is a data type in SystemVerilog that can take class) is built from an existing class (base/parent class).
values 0, 1, X, Z. ● The child class and the properties and methods
of the base class.
● It is used to replace reg and wire in RTL and testbench code.
Example:
● Unlike reg, logic can be driven by and
(but not by multiple drivers in the same class base_packet;
scope). rand bit [7:0] addr;
rand bit [7:0] data;
function void display();
Example: $display("BASE: addr=%0h data=%0h", addr, data);
endfunction
logic clk; endclass
logic [7:0] data;
class extended_packet extends base_packet;
assign clk = tb_clk; rand bit parity;
function void display();
always_ff @(posedge clk) begin [Link]();
data <= data + 1; $display("EXT: parity=%0b", parity);
end endfunction
endclass
Arrays
1
5. What are constraints? end
end
endmodule
● define rules/relationships that a random variable
must satisfy during randomization.
This prints five different random alphabetic strings of length 5.
● Declared inside a class using the constraint keyword.
property A_goes_low_and_stays_low_4;
6. What are the types of assertions? @(posedge clk) $fell(A) |-> (!A[*4]);
endproperty
SystemVerilog supports two main types of assertions:
assert property (A_goes_low_and_stays_low_4);
1.
Mention whichever matches the interviewer’s exact requirement.
o Checked inside procedural code.
o Typically used for single‑cycle checks or sanity
checks.
assert (a <= b) else $error("a is greater than b"); 9. Key differences between SystemVerilog and
Verilog.
2.
● : SystemVerilog = Verilog + advanced design +
o Described using property / sequence and evaluated
verification features.
over on a clock.
o Used to verify temporal relationships and protocols. ● : SystemVerilog adds logic, bit, byte, enum, struct,
union, string, new array types, etc.
property req_gnt;
@(posedge clk) req |-> ##1 gnt; ● : Verilog has no classes; SystemVerilog supports
endproperty classes, inheritance, polymorphism.
assert property (req_gnt);
● : Only in SystemVerilog.
(You may also mention cover property and assume property in formal ● : SVA and functional coverage are
verification context.) SystemVerilog features, not in Verilog.
● : Only in SystemVerilog.
● : SystemVerilog is the base for
UVM/OVM/VMM methodologies; Verilog testbenches are
7. Generate random string alphabet five times. typically directed and procedural.
Example code to generate a 5‑character random alphabetic string, 5 times: So, SystemVerilog is mainly used for and modern
class rand_string;
RTL coding, while Verilog is the older subset.
rand string s;
// Length of string = 5
constraint c_len { [Link]() == 5; }
10. What are the various data types available in
// Each character is an alphabet (a–z or A–Z) SystemVerilog? Give examples.
constraint c_alpha {
1. Net and variable types
foreach (s[i]) s[i] inside { ["a":"z"], ["A":"Z"] };
}
endclass
● logic (4‑state), bit (2‑state), wire, tri, etc.
module tb;
rand_string rs = new();
int i; logic [7:0] data;
bit [3:0] status;
initial begin
2. Integer types
repeat (5) begin
if (![Link]())
$error("Randomization failed");
else ● byte (8‑bit), shortint (16‑bit), int (32‑bit), longint (64‑bit),
$display("Random string %0d = %s", i, rs.s);
signed/unsigned.
i++;
2
int unsigned count; Mailbox
longint signed big_num;
● A is a built‑in class used for between
parallel processes.
3. Real‑number types
● It acts like a queue/FIFO of objects.
● real, shortreal, realtime. ● Key methods: put(), get(), peek(), try_get(), etc.
mailbox mbx = new();
4. User‑defined types
// Producer
● enum, struct, union, typedef. ```systemverilog typedef enum [Link](pkt);
{IDLE, READ, WRITE} state_t; state_t state;
// Consumer
[Link](pkt_rcv);
typedef struct packed { bit [7:0] addr; bit [7:0] data; } pkt_t;
● string, event, chandle, virtual interface. ● Key methods: get(n), put(n), try_get(n).
semaphore sem = new(1); // 1 token -> mutex
12. What are mailboxes and semaphores in 14. What is the Configuration Database (Config
SystemVerilog? How do they differ? DB) in SystemVerilog/UVM?
3
●
uvm_analysis_imp#(my_txn, my_scoreboard) imp;
In UVM, the (uvm_config_db) is a global,
hierarchical key‑value store. function new(string name, uvm_component parent);
[Link](name, parent);
● It is used to from imp = new("imp", this);
higher‑level components (like test/env) to lower‑level endfunction
components (like agents, drivers, monitors) without tight
function void write(my_txn t);
coupling.
// compare / check transaction
endfunction
Example: endclass
In UVM, are used for communication between components at - Measures whether all
the instead of individual signals. have been exercised. - Defined by the verification engineer using
covergroup, coverpoint, and cross. - Answers: “Did I generate all intended
Main ideas combinations/transactions?” - Independent of implementation structure.
Common UVM TLM port types 17. What are the differences between struct and
1. union in SystemVerilog?
In pure SystemVerilog RTL/testbench code, we generally prefer logic The constraint logic supports ranges, arithmetic relations, conditional
because it can be used in both continuous and procedural assignments expressions, inside, dist, unique, etc., letting you describe complex input
(single driver per signal). spaces at a high level.
19. What are the constraints in SystemVerilog? 21. How do you write a constraint to generate a
Can you explain the different types of multiple of 5?
constraints? Example: generate a random integer x that is a multiple of 5 in the range
0–95.
A specifies rules that randomized variables must satisfy. They
are declared in a class with the constraint keyword and solved class mult_of_5;
automatically by the SystemVerilog constraint solver. rand int x;
constraint c_multiple_5 {
Types / styles of constraints: x inside {[0:95]};
x % 5 == 0; // x is a multiple of 5
● – limit a variable to a value range. }
endclass
constraint c_range { addr inside {[16'h1000:16'h1FFF]}; }
Another way using an intermediate variable:
● – specify relationships
class mult_of_5_alt;
between variables. rand int k;
int x;
constraint c_rel { len > 0; len <= 256; }
constraint c_k_range { k inside {[0:19]}; }
constraint c_expr { end_addr == start_addr + len; }
function void post_randomize();
● – use inside with sets. x = 5 * k;
endfunction
endclass
constraint c_set { opcode inside {READ, WRITE, IDLE}; }
constraint c_count_3_ones {
[Link]() with (int'(item)) == 3; // exactly three 1s
20. What is a constraint logic, and how does it }
work? endclass
5
In a real testbench, time‑based behavior is more often checked with o Bins in a cross of two or more coverpoints,
, but this shows the idea using constraints. representing combinations.
●
o Values/ranges to be ignored in coverage calculations.
23. Can you write a constraint to generate ignore_bins reserved = {4'hF};
25. What are the different types of bins in 27. What are weighted and non weighted codes?
SystemVerilog? Can you provide examples?
In functional coverage (covergroup), define value ranges or sets to be
This is a question rather than pure SystemVerilog.
counted. Types include:
- Each bit position has a fixed weight (value contribution).
●
- The numeric value is the sum of weights of bits that are 1. - Example:
o Created automatically by the tool when no explicit bins code – weights are 8,4,2,1 for a 4‑bit number. - Example:
are defined. – 4‑bit code with weights 8,4,2,1 representing decimal digits 0–9.
●
o User‑defined bins for specific values or ranges. - Bit positions do have simple positional weights;
the code word value is not a direct sum of bit weights. - Examples:
bins small = {[0:3]}; , , , .
bins big = {[4:15]};
●
6
typedef - Creates an alias (new name) for an existing type. - Can be used Static casting
with any data type: int, struct, union, enum, etc.
● Syntax: type'(expression) or type'(handle).
typedef int count_t;
count_t cnt; // same as 'int cnt;' ● Checked at compile time for compatibility.
bit [7:0] b;
typedef struct { int i;
int id;
byte data; i = int'(b); // cast 8 bit vector to int
} pkt_t;
pkt_t p1; state_t s;
s = state_t'(2); // cast integer 2 to enum state_t
enum - Defines an with a set of named constant values. -
Optionally, a base type and explicit encodings can be given. Dynamic casting
enum logic [1:0] {IDLE=2'b00, READ=2'b01, WRITE=2'b10} state_t;
state_t state;
● Uses $cast(dest, src); returns 1 on success, 0 on failure.
● Common for base‑to‑derived class casting.
Relationship: - enum itself defines a type; you can still alias it using typedef base_pkt b;
if desired. - typedef is generic; enum is specifically for named constant sets. read_pkt r;
b = new read_pkt();
if (!$cast(r, b))
$error("Cast failed");
29. What is polymorphism in SystemVerilog, and else
[Link]();
when do we use it?
Dynamic casting is mainly used with polymorphism when we need to
is an OOP feature where a can point to recover the specific derived type.
objects of different derived classes, and the correct overridden method is
chosen at run time (dynamic binding).
Requirements: - Inheritance (extends). - Methods declared virtual in the 31. How do you connect a monitor to a DUT
base class and overridden in derived classes.
(Design Under Test)?
Example:
In a class‑based verification environment (e.g., UVM‑style):
class base_pkt;
virtual function void display(); ● to group DUT signals.
$display("Base packet");
endfunction ● Connect the interface to the DUT in the top module.
endclass ● Pass a handle to the monitor.
class read_pkt extends base_pkt;
function void display();
Example:
$display("Read packet");
endfunction // 1) Interface\ ninterface bus_if (input logic clk);
endclass logic req, gnt;
logic [7:0] addr, data;
endinterface
class write_pkt extends base_pkt;
function void display();
$display("Write packet"); // 2) DUT and interface instantiation
endfunction module top;
endclass logic clk;
bus_if bus (clk);
base_pkt pkt;
dut u_dut (.clk(clk), .req([Link]), .gnt([Link]),
.addr([Link]), .data([Link]));
initial begin
pkt = new read_pkt();
[Link](); // prints "Read packet" // Virtual interface passed to monitor (UVM style or manual)
initial begin
monitor m = new(bus); // constructor or config_db
pkt = new write_pkt();
end
[Link](); // prints "Write packet"
endmodule
end
// 3) Monitor class (simplified)
We use polymorphism to write (e.g., drivers, scoreboards) class monitor;
that works with different specific packet/sequence types without changing virtual bus_if vif;
function new(virtual bus_if vif);
the calling code.
[Link] = vif;
endfunction
task run();
30. When do we use casting in SystemVerilog? forever begin
@(posedge [Link]);
Can you provide examples? if ([Link] && [Link])
$display("Monitor: addr=%0h data=%0h", [Link], [Link]);
end
converts one data type to another. We use it when: - Assigning endtask
between types of different sizes or signedness. - Converting between endclass
base‑class and derived‑class handles (OOP casting). - Interpreting packed
bits as different types. The monitor is : it only observes signals, converts them to
transactions, and sends them to the scoreboard/coverage.
7
o randc variables cycle through all values in their range
before repeating.
32. What is a cross functional model error in randc bit [1:0] sel; // 0,1,2,3 in random order, then
SystemVerilog? repeat
The phrase usually refers to an error detected when comparing behavior ● std::randomize()
across . In a verification context:
o Randomize variables that are not class members or
apply temporary constraints.
● We often have a and the
DUT. int x, y;
● A occurs when the combination of if (!std::randomize(x, y) with { x < y; x inside {[0:10]};
})
features or operations in the DUT does not match the expected $error("Randomization failed");
behavior of the reference model.
● This is often caught by a , which compares ●
transactions from different sources (e.g., input vs. output, o Use dist constraints to control probabilities.
multiple interfaces, or multiple models) and flags mismatches.
Together, these mechanisms let us generate complex stimulus for
Practically, you might answer in an interview: > “A cross‑functional model
coverage‑driven verification.
error is a mismatch between the DUT outputs and the reference/functional
model for a particular combination of features or coverage cross. It usually
indicates either a design bug or an error in the model or stimulus.”
35. How do you write code to generate numbers
greater than 5?
33. What are packed and unpacked arrays in
SystemVerilog? Can you give examples? Example using class‑based randomization:
class greater_than_5;
- Represent a . - Can be used in rand int x;
arithmetic and bitwise operations like a single vector. - Declared with the
range of the variable name. constraint c_gt5 { x > 5; }
endclass
logic [7:0] byte; // 8 bit packed array
logic [3:0][7:0] bus_id; // 4 elements, each 8 bits (total 32 bits module tb;
packed) initial begin
greater_than_5 obj = new();
repeat (5) begin
- Represent a collection of elements, each of which can if ([Link]())
be simple or complex types. - Declared with the range of the $display("x = %0d", obj.x); // always > 5
variable name. else
$error("Randomization failed");
logic [7:0] mem [0:255]; // 256 element unpacked array, each is end
8 bit packed end
int q [$]; // queue (unpacked) of ints endmodule
- Packed arrays are stored as a single vector → useful for Or using std::randomize() without a class:
synthesis and bit‑level modeling. - Unpacked arrays are higher‑level int x;
collections → useful for memories, FIFOs, transaction arrays. - Types can
be combined (packed dimensions first, then unpacked): logic [7:0] mem initial begin
[0:15];. repeat (5) begin
assert (std::randomize(x) with { x > 5; });
$display("x = %0d", x);
end
end
34. What are the different types of
randomization in SystemVerilog? Both approaches ensure that all generated numbers are strictly greater
than 5.
●
o Use rand / randc class properties and 36. Can you provide a specific example of
[Link](). constraints like 010203040506?
class pkt;
rand bit [7:0] addr; Interpretation: generate a in such as 01
endclass 02 03 04 05 06.
o Use constraint blocks to control random values (most constraint c_size { [Link]() == 6; }
common style).
// arr = {1,2,3,4,5,6}
● randc constraint c_increasing {
foreach (arr[i]) {
8
●
arr[i] == i + 1; // 0->1, 1->2, ... 5->6
} [Link]() – delete all entries.
}
endclass Example:
Together these form a that ensures correct ordering For synthesis‑friendly code you typically place this inside a package or
between blocking/non‑blocking assignments, signal sampling, and module.
assertion checking.
● (Synopsys):
property clk_valid_levels;
@(posedge clk) !$isunknown(clk);
endproperty 48. What are the regions in SystemVerilog?
assert property (clk_valid_levels); Simulation is divided into ordered to control scheduling. A
simplified list:
Actual implementation depends on the clock specification (period, duty,
gating, etc.). ● – sampling for assertions.
● fork..join_none
● When A = 0, Y = B.
o Starts all blocks and ; execution ● When A = 1, Y = ~B.
continues immediately after the fork (detached
threads). SystemVerilog RTL:
fork
module xor_using_mux (
task1();
input logic A,
task2();
input logic B,
join_none
output logic Y
// both tasks run in background
);
11
● A simple divide‑by‑2 uses a T‑flip‑flop or D‑flip‑flop that toggles ● Derived classes must provide implementations for pure virtual
on each clock edge: methods to be concrete.
module clk_div2 (
input logic clk_in, Syntax:
input logic rst_n,
output logic clk_out virtual class base_driver;
); virtual task drive(); // may have default body
pure virtual function void configure(); // must be implemented
always_ff @(posedge clk_in or negedge rst_n) begin endclass
if (!rst_n)
clk_out <= 1'b0; class axi_driver extends base_driver;
else function void configure();
clk_out <= ~clk_out; // toggle -> divide by 2 // implementation
end endfunction
endmodule
task drive();
For divide‑by‑N, use an N‑state counter and toggle/emit a pulse at certain // override if needed
counts. endtask
endclass
// Usage
base_driver drv; // base handle
51. What is the difference between logic and reg in axi_driver axi_drv_h = new();
drv = axi_drv_h; // polymorphism
SystemVerilog? What are the default values of
wire and reg? Virtual classes are heavily used in UVM for creating generic, reusable base
components and then extending them for specific protocols or
reg - 4‑state variable (0,1,X,Z). - Can be assigned only in configurations.
procedural blocks (always, initial). - Cannot have multiple drivers.
Example:
logic a; // preferred in SV
reg b; // legacy Verilog style
Virtual classes
● A is an that
directly.
● It may contain that have no implementation
in the base class.
12
phase.drop_objection(this);
13
initial begin
8. Explain shallow copy and deep copy with
driver d = new(bus); // pass interface to class via virtual example.
handle
fork [Link](); join_none; ● – copies only the of an object; both
end variables refer to the object in memory.
endmodule
● – creates a and copies all fields so that
Virtual interfaces therefore static design world and class‑based the two objects are independent.
testbench world.
Shallow copy example
class pkt;
int addr;
6. What are semaphores? endclass
// Consumer
initial begin 10. Write tb top code.
packet rx;
[Link](rx); // wait until a packet is available
[Link]();
A typical (simplified) top‑level testbench module for a UVM‑style
end environment:
`timescale 1ns/1ps
Mailboxes are widely used (and also internally in UVM TLM FIFOs) for
synchronizing drivers, monitors, and scoreboards. import uvm_pkg::*;
`include "uvm_macros.svh"
14
end
module tb_top; endtask
endclass
// Clock & reset
logic clk; module tb_mailbox;
logic rst_n; mailbox mbx;
producer prod;
// Interface instance consumer cons;
bus_if bus (.*); // assume interface declared elsewhere with clk,
rst_n initial begin
mbx = new();
// DUT instance (example) prod = new(mbx);
dut u_dut ( cons = new(mbx);
.clk (clk),
.rst_n(rst_n), fork
.req ([Link]), [Link]();
.gnt ([Link]), [Link]();
.addr ([Link]), join
.data ([Link]) end
); endmodule
// Clock generation Here a single mailbox is shared; producer put()s packets, consumer
initial begin
clk = 0; get()s them.
forever #5 clk = ~clk;
end
// Reset generation
initial begin
12. Explain virtual class.
rst_n = 0; A is an that
#20 rst_n = 1;
end directly.
These constraints ensure diagonal elements are identical while logic [7:0] mem [0:15]; // packed [7:0], unpacked [0:15]
off‑diagonal elements remain unconstrained (random).
16
int aa[string]; obj = null; // remove reference → eligible for garbage collection
aa["ID_1"] = 10;
To deallocate, set handles to null or reassign them to other objects.
Dynamic → good for contiguous indices; associative → good for sparse /
look‑up table style data.
- Indexed by arbitrary key; no inherent order. - Use Still cannot contain time‑consuming statements; that rule remains.
methods first/next/last/prev to iterate.
int aa[string];
aa["key"] = 3;
26. What is coverage?
Queue is for FIFO‑like ordered lists; associative array is for key‑value measures how thoroughly the design has been exercised by the
maps. tests.
These are used heavily in UVM to create reusable verification components. class asc_rand;
rand int arr[];
●
}
constraint blocks specify legal value space. }
endclass
● [Link]() and std::randomize() to invoke the solver.
Randomization will generate already‑sorted numbers → no need for sort().
● randc = cyclic randomization (covers range before repeating).
● dist for weighted distributions, inside for sets, unique for 28. What is semaphore?
uniqueness.
(Short answer – see also earlier set.)
Purpose: generate high‑quality, constrained‑random stimulus for
coverage‑driven verification. Semaphore is a built‑in class for :
module dut (bus_if bus); Monitor then uses virtual bus_if to read error.
// use [Link], [Link], ...
endmodule If interviewer forbids RTL change: use bind or hierarchical reference:
[Link] in TB.
class driver;
virtual bus_if vif;
function new(virtual bus_if vif); [Link] = vif; endfunction
task run();
forever begin
@(posedge [Link]);
34. Write chess constraints.
[Link] <= 1;
[Link] <= 8'hAA; Interpretation: 8×8 board, one queen per row/column and no two queens
end on same diagonal (like N‑Queens) – a common constraint example.
endtask
endclass class chess_queens;
rand int q_col[8]; // q_col[row] = column of queen in that row
module top; (0..7)
logic clk; bus_if bus(clk);
dut d0(bus); // each column 0..7
initial begin constraint c_range {
driver drv = new(bus); // pass interface to class foreach (q_col[i]) q_col[i] inside {[0:7]};
fork [Link](); join_none; }
end
endmodule // no two queens in same column
constraint c_unique {
unique { q_col };
}
32. Randomize 4×4 matrix where two diagonals // no two queens on same diagonal
stored with 1 and probability of 1 is 90% (ignore constraint c_diag {
foreach (q_col[i]) foreach (q_col[j])
others). if (i < j)
(q_col[i] - q_col[j]) != (i - j) &&
(q_col[i] - q_col[j]) != (j - i);
We only care about diagonal elements: (i==j) or (i+j==3); random 1 with
}
90% probability. endclass
18
class pkt; int id; endclass
pkt p1 = new();
35. Constraint to fill array size 1024 (32 bit) with pkt p2;
even number in each nibble. p2 = p1; // shallow → both handles use same allocated object
Each 4‑bit nibble must be even → LSB of each nibble = 0. pkt p3 = new();
[Link] = [Link]; // deep (manual) → separate object, separate memory
class even_nibbles;
rand bit [31:0] arr[1024];
UVM clone() allocates new memory for deep copied object.
constraint c_even_nibs {
foreach (arr[i]) begin
foreach (arr[i][nibble]) with (nibble) ; // explanation below
}
end
38. SV code to sum 2 numbers with help from a
endclass function.
function int add2 (int a, int b);
Simpler: force all LSBs of each nibble to 0 using mask: return a + b;
endfunction
class even_nibbles2;
rand bit [31:0] arr[1024]; module tb;
int x = 10, y = 20, z;
constraint c_even_nibs { initial begin
foreach (arr[i]) z = add2(x, y);
(arr[i] & 32'h1111_1111) == 32'h0000_0000; // all nibble LSBs = $display("z = %0d", z);
0 end
} endmodule
endclass
Any 32‑bit value whose bit0,4,8,…,28 are 0 has even number in each
nibble.
39. What is event scheduling in SV? INC and
WRAP memories?
36. Constraint to count number of 0s in a Event scheduling = how simulator orders events in time using
(preponed, active, inactive, NBA, observed, postponed). See Q30.
number; SV code for two signals with 500 ns
relation. types usually refer to address counters in memories: -
– after each access, address increments until max and
Count 0s in 32‑bit number then stops. - – address increments and wraps around to 0 after
class count_zeros; max. Used in circular buffers and some SRAM/DDR burst modes.
rand bit [31:0] val;
int zeros;
Signal sig1 goes high; after 500 ns, sig2 must go low SystemVerilog adds: - 2‑state: bit, byte, shortint, int, longint. - 4‑state:
logic, integer, time. - User‑defined: enum, struct, union, typedef. - Special:
initial begin
sig1 = 0; sig2 = 1; string, event, chandle, class, mailbox, semaphore, arrays (dynamic,
@(posedge start_event); associative, queue).
sig1 <= 1;
#500ns sig2 <= 0;
end
19
Helps find corner‑case bugs not thought of initially. Same idea as Q27 but more generic:
Works together with functional coverage for
constraint c_asc {
. foreach (arr[i]) if (i>0) arr[i] >= arr[i-1];
Enables reusability: same environment can run many tests with }
different seeds/constraints.
No sort() or reverse() used.
45. Declare a 16 bit associative array. // b should be high between 1 and 3 cycles after c
property p_b_1_to_3;
bit [15:0] aa[int]; // key: int, value: 16 bit @(posedge clk) c |-> ##[1:3] b;
bit [15:0] aa_str[string]; // key: string endproperty
assert property (p_b_1_to_3);
●
class arr16;
rand bit [15:0] aa[int]; $random is a that returns a
pseudo‑random 32‑bit number.
constraint c_size { [Link]() == 8; } // example
constraint c_even_odd {
Key differences: - rand works with constraint solver; $random does not. -
foreach (aa[i]) { rand gives repeatability via seeds plus randomize(); $random sequencing is
if (i % 2 == 0) simpler and often less controllable. - randc provides cyclic behavior;
aa[i][0] == 1'b1; // even index → odd value (LSB=1)
$random cannot.
else
aa[i][0] == 1'b0; // odd index → even value (LSB=0)
}
}
endclass
52. Assertion to find a glitch + circuit.
signal y should follow x without glitches when passing through
combinational logic.
47. Constraint to generate ascending order
without array methods. Glitch definition: y toggles more than once within one clock period.
20
Assertion (no double toggle between clocks): 57. Snippets for deep copy and shallow copy.
property no_glitch; class pkt;
@(posedge clk) int id;
!$rose(y) throughout (##[1:$] !$fell(y)) or function pkt copy(); // deep copy
!$fell(y) throughout (##[1:$] !$rose(y)); pkt p = new();
endproperty [Link] = [Link];
return p;
// Simpler check: no change between two consecutive clocks endfunction
property stable_between_clks; endclass
@(posedge clk) $stable(y);
endproperty pkt p1 = new();
assert property (stable_between_clks); pkt p2 = p1; // shallow copy
pkt p3 = [Link](); // deep copy
(Exact form may vary; interviewer mainly wants idea of using $stable,
$rose, $fell.)
●
`uvm_component_utils(base_driver)
bit – 2‑state (0/1) vector type, synthesizable. endclass
● reg – 4‑state (0/1/X/Z) variable from Verilog; replaced by logic in class my_driver extends base_driver;
SV. `uvm_component_utils(my_driver)
endclass
● int – 32‑bit, 2‑state signed in SV.
// In test build_phase
● integer – at least 32‑bit, 4‑state signed
function void build_phase(uvm_phase phase);
super.build_phase(phase);
(implementation‑dependent size). factory.set_type_override_by_type(base_driver::get_type(),
my_driver::get_type());
Use bit/int for 2‑state TB and synthesis; reg/integer are older 4‑state endfunction
types.
constraint c_even_odd {
foreach (data[i]) {
if (i % 2 == 0)
60. Constraint for int a not generating values
data[i] % 2 == 1; // even index → odd value between 100 and 200.
else
data[i] % 2 == 0; // odd index → even value
(Already answered as Q1 in previous part.)
}
}
constraint c_a_not_100_200 { a < 100 || a > 200; }
56. Constraint for two arrays being equal. 61. Constraint for pattern 0,2,0,4,0,6,…
class two_arrays;
rand int a[10];
(See earlier.)
rand int b[10];
constraint c_pattern {
constraint c_equal {
foreach (arr[i]) {
foreach (a[i]) b[i] == a[i];
if (i % 2 == 0)
}
arr[i] == 0;
endclass
else
arr[i] == (i+1); // 1→2,3→4,...
21
}
}
property p_A_100_after_rise;
@(posedge clk) $rose(A) |-> A[*100];
endproperty
assert property (p_A_100_after_rise);
Example:
@(posedge clk) req |-> ##1 gnt; // gnt 1 cycle after req, but
sequence overlaps
@(posedge clk) req |=> gnt; // gnt in next cycle directly
22
endclass
23
h = new B(); [Link](); // prints B (B::run) endfunction
end endclass
This is fundamental in UVM: components are referred to via base types class child extends parent;
function void display();
(like uvm_component) but their behavior comes from the specific derived $display("child"); // overrides parent implementation
type. endfunction
endclass
●
[Link] = 10;
are constraints written directly at the
randomize() call site using the with clause, instead of inside the pkt p2 = p1; // shallow copy – p1 and p2 point to same object
[Link] = 20;
class. $display("[Link]=%0d", [Link]); // prints 20
● They are typically used for or for
tightening a constraint temporarily. ● : creates a and copies over the data fields,
int x, y; so future changes are independent.
class pkt;
// randomize both x and y such that x<y and x is between 0 and 10 int id;
std::randomize(x, y) with { x inside {[0:10]}; x < y; }; function pkt copy();
pkt tmp = new();
You can also combine inline constraints with class randomization: [Link] = [Link];
return tmp;
pkt p = new(); endfunction
[Link]() with { addr == 8'hAA; }; // overrides normal addr range endclass
● The parent method should be declared virtual if you want 11. What is super keyword?
polymorphic behavior.
class parent; ● super is used within a derived class to access
virtual function void display();
$display("parent"); :
24
o Call the base class constructor: [Link](...). 15. What is a virtual interface?
o Call overridden methods: [Link](). ● A is essentially a to an
o Access base-class fields if not hidden. interface instance.
class parent;
function new(string name); ● Classes cannot directly connect to module ports, so they use a
$display("parent new: %s", name); virtual interface to read and drive DUT signals.
endfunction interface bus_if (input logic clk);
endclass logic req, gnt;
endinterface
class child extends parent;
function new(string name); class driver;
[Link](name); // call parent's constructor virtual bus_if vif; // virtual interface handle
$display("child new: %s", name);
endfunction function new(virtual bus_if vif);
endclass [Link] = vif;
endfunction
super helps you reuse parent behavior while still customizing the child.
task run();
forever begin
@(posedge [Link]);
[Link] <= 1'b1;
12. What is functional coverage? end
endtask
● is a user‑defined metric that checks endclass
whether the described in the verification plan
have been exercised. Virtual interfaces are usually passed via constructors or UVM config_db
from tb_top.
● It is implemented using covergroup, coverpoint, cross, and
optionally bins with ranges or named bins.
covergroup cg @(posedge clk);
// cover all 8 opcodes
coverpoint opcode { bins all[] = {[0:7]}; }
16. What is interface?
// cover packet length ranges ● An interface bundles related signals, clocking blocks, tasks,
coverpoint length { functions, and assertions into a single reusable unit.
bins small = {[0:63]};
bins big = {[64:255]}; ● It simplifies DUT port connections and keeps the protocol
} description in one place.
interface bus_if(input logic clk);
// cross coverage of opcode vs length logic req, gnt;
cross opcode, length; logic [7:0] addr, data;
endgroup
// Optional task to drive a transaction
Functional coverage tells you how much of the intended behavior has task drive(input logic [7:0] a, d);
actually been tested, not just which lines of RTL executed. addr <= a;
data <= d;
req <= 1;
@(posedge clk);
req <= 0;
13. What is setup and hold time? endtask
endinterface
For a flip‑flop:
The same interface instance is connected to both the DUT and the
testbench via virtual interfaces.
● : minimum time that data input D must be
stable the active clock edge (e.g., rising edge).
● : minimum time that data must remain stable
the clock edge. 17. What are different types of assertions?
●
If these conditions are violated, the flip‑flop can go into ,
o Checked at the moment they are executed in
leading to unpredictable output. In RTL, we normally assume correct
procedural code.
setup/hold, but in back‑annotated timing simulations and STA these
constraints are critical. o Useful for single‑cycle conditions.
assert (a <= b)
else $error("a is greater than b");
25
You can also talk about and properties used mainly in formal
● Constraints are solved by the internal when you
verification.
call randomize().
class packet;
rand bit [7:0] addr;
rand bit [7:0] len;
18. How is read and write operation executed at
same time in dual port RAM? // address range 0x10–0x1F and length between 1 and 32
constraint c_addr { addr inside {[8'h10:8'h1F]}; }
constraint c_len { len inside {[1:32]}; }
● A has two independent ports (Port A and endclass
Port B), each with its own address, data, and control signals.
● In a given clock cycle: Constraints enable stimulus
o Port A can perform a read while Port B performs a generation.
write, or vice‑versa.
o Both ports can even perform writes (to different
addresses) simultaneously.
23. What is casting? What is static casting?
● If both ports access the , the
behavior depends on memory configuration (write‑first, read‑first, What are the components in verification?
or no‑change). The verification environment must account for
this according to spec. Casting
● Casting is converting a value or handle from one type to another.
SystemVerilog keeps backward compatibility while dramatically improving task delay_and_print(int v);
verification productivity. #10ns;
$display("v=%0d", v);
endtask
26
(Concept already explained in Q15.) 29. Explain polymorphism with code.
class base_seq;
We use a virtual interface to: - class‑based testbench and DUT
virtual task body();
signals. - Keep classes independent of a specific interface instance, $display("base body");
enabling reuse across different top‑level modules. - Pass connections endtask
through uvm_config_db or constructors without hard‑coding hierarchical endclass
26. What are the different data types in SV? class write_seq extends base_seq;
task body(); $display("write seq"); endtask
endclass
Some important categories:
base_seq seq;
●
initial begin
: bit, byte, shortint, int, longint. seq = new read_seq(); [Link](); // dynamic call ->
read_seq::body
● : logic, reg, integer, time. seq = new write_seq(); [Link](); // dynamic call ->
write_seq::body
● : typedef, enum, struct, union. end
● : string, event, chandle, class types, mailbox, The same base handle seq can refer to different sequence types; the
semaphore. correct body() is picked at runtime.
● : fixed‑size, dynamic, associative, queues; each can be
packed/unpacked.
These powerful data types make modeling complex protocols easier 30. Explain the difference between shallow copy
compared to classic Verilog. and deep copy with code and diagram.
(Concept already in Q10.)
28. Explain inheritance with code. 31. What is the difference between functional
class base_packet;
rand bit [7:0] addr;
and code coverage?
function void display(); ● answers: “How much of the RTL code structure
$display("[BASE] addr=%0h", addr);
endfunction did we execute?” (statements, branches, conditions, FSM states,
endclass toggles).
● answers: “How much of the intended
class read_packet extends base_packet;
rand bit [7:0] data; functionality or scenarios from the spec did we exercise?”
function void display();
[Link](); It’s possible to have 100% code coverage but poor functional coverage if
$display("[READ] data=%0h", data); you did not plan the right scenarios, and vice versa if some dead code
endfunction
endclass remains unexecuted.
Both read_packet and write_packet reuse addr and display() from ● real variables default to 0.0.
base_packet but customize the print message.
In synthesizable RTL you typically reset registers to a known value using
an explicit reset signal.
27
33. What is the difference between structure and 37. Difference between conditional and branch
class? bins?
struct) - Collection of fields grouped together. - No inherent ● : Tracks whether each possible
methods, although you can write functions that take structs as arguments. - branch of a decision (e.g., if, else if, else, case item) has been
Typically allocated statically or as part of another variable (no new taken.
required). ● : Looks inside a compound
decision, tracking each boolean sub‑expression.
typedef struct packed {
bit [7:0] addr;
bit [7:0] data; Example:
} pkt_s;
if (a && b) begin ... end
- Reference type; instantiated dynamically using new. - Can contain
, , and . - Supports and ● Branch: expression (a && b) true vs false.
; suitable for verification objects.
● Condition: four combinations of a and b (00, 01, 10, 11).
class pkt_c;
rand bit [7:0] addr, data;
function void print();
$display("addr=%0h data=%0h", addr, data);
endfunction
38. What is the use of clocking block?
endclass ● Clocking blocks give the testbench a
and specify when signals should be sampled or
driven relative to that clock.
● They help avoid race conditions between DUT and TB.
34. How to disable constraints? clocking cb @(posedge clk);
default input #1step output #1ns; // input sampling, output driving
You can disable individual constraints or all constraints for an object using skew
constraint_mode(). input data_out;
output data_in;
class pkt; endclocking
rand int addr;
constraint c_range { addr inside {[0:255]}; } Inside TB, you can write cb.data_in <= value; and @(cb); for clean timing
endclass
semantics.
pkt p = new();
initial begin
// disable single constraint
p.c_range.constraint_mode(0);
39. Where do we define clocking block?
[Link](); ● Typically , because the interface already
contains the clock and related signals.
// re enable later if needed
p.c_range.constraint_mode(1); ● This keeps the timing information local to the bus definition and
end reusable across multiple modules.
interface bus_if(input logic clk);
You can also override constraints in a derived class instead of disabling logic req, gnt;
them (see Q47).
clocking cb @(posedge clk);
output req;
input gnt;
endclocking
35. What is a wildcard bin? endinterface
class base_pkt;
Assume event ev; rand int addr;
constraint c_addr { addr inside {[0:255]}; }
● @ev; – blocks until ev is triggered once.
endclass
●
class small_addr_pkt extends base_pkt;
wait([Link]); – waits until event’s triggered property // overrides c_addr from base
becomes non‑zero (can be used with additional conditions): constraint c_addr { addr inside {[0:15]}; }
endclass
wait([Link] && ready);
44. What is SystemVerilog event schedule? 48. What is semaphore and how is it used in a
program?
SystemVerilog divides each simulation time step into (the
stratified event queue): (See Q9.) In summary: semaphores are used with get/try_get/put to
implement blocking and non‑blocking access to shared resources.
1. – sampling for assertions, etc.
2. – evaluation of always blocks, blocking assignments.
3. – #0 events. 49. How does semaphore implement blocking
4. – LHS updates of non‑blocking methods?
assignments.
5. – assertion evaluation after NBAs. ● get(n) is a : if fewer than n tokens are available, the
process waits in the semaphore queue until enough tokens are
6. – final $display and monitoring.
returned.
This ordering ensures consistent interaction between blocking/non‑blocking ● try_get(n) is : it returns 1 on success, 0 on failure,
assignments and assertions. and never blocks.
if (!sem.try_get(1)) begin
$display("resource busy, skipping");
end
45. How do we inherit properties and methods? else begin
// exclusive access here
[Link](1);
By using extends when declaring a class: end
class parent;
int id;
function void show();
$display("id=%0d", id); 50. What is the coverpoint?
endfunction
endclass
A is part of a covergroup that specifies the
class child extends parent; whose values you want to track for functional coverage.
int extra;
endclass covergroup cg @(posedge clk);
coverpoint addr { bins all[] = {[0:15]}; }
endgroup
child now has both id and extra, plus the show() method.
Each time the covergroup is sampled, the current value of addr is recorded
in the appropriate bin.
46. What are properties and methods?
29
51. What is polymorphism and how is it
implemented? 57. Explain code coverage and functional
(Already explained in Q5 and Q29.) In short: - Implemented via coverage with example.
. - Base handle points to derived object;
when calling a virtual method, the derived implementation runs. Code coverage example: enabling tool options to measure how many
statements and branches of a FIFO RTL module were executed.
SystemVerilog classes fully support OOP and UVM builds on this model.
60. Difference between fork join_any and fork join_none .
● join_any: parent waits for first child to complete, then remaining
55. Explain fork..join, join_any, join_none. children are killed.
fork ● join_none: parent does not wait at all; children run concurrently
task1();
task2(); while parent continues.
join
// Parent thread waits until BOTH task1 and task2 finish. This affects how long the testbench thread stays alive and how timeouts
must be handled.
fork
task1();
task2();
join_any
// Parent waits until ANY ONE finishes, then remaining threads are
terminated.
61. What is Assertion?
● An is a statement that checks that a given property
fork holds during simulation (or formal analysis).
task1();
task2(); ● They help and document the
join_none intended behavior.
// Parent does NOT wait; both tasks continue in background.
Types: immediate (single‑cycle) and concurrent (multi‑cycle temporal
Used for parallelism in testbenches and some RTL models. properties).
56. What are constraints and why are they used? 62. What is modport?
(See Q22.) They are used to: - Constrain random values to ranges. - ● A is a named view of an interface that defines which
Model dependency relations between fields. - Improve coverage closure by signals are for a given user (DUT, TB,
focusing on interesting cases instead of fully random noise. etc.).
30
interface bus_if(input logic clk); (As earlier.)
logic req, gnt;
modport DUT (input req, clk, output gnt); class fib_seq;
modport TB (output req, input gnt, clk); rand int f[];
endinterface constraint c_size { [Link]() == 8; }
constraint c_fib {
The DUT and testbench modules use different modports, enforcing correct f[0] == 0;
direction usage. f[1] == 1;
foreach (f[i]) if (i>=2) f[i] == f[i-1] + f[i-2];
}
endclass
63. How many bins will be created for the This generates the first 8 Fibonacci numbers: 0,1,1,2,3,5,8,13.
covergroup shown?
module top;
bit [6:0] a;
int b; 67. Write a constraint to generate sequence of
covergroup vk_coverage;
coverpoint a;
prime numbers.
coverpoint b {
bins b_bin1 = {1,2,3,4,5}; Pure declarative prime constraints are complex, so a practical answer
bins b_bin2 = default; mixes randomization with procedural checks.
}
endgroup class prime_seq;
endmodule rand int p[];
constraint c_size { [Link]() == 5; }
● coverpoint a on a 7‑bit variable creates ; most tools function bit is_prime(int n);
create 128 bins (one per value). int i;
if (n < 2) return 0;
● coverpoint b has 2 explicit bins: b_bin1 and a default bin for (i = 2; i*i <= n; i++)
b_bin2. if (n % i == 0) return 0;
return 1;
● So total ≈ . Mention that the exact number for a can endfunction
31
70. What are types of constraints? if (!rst_n)
q <= 1'b0; // initialization
else
Common constraint patterns: q <= d;
end
● : a inside {[0:10]};
● : a < b;
76. What is modport?
● : opcode inside {READ, WRITE};
(Same as Q62.) Modports help partition interface signals by direction for
● : a dist {0 := 80, 1 := 20}; different users.
● : unique {a, b, c};
Combinational logic computes next_state from state and inputs. 80. What is the main advantage of
SystemVerilog?
● SystemVerilog unifies
75. How flip flops are initialized in sequential into a single language.
circuits? ● It provides:
● Flip‑flops are initialized using (synchronous or o Modern RTL constructs (always_ff, interfaces, rich
asynchronous). types).
● You drive reset at TB top for some cycles; RTL sets registers to o Powerful verification features (classes, constraints,
known values when reset is asserted. coverage, SVA).
always_ff @(posedge clk or negedge rst_n) begin
32
o Ecosystem support through methodologies like ,
which standardize how verification environments are
built.
33
4. Explain threads.
SystemVerilog Interview Q&A – Set 7 In SV, a is an independent process that can run in parallel with
(Q1–43) others.
initial begin
● – groups DUT signals and connects #10; $display("Thread 2 after 10 time units");
TB classes to DUT. end
● – class that models one stimulus
item (e.g., bus read/write). Both initial blocks are separate threads executing concurrently.
● – creates a stream of transactions (often
constrained‑random).
● – converts transactions into pin‑level activity on the 5. Explain events.
interface.
● – passively samples DUT signals and converts them An is a simple synchronization object.
back to transactions.
● – checks DUT outputs vs Declared as event ev;.
expected results. Triggered with -> ev; or ->> ev; (non‑blocking trigger).
● – functional coverage using covergroups. Waited on with @ev; or wait([Link]);.
● – containers that build, connect, and
Example:
configure the above.
● – top‑level class selecting configuration, sequences, and event done;
running the simulation.
initial begin
#5; -> done; // trigger
Data flow: . end
initial begin
@done; // wait
2. Difference between mailbox and queue. $display("Received event at %0t", $time);
end
property p_clk_toggles;
- Primarily a hardware description language for RTL and gate‑level @(posedge clk) $changed(clk);
design. - Limited data types (reg, wire, integer, real). - No classes, no endproperty
constrained randomization, no functional coverage. - Basic tasks/functions
// Better: check that period is within range using a reference time
and simple testbenches.
property p_clk_period;
time t1, t2;
- Superset of Verilog (backward compatible). - Adds @(posedge clk)
powerful : classes & OOP, rand/randc, constraints, (t1 = $time), ##1 (t2 = $time,
(t2 - t1) inside {[9:11]}); // 10 time units ±1
covergroups, assertions (SVA), mailboxes, semaphores, queues, dynamic endproperty
& associative arrays. - Adds : logic, always_ff,
always_comb, interfaces, packed structs/unions, enums, unique/priority, etc. assert property (p_clk_period);
- Enables standard methodologies like .
Even simpler form used in labs:
34
// Clock must not stop toggling module tb_top;
property p_clk_not_stuck; logic clk; bus_if bus(clk);
@(posedge clk) 1 |-> ##1 $rose(clk) or $fell(clk); driver d;
endproperty initial begin
assert property (p_clk_not_stuck); d = new(bus); // pass interface to class
end
endmodule
interface bus_if(input logic clk); Call [Link]() repeatedly; order alternates between ascending and
logic req, gnt; descending.
endinterface
class driver;
virtual bus_if vif; // virtual interface handle
13. Tasks t1, t2, t3 executed in parallel but must
function new(virtual bus_if vif);
[Link] = vif; finish in order t3, then t2, then t1.
endfunction
We can run them in parallel using fork...join_none and use events /
task run(); semaphores to enforce completion order.
forever begin
@(posedge [Link]);
task t1(); #20; $display("t1 done"); ->ev1; endtask
[Link] <= 1'b1;
task t2(); #10; $display("t2 done"); ->ev2; endtask
end
task t3(); #5; $display("t3 done"); ->ev3; endtask
endtask
endclass
event ev1, ev2, ev3;
35
$display("Thread B start");
initial begin #5; $display("Thread B end");
fork end
t1();
t2(); A and B run concurrently. You can also spawn threads inside a procedural
t3();
join_none // start all three in parallel block:
Another way is to use a semaphore with proper token ordering, but events
are simpler.
15. Explain arrays and types. task t1(); ... ->e1; endtask
task t2(); ... ->e2; endtask
SystemVerilog arrays types: task t3(); ... ->e3; endtask
initial begin
● – bits laid out contiguously; useful for arithmetic fork
and slicing. t1();
t2();
logic [7:0] byte_packed; // packed t3();
join_none
● – size decided at runtime, changeable with All three run in parallel, but the checking/printing or follow‑up logic waits for
new[]. completion in order t3 → t2 → t1.
● – indexed by key type (int, string, etc.). 19. How the semaphore is worked?
int aa[string]; aa["ID"] = 5; Operational explanation:
initial begin
36
This mechanism ensures only a limited number of threads can enter the output gnt);
modport TB (output req,
critical section.
input gnt, clk);
endinterface
Example:
21. What is mailbox? And its different methods. interface axi_if(input logic aclk);
logic valid, ready;
logic [31:0] addr, data;
A is a class‑based message queue used for communication
between threads or components. // protocol task
task send(input logic [31:0] a, d);
Declaration and creation: addr <= a;
data <= d;
mailbox mbx; // unbounded valid <= 1;
mailbox #(packet) mbx_p; // parameterized @(posedge aclk);
initial mbx = new(); wait (ready);
valid <= 0;
endtask
Common methods: - put(item) – blocking put, waits if mailbox is full (for endinterface
bounded mailbox). - get(item) – blocking get, waits until an item is
available. - try_put(item) – non‑blocking; returns 1 on success, 0 if full. -
try_get(item) – non‑blocking; returns 1 on success, 0 if empty. -
peek(item) – read item without removing it. - num() – returns current 25. Define clocking block.
number of items.
A defines a clock domain and specifies when signals are
sampled and driven relative to that clock, avoiding race conditions.
22. Define different threads of fork_join and give interface bus_if(input logic clk);
logic req, gnt;
example for fork...join_none with code snippet.
clocking cb @(posedge clk);
fork...join has three variants: default input #1step output #2ns; // skews
output req;
input gnt;
● fork...join – parent waits for child threads to finish. endclocking
endinterface
● fork...join_any – parent waits until child finishes;
remaining threads are killed. Inside TB you use [Link] and @(cb) for timing‑safe operations.
37
$rose can be used on any boolean expression; posedge is tied to event
control.
31. Write functional coverage for 32x32 memory
array.
27. What is immediate and concurrent assertion? Example: cover all addresses and read/write operations for a 32x32
Explain. memory.
- Checked at the time they are executed in covergroup mem32x32_cg @(posedge clk);
coverpoint addr { bins all_addr[] = {[0:31]}; }
procedural code. - Used for single‑cycle conditions. coverpoint we { bins read = {0};
bins write = {1}; }
assert (a <= b) cross addr, we;
else $error("a > b"); endgroup
- Describe temporal properties over multiple clock You can also add data value bins if required.
cycles using sequence and property. - Sampled and evaluated in the
assertion regions of the event schedule.
property p_req_gnt;
@(posedge clk) req |-> ##1 gnt; // if req, gnt must be high next 32. What is functionality of bins?
cycle
endproperty In a covergroup, define which values or value ranges to track. Each
assert property (p_req_gnt); time the covergroup is sampled, the current value falls into one bin, and
that bin’s hit count is incremented.
class base_pkt;
int id; 33. Write constraint to generate unique values
function void print();
$display("base id=%0d", id);
for array of 16 elements.
endfunction class unique_arr;
endclass rand int a[];
constraint c_size { [Link]() == 16; }
class read_pkt extends base_pkt; constraint c_unique { unique { a }; }
int data; endclass
function void print();
[Link](); unique {a} ensures all elements in array a have different values.
$display("read data=%0d", data);
endfunction
endclass
38
} After shallow copy, changing p2.a changes p1.a; after deep copy, they are
endgroup
independent.
36. What is constraint and types? 40. What is clocking block and modport?
A restricts the set of values that rand/randc variables can take ● – defines timing (sampling/driving) for signals
during randomization. relative to a clock; used inside interfaces.
● – defines a specific view of interface signal directions for
Common types / styles: - Range constraints – a inside {[0:10]}; - a user (DUT, TB, monitor, etc.).
Relational constraints – a < b; - Set/inside constraints – opcode inside
{READ, WRITE}; - Distribution constraints – a dist {0 := 50, 1 := 50}; - Example:
Uniqueness constraints – unique {id0, id1}; - Conditional/implication
constraints – (mode==BURST) -> len>1; - Soft vs hard constraints – soft interface bus_if(input logic clk);
logic req, gnt;
keyword for overridable defaults.
clocking cb @(posedge clk);
default input #1step output #2ns;
output req;
37. Write code for blocking and non-blocking. input gnt;
endclocking
// Blocking assignment (=)
always @(posedge clk) begin modport DUT (input clk, req, output gnt);
a = b; // RHS evaluated and assigned immediately modport TB (clocking cb);
end endinterface
39
Good controllability and observability are essential for
.
SystemVerilog Interview Q&A – Set
8A (Q1–30)
5. What is Thread and explain the different
thread synchronization techniques.
1. What is $write? In SystemVerilog, a is an independently executing process created
by:
$write is a SystemVerilog system task used to
.
● initial / always blocks
$write("Time = %0t value = %0d ", $time, data);
● fork...join* blocks
● Use $write when you want to ● process class
and control where line breaks occur (usually by printing "\n"
yourself or by a later $display).
$display("Time = %0t value = %0d", $time, data); 17. fork...join, join_any, join_none – specify how parent thread
waits for child threads.
● Every $display call starts on a new line in the transcript. 18. – synchronize TB actions to clock edges.
● Same formatting rules as $write with %0d, %0h, %0b, %0s, etc.
6. What is blocking and non blocking
assignment?
3. How to improve the Test Coverage.
● =)
To improve overall coverage (code and functional):
o Executes immediately and the execution of
– identify unhit / low‑hit areas. following statements until assignment completes.
33.
– remove over‑constraining that o Used mainly in or testbench
34.
prevents some scenarios. procedural code.
40
● Improve – failures point directly to violated 12. Differentiate between Mailbox and Queue.
property.
● Can be reused in formal tools for exhaustive checking. - Class‑based communication channel between
threads/components. - Methods: put, get, try_put, try_get, peek, num. -
Types: (single‑cycle, procedural) and (temporal, put/get can be ; used for synchronization + data transfer.
multi‑cycle SVA).
[$]) - Built‑in dynamic container inside one process. - Methods:
push_front, push_back, pop_front, pop_back, insert, delete. - No blocking
semantics; just stores data.
8. Differentiate between fork-join, fork-join_none and
So:
fork-join_any.
,
.
Assume:
fork
task1(); 13. Differentiate between Task and Function.
task2();
join // or join_any / join_none
- Executes in (no @, #, wait, fork). - Can be
used in expressions and RHS of assignments. - Returns a single value or
● fork...join – Parent waits until child threads finish. void.
● fork...join_any – Parent waits until child finishes; - May contain and can run for multiple cycles. -
remaining threads are . Cannot be used in expressions; called as a statement. - Can have multiple
input/output/inout arguments.
● fork...join_none – Parent ; child threads continue
in background while parent proceeds. Example:
initial begin
a = 1; b = 0; #1;
15. What is the difference between global
$display("y = %0b", y); // $display prints with newline declaration and local declaration of variables?
a = 1; b = 1; #1; ●
$write("y = %0b ", y); // $write without newline o Visible in a wider scope (e.g., package, module, or
$display("(using display again)");
end class level).
endmodule o Can be accessed from many blocks; easier to share
but can create coupling.
●
41
o Declared inside a ; visible ● Works well with to measure progress.
only within that scope.
o Helps encapsulation and avoids name clashes. Example:
class pkt;
Within classes you can also use local / protected keywords to restrict rand bit [7:0] addr, data;
access from outside the class or derived classes. constraint c { addr inside {[0:15]}; }
endclass
pkt p = new();
repeat (10) begin
16. Define assertions and need of assertions in assert([Link]());
verification. $display("addr=%0h data=%0h", [Link], [Link]);
end
cg cov = new();
Coverage report tells how many opcodes and length ranges have been
17. Explain fork-join, fork-join_any and fork-join_none
exercised and which combinations are missing.
techniques.
Already summarized in Q8; here with a bit more detail:
Use join when you need all results, join_any for “first response wins” Many errors (like range mismatches, missing connections) are detected at
behavior, and join_none for background threads. elaboration; dynamic behavior issues appear at runtime.
18. Explain Randomization and need of 21. What is self checking testbench?
randomization in design verification.
A automatically compares DUT outputs against
in SystemVerilog means using rand/randc variables and expected values and .
constraints with randomize() to automatically generate input stimulus.
Typically includes:
Need / advantages:
● (sequences)
● Quickly explore a of input combinations. ● to sample DUT outputs
● Find corner‑case bugs that are hard to think of manually. ●
● Together with , ensures only scenarios are ● that compares actual vs expected and logs
generated. mismatches
42
● for temporal checks
da = new[10]; // allocate 10 elements
Self‑checking is essential for regressions where manual waveform
// resize to 20 and keep old values
inspection is impossible. int tmp[];
tmp = new[20];
for (int i = 0; i < [Link](); i++)
tmp[i] = da[i];
da = tmp;
22. Define assertions and need of assertions.
Dynamic arrays are useful when the number of elements is not known at
Same as Q7/Q16, but short:
compile time but indices are dense (0..N-1).
● Assertions: executable properties that the design must satisfy.
● Needed to detect protocol violations, illegal states, and to
formalize the spec. 27. Write a Code to Randomize a Dynamic Array
of size 10 and should have Even Numbers.
23. What is Constraints? class even_da;
rand int da[];
In SystemVerilog, are declarative rules on rand/randc variables constraint c_size { [Link]() == 10; }
written inside classes with the constraint keyword. They guide the constraint c_even {
foreach (da[i]) da[i] % 2 == 0;
during randomize() so that only are }
generated. endclass
constraint c_pattern {
foreach (a[i]) {
if (i < [Link]()/2)
25. What is difference between Shallow Copy and a[i] % 2 == 0; // first half even
else
Deep Copy? a[i] % 2 == 1; // second half odd
}
● : copies only the handle → both handles point to the }
. Modifying through one handle affects the other. endclass
pkt p1 = new();
pkt p2 = p1; // shallow
29. What is Functional Coverage?
● : creates a and copies over contents.
(See Q19.) Short answer:
class pkt;
● User‑defined metric using covergroups that checks how much of
int a;
function pkt copy(); the has been exercised.
pkt t = new(); ● Complementary to code coverage.
t.a = this.a;
return t;
endfunction
endclass
30. Write a Constraint to generate the 2 to the
pkt p3 = [Link](); // deep power of 2 Values.
Deep copy is preferred when storing transactions for later checking. If question means generate numbers that are (1,2,4,8,…):
class pow2_vals;
rand int x;
43
Alternatively use an exponent variable:
class pow2_alt;
rand int e;
int x;
constraint c_e { e inside {[0:7]}; }
function void post_randomize();
x = 1 << e; // x = 2^e
endfunction
endclass
44
The mailbox automatically handles between generator and driver.
Two classes communicate using such 1. Instance of a class that extends uvm_object or plain
as: class.
2. Created with new(), no fixed place in testbench
● – one class put()s transactions, another get()s them. hierarchy.
● – both classes hold a handle to the 3. Typically used for , configuration,
same queue or object and use methods to exchange data. sequences.
● – uvm_blocking_put_port,
●
uvm_blocking_get_port, etc.
o Class that extends uvm_component.
Simple mailbox example: o Part of the ; built in
class producer; build_phase() and has a parent/child relationship.
mailbox #(int) mbx; o Represents structural elements: environment, agent,
function new(mailbox #(int) mbx); [Link] = mbx; endfunction
task run(); int v; forever begin driver, monitor, scoreboard.
v = $urandom_range(0,100);
[Link](v); So: object = data / lightweight helper; component = structural TB element
end endtask with phases and hierarchy.
endclass
class consumer;
mailbox #(int) mbx;
function new(mailbox #(int) mbx); [Link] = mbx; endfunction
task run(); int v; forever begin
4. Write a code for a class to display a property
[Link](v); from calling function.
$display("Got %0d", v);
class my_class;
end endtask
int value;
endclass
function new(int v = 0); value = v; endfunction
Both classes share the same mailbox handle, hence they communicate. function void print();
$display("value = %0d", value);
endfunction
endclass
45
obj.push_back(10); int i, j, tmp;
obj.push_back(20);
[Link](); initial begin
$display("popped = %0d", obj.pop_front()); for (i = 0; i < 5; i++)
end for (j = i+1; j < 5; j++)
if (a[j] < a[i]) begin
tmp = a[i]; a[i] = a[j]; a[j] = tmp;
end
Major categories: (Or mention you can also use [Link]() for dynamic arrays / queues.)
● `**)**: ordered collection withpush/pop` operations. and_r = s.a & s.b; // bitwise AND
if (|and_r) // logical test using reduction OR
● Each of the above can be or based on $display("and_r = %b", and_r);
declaration. end
endmodule
If interviewer insists on “pointer” concept, you can say: use class handles
8. Differentiate between dynamic array, or ref arguments.
associative array and queue.
● : contiguous indices 0..size-1, resizable with
new[]. Good when number of items known but calculated at 12. Explain Mailbox and its methods.
runtime.
Mailbox is a between
● : indexed by key type; sparsely populated; threads/components.
supports exists, first, next for traversal.
Declaration:
● `**)**: ordered list;
supportspush_front,push_back,pop_front,pop_back`; good for mailbox mbx; // untyped
FIFO/LIFO behavior. mailbox #(packet) mbx_p; // typed
Key methods:
initial begin
● Queue: dynamic array [$], non‑blocking, used as data structure
a = new(); b = new(); c = new(); inside a thread.
fork
begin [Link](); [Link](); [Link](); end
join 18. Explain polymorphism and its application.
end
Polymorphism: base‑class handle refers to different derived objects; calling
Or using events to signal completion: virtual method invokes derived implementation.
event ea, ec;
Application: in UVM, many APIs use base types (uvm_sequence,
// in main thread uvm_driver), but actual behavior comes from derived classes selected by
fork factory or configuration (e.g., different protocol drivers, different
begin [Link](); ->ea; end sequences) without changing testbench structure.
begin @ea; [Link](); ->ec; end
begin @ec; [Link](); end
join
Describe in words: we can chain tasks using events so that A must finish 19. Which is the default array used in
before C starts, and C must finish before B. SystemVerilog?
When you declare an array without explicitly specifying packed/unpacked,
you usually refer to . Some interviewers also expect:
14. Write a code to generate odd numbers using is default choice in verification when number of elements is
constraints. not fixed. A safe short answer:
class odd_c;
rand int x; Default normal array in SV is an with index
constraint c_odd { x % 2 == 1; } range specified to the right of the variable name.
endclass
Explain with
47