← Design Verification Interviews
Interview Question · Concept
What Context and Pure Promise
The Question
The interviewer asks
What does context give the C code, and what does pure allow the simulator to do? Which do you choose for a stateful reference model?
You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
A context import gets the calling scope. So C may call exports, use svGetScope and use VPI. The simulator must record that scope and assume C may change SystemVerilog state. A pure function promises its result depends only on its arguments. So the simulator may skip or reuse calls, though it does not have to. A stateful model is never pure: use a plain import, and context only if it calls back.
Self-Check
Tick each key point you covered in your answer.
What Interviewers Listen For (Junior)
Names one thing each keyword allows, and rejects pure for a model that keeps state.
What Interviewers Listen For (Mid-Level)
Explains pure as permission, not a cache, and asks whether the C calls back before choosing context.
What Interviewers Listen For (Senior)
Warns that a stateful function marked pure can pass on one simulator and fail on another, and makes this a review rule.
Cross-Questions
Where the interviewer goes next. Open a node to practise that follow-up.
WhyBreak ItCompareScale It
- What Context and Pure Promise
-
WhyWhy Context Imports Cost MoreL2 Mid-Level
Why is a
contextimport slower than a plain one?2:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
On each call, the simulator records the calling scope so C can ask for it. C may also call exports that change SystemVerilog variables. So the simulator cannot keep values cached across the call. A plain import promises neither, so the call can be cheaper.
Self-Check
Tick each key point you covered in your answer.
Misconception
"Context makes the call run in a separate thread."
Every DPI call runs on the calling simulator thread and returns before the caller continues. Context adds the scope, not a thread.
Source Lesson D1.7 (the call chain is synchronous; measured on Verilator 5.052)
-
CompareCallbacks Compared with ArgumentsL2 Mid-LevelL3 Senior
The C model needs five configuration values. Compare passing them as arguments with letting C fetch them through exported getters.
2:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
Arguments keep the import plain and the data flow visible. C cannot read anything the testbench did not hand it. Getters need a
contextimport and hide the dependency inside C. They also run on every call unless C caches them. Pass configuration once, at model creation or reset, and keep callbacks for real events such as reporting an error.Self-Check
Tick each key point you covered in your answer.
What Interviewers Listen For (Senior)
Puts configuration in a create or reset call, so the hot path stays a plain import.
Half-Truth
"Getters are better, because C always sees the latest value."
Configuration rarely changes inside a test. When it does, a reset or reconfigure call makes the change explicit and testable.
-
Break ItA Stateful Function Marked PureL3 Senior
Break it: a sequence-number model is declared
pure, and every test passes on your simulator. What could happen on another simulator or a new release?2:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
The other tool may skip a call whose result looks unused, or reuse an earlier result for the same arguments. Then the model misses an update, and its sequence numbers drift from the DUT. Nothing in your passing runs proves the declaration is safe. Review imports for
pureon any function with side effects.Self-Check
Tick each key point you covered in your answer.
What Interviewers Listen For (Senior)
Treats a passing run as no evidence here, and fixes it with a declaration rule, not a test.
Tool as Truth
"It passed on our simulator, so
pureis fine."Skipping is optional. Verilator 5.052 never skipped in our probe, so a run there cannot show the bug that another tool may expose.
Source ASIC Point engine notes (Verilator 5.052 DPI probe, 2026-11-08: a pure import with an unused result was still called)
-
Scale ItKeeping Pure Honest in a TeamL3 SeniorL4 Staff
How do you stop this mistake across a team of twenty engineers?
2:30You have two and a half minutes. Speak or type, then press Get Feedback under your answer. No credits needed.
Speech-to-text runs in your browser. Chrome and Edge may send audio to their own speech service.
You can edit your answer before you send it. Feedback uses AI and checks your answer only against our written answer. No credits are used and your answer is not saved.
Reveal the Model Answer
Keep every import in one package, so a reviewer sees all declarations together. Allow
pureonly for functions that are clearly mathematical, such as a CRC of the arguments. Run the regression on a second simulator when the project has one, because skipped calls show up there first.Self-Check
Tick each key point you covered in your answer.
Half-Truth
"Write a test that checks the pure function is called every time."
A test cannot force the optimiser to act. The tool that skips calls may not be the one the test runs on.
What People Get Wrong
Common wrong answers and why they fail. Run It shows the wrong belief failing on a real simulator.
Misconception
"pure makes the simulator cache the result, so calling it in a loop is free."
It is a permission, not a promise. Verilator 5.052 made every call in the twin. Another simulator may reuse results, which is why state must never hide behind pure.
Run It
A pure import called 100 times with the same argument. A C counter records each real call.
x=9 calls into C=100 FAIL: the simulator made all 100 calls; pure allows reuse but does not promise itSee the Fix
module tb;
// The fix: the testbench calls once and keeps the value itself.
import "DPI-C" pure function int c_sq(input int v);
import "DPI-C" function int c_calls();
int x;
initial begin
x = c_sq(3);
for (int i = 0; i < 100; i++) assert (x == 9);
$display("x=%0d calls into C=%0d", x, c_calls());
if (c_calls() == 100) $display("FAIL: the simulator made all 100 calls; pure allows reuse but does not promise it");
else if (c_calls() == 1) $display("PASS: one call, because the testbench reused the value");
$finish;
end
endmodule
Prints: x=9 calls into C=1 PASS: one call, because the testbench reused the value
Misconception
"A function that only reads a C global is still pure."
Its result depends on that global, not only on its arguments. If the simulator reuses an old result, the model reads stale state.
Source IEEE 1800-2017 §35.5.2 (pure functions)
Half-Truth
"context lets C read the module's variables directly."
It gives C a scope, not a pointer into the module. C still reads through exported functions or VPI.
Buzzword Without Mechanism
"Mark every import context, just to be safe."
Each context call makes the simulator save the scope. It must also treat the call as able to change any SystemVerilog state, which blocks optimisation.
Source Spear & Tumbush, SystemVerilog for Verification (3rd ed.), §12.7