Skip to content

Commit

Permalink
Use DPIC-function to return deferred result (#250)
Browse files Browse the repository at this point in the history
Before this commit, we fetch simv_result at 5000 cycles. Only
when the result is not zero, it works and stop simulation.

Now we use DPIC function to implement the return of simv_result when not
zero, so only one DPIC function will be used to stop simulation.
That will reduce the cost of fetch and get result return faster.
  • Loading branch information
klin02 authored Jan 18, 2024
1 parent 207cceb commit b1ff113
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 29 deletions.
35 changes: 28 additions & 7 deletions src/test/csrc/vcs/vcs_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "ram.h"
#include "flash.h"
#include "refproxy.h"
#ifdef CONFIG_DIFFTEST_DEFERRED_RESULT
#include "svdpi.h"
#endif // CONFIG_DIFFTEST_DEFERRED_RESULT

static bool has_reset = false;
static char bin_file[256] = "ram.bin";
Expand Down Expand Up @@ -90,19 +93,37 @@ extern "C" int simv_step() {
}
}

#ifdef TB_DEFERRED_RESULT
#ifdef CONFIG_DIFFTEST_DEFERRED_RESULT
svScope deferredResultScope;
extern "C" void set_deferred_result_scope();
void set_deferred_result_scope() {
deferredResultScope = svGetScope();
}

extern "C" void set_deferred_result();
void difftest_deferred_result() {
if (deferredResultScope == NULL) {
printf("Error: Could not retrieve deferred result scope, set first\n");
assert(deferredResultScope);
}
svSetScope(deferredResultScope);
set_deferred_result();
}

static int simv_result = 0;
extern "C" void simv_nstep(uint8_t step) {
if (simv_result)
return;
for (int i = 0; i < step; i++) {
int ret = simv_step();
if (ret)
simv_result = ret;
if (ret) {
simv_result = ret;
break;
}
}
if (simv_result) {
difftest_deferred_result();
}
}
extern "C" int simv_result_fetch() {
return simv_result;
}
#else
extern "C" int simv_nstep(uint8_t step) {
Expand All @@ -113,4 +134,4 @@ extern "C" int simv_nstep(uint8_t step) {
}
return 0;
}
#endif // TB_DEFERRED_RESULT
#endif // CONFIG_DIFFTEST_DEFERRED_RESULT
38 changes: 16 additions & 22 deletions src/test/vsrc/vcs/DeferredControl.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,32 @@ module DeferredControl(
output reg simv_result
);

import "DPI-C" function int simv_result_fetch();
import "DPI-C" function void simv_nstep(int step);
import "DPI-C" context function void set_deferred_result_scope();

initial begin
set_deferred_result_scope();
simv_result = 1'b0;
end

export "DPI-C" function set_deferred_result;
function void set_deferred_result();
simv_result = 1'b1;
endfunction

`ifdef CONFIG_DIFFTEST_NONBLOCK
`ifdef PALLADIUM
initial $ixc_ctrl("gfifo", "simv_nstep");
`endif // PALLADIUM
`endif // CONFIG_DIFFTEST_NONBLOCK

reg [63:0] fetch_cycles;
initial fetch_cycles = 4999;
`ifdef PALLADIUM
initial $ixc_ctrl("sfifo", "set_deferred_result");
`endif // PALLADIUM

reg [63:0] fetch_timer;
always @(posedge clock) begin
if (reset) begin
simv_result <= 1'b0;
fetch_timer <= 64'b0;
end
else begin
if (fetch_timer == fetch_cycles) begin
fetch_timer <= 1'b0;
if (simv_result_fetch()) begin
simv_result <= 1'b1;
end
end
else begin
fetch_timer <= fetch_timer + 64'b1;
end

if ((~simv_result) && (|step)) begin
simv_nstep(step);
end
if (!reset && !simv_result && step != 0) begin
simv_nstep(step);
end
end

Expand Down

0 comments on commit b1ff113

Please sign in to comment.