Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DPIC-function to return deferred result #250

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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