Work it through
An information-loss check
Discarding bval turns the four low aval bits into binary 1010. It loses the distinction between real binary bits and unknown/high-impedance positions.
Keeping both masks preserves the exact 10XZ sample.
Your next page is on its way.
Chapter 2 · Interfaces, scheduling & DPI
Place testbench execution in the correct event region and cross the DPI boundary without losing type, lifetime, or ownership guarantees.

A worked mechanism
A C integer cannot carry all four SystemVerilog logic values.
logic [3:0] v = 4'b10xz
The packed input is exactly four bits.
low aval = 4'b1010; low bval = 4'b0011
For svLogicVecVal: 0=(0,0), 1=(1,0), X=(1,1), Z=(0,1), in (aval,bval) order.
do not keep only aval
Use the simulator DPI declaration and helpers; preserve both planes.
round trip = 4'b10xz
Recombine both planes for the same four meaningful bits.
Work it through
Discarding bval turns the four low aval bits into binary 1010. It loses the distinction between real binary bits and unknown/high-impedance positions.
Keeping both masks preserves the exact 10XZ sample.
The diagram shows the low four meaningful bits of the DPI word. Unused padding bits and simulator storage must not be interpreted as payload; pointer lifetime still follows the DPI contract.
Round-trip 0, 1, X, and Z at each bit position through the adapter, checking values with case equality.
The language bench / interfaces
clocking driver_cb @(posedge clk);
default input #1step output #0;
input ready;
output valid, data;
endclocking
modport DRIVER (clocking driver_cb);interface rv_if(input logic clk);
logic valid, ready;
logic [7:0] data;
clocking driver_cb @(posedge clk);
default input #1step output #0;
input ready;
output valid, data;
endclocking
clocking monitor_cb @(posedge clk);
default input #1step;
input valid, ready, data;
endclocking
modport DUT (input clk, valid, data, output ready);
modport DRIVER (clocking driver_cb);
modport MONITOR (clocking monitor_cb);
endinterfaceA virtual interface references an existing interface instance. Constructing a class does not instantiate hardware. Bind the correctly typed view before using it; here the constructor rejects a null handle.
class rv_driver;
virtual rv_if.DRIVER vif;
function new(virtual rv_if.DRIVER bus);
if (bus == null) $fatal(1, "Driver requires an interface");
vif = bus;
endfunction
task drive_next(input logic next_valid,
input logic [7:0] next_data);
@(vif.driver_cb);
vif.driver_cb.valid <= next_valid;
vif.driver_cb.data <= next_data;
endtask
endclass
// In an elaborated top-level module:
// rv_if bus(clk);
// rv_driver drv;
// initial drv = new(bus);This primitive demonstrates access and drive timing. The caller supplies initialization, reset handling, and the rule that VALID and DATA remain stable until an accepted transfer. One driver owns these outputs.
Input #1step samples immediately before the edge. Synchronous output #0 drives in Re-NBA of that time slot; it is different from a procedural #0 delay. A newly driven request cannot count as already present at the acceptance edge.
The language bench / sampling
VALID=1, READY=0 before 10 ns. The edge has not arrived.
clocking cb @(posedge clk);
default input #1step output #0;
input valid, ready;
endclocking
// DUT: ready <= 1 at the 10 ns edgeQuestion-first preparation
Each question maps directly to one of the sections below, so you can test the contract before reading the explanation.
One representative prompt from each major mechanism. Open any card in the live question bank.
Program, clocking, and scheduler regions
Program blocks and clocking blocks were designed to separate testbench activity from RTL updates. Modern environments still need to understand the event regions even when they use interfaces, classes, and UVM instead.
One simulation time slot
Concurrent assertions capture values before current-slot design updates.
Design evaluation and zero-delay rescheduling; order within a region can race.
Deferred nonblocking LHS updates apply.
Assertions evaluate and program/testbench reactions can follow stabilized design state.
Concurrent assertions capture values before current-slot design updates.
Source order is not a synchronization primitive. The event region and edge-relative skew are the actual temporal contract.
Trace each read and write through Preponed, Active, Inactive, NBA, Observed, Reactive, and postponed behavior at the same simulation time.
Put RTL in design regions, assertions in their sampling/reactive flow, and testbench access behind a clocking or synchronization boundary.
Two blocks that read and write the same signal in the Active region can race even when source order looks deterministic.
Use sampled-value functions, scheduler-aware assertions, randomized compilation order, and tests that drive exactly on a clock edge.
A program executes testbench activity in Reactive regions after design and assertion work for the slot. It restricts some design constructs and was intended to reduce DUT/testbench races. Modern UVM usually uses modules, interfaces, clocking blocks, and explicit objections instead.
A clocking block names a clocking event and direction for each signal. Input skew chooses when values are sampled relative to the event; output skew chooses when drives occur. Assignments to clocking outputs follow clocking-drive semantics, so a universal rule such as “always use =” is incomplete.
interface bus_if(input logic clk);
logic valid, ready;
logic [31:0] data;
clocking drv_cb @(posedge clk);
default input #1step output #0;
input ready;
output valid, data;
endclocking
clocking mon_cb @(posedge clk);
default input #1step;
input valid, ready, data;
endclocking
endinterfaceExplain it out loud
No. They schedule program activity in Reactive regions relative to design activity, but they do not resolve races among testbench threads or replace a clear clocking, ownership, and completion protocol.
A nuanced answer acknowledges the feature without presenting it as the modern UVM default.
Claiming program automatically makes any testbench deterministic.
It defines a named edge-relative sampling and driving contract, including input and output skew, so monitors and drivers do not depend on same-region execution order.
Look for sampling versus driving skew and the reason it removes ambiguity.
Treating a clocking block as only a namespace for interface signals.
DPI
DPI makes C calls convenient, not free. Direction, type mapping, open-array representation, scope, reentrancy, and context all affect correctness and performance.
Foreign-function boundary
Direction and state domain start the contract.
Simulator-defined handles preserve shape and four-state bits.
Copy if data must survive beyond the call.
Compare size, order, values, and error behavior.
Direction and state domain start the contract.
One explicit adapter is easier to validate than many call sites that each guess at C and SystemVerilog representation.
List every imported or exported symbol, data direction, state domain, array shape, callback, simulator-service call, and ownership transition.
Use pure for side-effect-free calls, context only when simulator context is required, and open-array APIs for portable array access.
Assuming native struct layout or retaining a temporary simulator pointer can corrupt data even when the call signature compiles.
Round-trip boundary values, X/Z vectors, empty arrays, callbacks, and repeated calls; profile large transfers rather than assuming zero overhead.
Simple 2-state scalars often map naturally to C integer types. Four-state packed vectors require separate value and unknown masks. Open arrays should be accessed with the DPI API because range direction and representation are simulator-managed.
| Boundary | Question | Proof |
|---|---|---|
| 2-state scalar | Width and signedness? | Min/max and negative tests |
| 4-state vector | Are aval and bval preserved? | 0/1/X/Z round trip |
| Open array | Shape and direction? | Every dimension and empty case |
| String | Encoding and lifetime? | Copy and termination checks |
| chandle | Who owns the object? | Create/use/free lifecycle |
| Callback | Does it need context? | Scope and reentrancy test |
A DPI call crosses runtimes and may marshal data. Small calls in a hot per-cycle loop can dominate model time. Move stable policy into C only when it improves clarity or performance, pass larger batches, and keep cycle-accurate synchronization on the SystemVerilog side.
import "DPI-C" pure function int crc32_2state(
input byte unsigned data[]
);
import "DPI-C" context task inspect_4state(
input logic [127:0] value,
output int unknown_bits
);
export "DPI-C" task report_error;Explain it out loud
A four-state packed value crosses with separate value and unknown-state representation, commonly aval and bval words. Mapping it to a plain C integer would lose X/Z.
The answer should identify information loss and a validation strategy.
Casting a logic vector pointer to uint32_t and assuming portable layout.
No. It is lightweight compared with many alternatives, but call transitions, marshalling, context, and array handling still cost time. Measure and batch hot-path work.
A practical answer balances interoperability with performance and ownership.
Assuming convenience syntax means no runtime or copying cost.