Skip to content

Commit

Permalink
target/common: Scale verilator testbench time precision as picoseconds (
Browse files Browse the repository at this point in the history
  • Loading branch information
Raragyay authored Nov 6, 2023
1 parent 8a020de commit 252ee2c
Showing 1 changed file with 7 additions and 2 deletions.
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

0 comments on commit 252ee2c

Please sign in to comment.