| 47 | } |
| 48 | |
| 49 | static inline int64_t GetPerformanceCounter() noexcept |
| 50 | { |
| 51 | // Read the hardware time stamp counter when available. |
| 52 | // See https://en.wikipedia.org/wiki/Time_Stamp_Counter for more information. |
| 53 | #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) |
| 54 | return __rdtsc(); |
| 55 | #elif !defined(_MSC_VER) && defined(__i386__) |
| 56 | uint64_t r = 0; |
| 57 | __asm__ volatile ("rdtsc" : "=A"(r)); // Constrain the r variable to the eax:edx pair. |
| 58 | return r; |
| 59 | #elif !defined(_MSC_VER) && (defined(__x86_64__) || defined(__amd64__)) |
| 60 | uint64_t r1 = 0, r2 = 0; |
| 61 | __asm__ volatile ("rdtsc" : "=a"(r1), "=d"(r2)); // Constrain r1 to rax and r2 to rdx. |
| 62 | return (r2 << 32) | r1; |
| 63 | #else |
| 64 | // Fall back to using C++11 clock (usually microsecond or nanosecond precision) |
| 65 | return std::chrono::high_resolution_clock::now().time_since_epoch().count(); |
| 66 | #endif |
| 67 | } |
| 68 | |
| 69 | #ifdef HAVE_GETCPUID |
| 70 | static bool g_rdrand_supported = false; |
no test coverage detected