SystemVerilog Interview Q&As
SystemVerilog Interview Q&As
2) What is pre_randomization?
A callback function that is automatically called before randomization of an object to set
initial values or states.
my_array.sort(); // Ascending
my_array.rsort(); // Descending
rand int x;
constraint c { x > 5 && x < 10; }
covergroup cg;
coverpoint addr { bins range[] = {[0:255]}; }
endgroup
property ack_p;
@(posedge clk) req |=> ack;
endproperty
assert property (ack_p);
Level-triggered:
property ack_level;
@(posedge clk) req && !ack |-> ack;
endproperty
Distributed:
var dist { 1 := 2, 2 := 1 }; // 2:1 ratio
initial begin
q = {1, 2, 3, 4}; // Initialize
foreach (q[i]) $display("q[%0d] = %0d", i, q[i]); // Display
End
41) Driver code for data payload (dynamic array) and enable signal
task send_data(input bit enable, input int data[]);
if (enable) begin
foreach (data[i]) begin
$display("Sending data: %0d", data[i]);
end
end
endtask
42) Difference between posedge and $rose
posedge: Trigger used in procedural blocks (@posedge clk).
$rose(signal): Function used in assertions to detect rising edge.
Example:
covergroup cg;
coverpoint a {
bins b0 = {0};
bins b1 = {1};
}
endgroup
constraint bidir {
a + b == 10;
a inside {[2:8]};
}
61) Assertion code to generate 100 MHz signal (check posedge and negedge)
Assuming a 10 ns clock period:
property check_100MHz;
time t;
@(posedge clk)
t == $time % 10ns == 0;
endproperty
To check edges:
property clk_edges;
@(posedge clk) 1 |-> $rose(clk) or $fell(clk);
endproperty
62) If base class is encrypted, how to write constraint in extended class?
Define new constraints in the extended class using only inherited variables (no redefinition).
If access is restricted, override using public/protected members.
initial begin
#10 a <= b;
#20 a <= c;
end
a <= b;: Non-blocking; will schedule to update in the next time slot. Result: Non-blocking
may cause both a <= b and a <= c to evaluate to the same a.
93) What to do with 100% code coverage and 30% functional coverage?
Functional scenarios are lacking. Analyze:
Missing coverpoints
Incomplete stimulus
Improve testcases to cover real functionality