21 #ifndef BENCHMARK_CYCLECLOCK_H_
22 #define BENCHMARK_CYCLECLOCK_H_
26 #include "benchmark/benchmark.h"
29 #if defined(BENCHMARK_OS_MACOSX)
30 #include <mach/mach_time.h>
39 #if defined(COMPILER_MSVC) && !defined(_M_IX86)
41 #pragma intrinsic(__rdtsc)
44 #ifndef BENCHMARK_OS_WINDOWS
49 #ifdef BENCHMARK_OS_EMSCRIPTEN
50 #include <emscripten.h>
59 namespace cycleclock {
62 #if defined(BENCHMARK_OS_MACOSX)
72 return mach_absolute_time();
73 #elif defined(BENCHMARK_OS_EMSCRIPTEN)
76 return static_cast<int64_t>(emscripten_get_now() * 1
e+6);
77 #elif defined(__i386__)
79 __asm__
volatile(
"rdtsc" :
"=A"(
ret));
81 #elif defined(__x86_64__) || defined(__amd64__)
83 __asm__
volatile(
"rdtsc" :
"=a"(low),
"=d"(high));
84 return (high << 32) | low;
85 #elif defined(__powerpc__) || defined(__ppc__)
88 asm(
"mftbu %0" :
"=r"(tbu0));
89 asm(
"mftb %0" :
"=r"(tbl));
90 asm(
"mftbu %0" :
"=r"(tbu1));
91 tbl &= -
static_cast<int64_t>(tbu0 == tbu1);
93 return (tbu1 << 32) | tbl;
94 #elif defined(__sparc__)
96 asm(
".byte 0x83, 0x41, 0x00, 0x00");
97 asm(
"mov %%g1, %0" :
"=r"(
tick));
99 #elif defined(__ia64__)
101 asm(
"mov %0 = ar.itc" :
"=r"(itc));
103 #elif defined(COMPILER_MSVC) && defined(_M_IX86)
109 #elif defined(COMPILER_MSVC)
111 #elif defined(BENCHMARK_OS_NACL)
124 struct timespec ts = { 0, 0 };
125 clock_gettime(CLOCK_MONOTONIC, &ts);
126 return static_cast<int64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec;
127 #elif defined(__aarch64__)
133 asm volatile(
"mrs %0, cntvct_el0" :
"=r"(virtual_timer_value));
134 return virtual_timer_value;
135 #elif defined(__ARM_ARCH)
138 #if (__ARM_ARCH >= 6)
143 asm volatile(
"mrc p15, 0, %0, c9, c14, 0" :
"=r"(pmuseren));
145 asm volatile(
"mrc p15, 0, %0, c9, c12, 1" :
"=r"(pmcntenset));
146 if (pmcntenset & 0x80000000ul) {
147 asm volatile(
"mrc p15, 0, %0, c9, c13, 0" :
"=r"(pmccntr));
149 return static_cast<int64_t>(pmccntr) * 64;
154 gettimeofday(&tv,
nullptr);
155 return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
156 #elif defined(__mips__)
160 gettimeofday(&tv,
nullptr);
161 return static_cast<int64_t>(tv.tv_sec) * 1000000 + tv.tv_usec;
166 #
error You need
to define CycleTimer
for your
OS and CPU
172 #endif // BENCHMARK_CYCLECLOCK_H_