MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetPerformanceCounter

Function GetPerformanceCounter

src/random.cpp:60–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60inline int64_t GetPerformanceCounter() noexcept
61{
62 // Read the hardware time stamp counter when available.
63 // See https://en.wikipedia.org/wiki/Time_Stamp_Counter for more information.
64#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
65 return __rdtsc();
66#elif !defined(_MSC_VER) && defined(__i386__)
67 uint64_t r = 0;
68 __asm__ volatile ("rdtsc" : "=A"(r)); // Constrain the r variable to the eax:edx pair.
69 return r;
70#elif !defined(_MSC_VER) && (defined(__x86_64__) || defined(__amd64__))
71 uint64_t r1 = 0, r2 = 0;
72 __asm__ volatile ("rdtsc" : "=a"(r1), "=d"(r2)); // Constrain r1 to rax and r2 to rdx.
73 return (r2 << 32) | r1;
74#else
75 // Fall back to using standard library clock (usually microsecond or nanosecond precision)
76 return std::chrono::high_resolution_clock::now().time_since_epoch().count();
77#endif
78}
79
80#ifdef HAVE_GETCPUID
81bool g_rdrand_supported = false;

Callers 4

StrengthenFunction · 0.85
RNGStateClass · 0.85
SeedTimestampFunction · 0.85
Random_SanityCheckFunction · 0.85

Calls 1

countMethod · 0.80

Tested by

no test coverage detected