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

target/common: Scale verilator testbench time precision as picoseconds #58

Merged
merged 4 commits into from
Nov 6, 2023
Merged
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
9 changes: 7 additions & 2 deletions target/common/test/verilator_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ namespace sim {

// Number of cycles between HTIF checks.
const int HTIFTimeInterval = 200;

// We want to return timestamp in picosecond accuracy, assuming that one cycle
// takes 1ns Since 1 cycle takes 2 sim::TIME increments, scale by 500 to get
// time = cycle * 1000 + <some constant>
const int TIME_CYCLES_TO_TIMESTAMP = 500;
void sim_thread_main(void *arg) { ((Sim *)arg)->main(); }

// Sim time.
int TIME = 0;
vluint64_t TIME = 0;

Sim::Sim(int argc, char **argv) : htif_t(argc, argv), ipc(argc, argv) {
// Search arguments for `--vcd` flag and enable waves if requested
Expand Down Expand Up @@ -78,7 +83,7 @@ void Sim::main() {
} // namespace sim

// Verilator callback to get the current time.
double sc_time_stamp() { return sim::TIME * 1e-9; }
double sc_time_stamp() { return sim::TIME * sim::TIME_CYCLES_TO_TIMESTAMP; }

// DPI calls.
void tb_memory_read(long long addr, int len, const svOpenArrayHandle data) {
Expand Down
Loading