Skip to content

Commit

Permalink
Support non-Darwin, non-Linux, aarch64 platforms
Browse files Browse the repository at this point in the history
We can read the cntvct_el0 register to observe the CPU clock. It is a
single instruction and has barely any overhead.
  • Loading branch information
depressed-pho committed May 12, 2024
1 parent 51e21db commit acf1cc4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions criterion-measurement/cbits/cycles.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ StgWord64 criterion_rdtsc(void)
return mach_absolute_time();
}

#elif aarch64_HOST_ARCH

StgWord64 criterion_rdtsc(void)
{
StgWord64 ret;
__asm__ __volatile__ ("mrs %0, cntvct_el0" : "=r"(ret));
return ret;
}

#elif x86_64_HOST_ARCH || i386_HOST_ARCH

StgWord64 criterion_rdtsc(void)
Expand Down

0 comments on commit acf1cc4

Please sign in to comment.