diff --git a/target/common/test/verilator_lib.cc b/target/common/test/verilator_lib.cc index 63ac66d5b..3e1ae89e1 100644 --- a/target/common/test/verilator_lib.cc +++ b/target/common/test/verilator_lib.cc @@ -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 + +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 @@ -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) {