Skip to content

Commit 3346b87

Browse files
committed
vcs: Ensure correct execution order of difftest DPI calls
An additional `simv_step_event` was introduced to control the execution order of the `simv_nstep()` DPI call. The order of DPI calls in different `always` blocks is inherently unpredictable. Since `simv_nstep()` depends on the state updated by other `v_difftest_*` DPI calls, a `#0.1` delay was added to ensure that `simv_nstep()` is executed at the end of each clock posedge. This modification resolves potential timing issues caused by the implicit dependency between difftest DPI calls. Additionally, the file extension of `DifftestEndpoint.v` was changed to `.sv`, as the `event` mechanism is a feature specific to SystemVerilog. Signed-off-by: Jiuyue Ma <[email protected]>
1 parent 6928751 commit 3346b87

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/test/vsrc/vcs/DifftestEndpoint.v renamed to src/test/vsrc/vcs/DifftestEndpoint.sv

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ DeferredControl deferred(
269269
);
270270
`else
271271
reg [7:0] simv_result;
272+
`ifdef PALLADIUM
273+
/*
274+
* In PALLADIUM, we delay the step signal to next cycle to make sure
275+
* `simv_step` was triggered after other DPI calls, which needs more
276+
* trick to be correct. Such as introducing `ping-pong buffer` to
277+
* handle the delay-step, and dpics at the next cycle coming together.
278+
*/
272279
always @(posedge clock) begin
273280
if (reset || simv_result == `SIMV_DONE) begin
274281
simv_result <= 8'b0;
@@ -279,6 +286,40 @@ always @(posedge clock) begin
279286
end
280287
end
281288
end
289+
`else
290+
/*
291+
* for other platform, we introduce a delayed difftest step
292+
* mechanism to make sure all difftest state was updated properly
293+
* before `simv_step()` called.
294+
*/
295+
reg [7:0] _res;
296+
event simv_step_event;
297+
// check difftest_step
298+
always @(posedge clock) begin
299+
if (!reset) begin
300+
if (n_cycles && |difftest_step) begin
301+
// delay a little before trigger the simv step event
302+
#0.1 -> simv_step_event;
303+
end
304+
end
305+
end
306+
// all difftest state was updated, step difftest by `simv_nstep()`
307+
always @(simv_step_event or posedge reset) begin
308+
if (reset)
309+
_res <= 8'b0;
310+
else
311+
_res <= simv_nstep(difftest_step);
312+
end
313+
// update to `simv_result` at next cycle
314+
always @(posedge clock) begin
315+
if (reset || simv_result == `SIMV_DONE) begin
316+
simv_result <= 8'b0;
317+
end
318+
else begin
319+
simv_result <= _res;
320+
end
321+
end
322+
`endif // PALLADIUM
282323
`endif // CONFIG_DIFFTEST_DEFERRED_RESULT
283324

284325
/*

vcs.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ VCS_FLAGS += +incdir+$(GEN_VSRC_DIR)
107107
VCS_FLAGS += $(EXTRA)
108108

109109
VCS_VSRC_DIR = $(abspath ./src/test/vsrc/vcs)
110-
VCS_VFILES = $(SIM_VSRC) $(shell find $(VCS_VSRC_DIR) -name "*.v")
110+
VCS_VFILES = $(SIM_VSRC) $(shell find $(VCS_VSRC_DIR) -name "*.v" -or -name "*.sv")
111111
$(VCS_TARGET): $(SIM_TOP_V) $(VCS_CXXFILES) $(VCS_VFILES)
112112
$(VCS) $(VCS_FLAGS) $(SIM_TOP_V) $(VCS_CXXFILES) $(VCS_VFILES)
113113
ifeq ($(VCS),verilator)

0 commit comments

Comments
 (0)