#include <stdint.h>
#if defined(_WIN32) || defined(_WIN64)
#include <intrin.h>
#pragma intrinsic(__rdtsc)
#endif
uint64_t get_rdtsc() {
#if defined(_WIN32) || defined(_WIN64)
return
__rdtsc();
#elif defined(__GNUC__) || defined(__clang__)
uint32_t low, high;
__asm__
volatile
(
"rdtsc"
:
"=a"
(low),
"=d"
(high)
);
return
((uint64_t)(high) << 32) | low;
#else
#error "Unsupported platform"
#endif
}
uint64_t hash64(uint64_t val) {
return
(val * 0x61c8864680b583ebull);
}
uint64_t rdtsc_rand64() {
uint64_t rdtsc_val = get_rdtsc();
uint64_t ret = hash64(rdtsc_val);
return
ret;
}