File indexing completed on 2024-07-30 05:19:43
0001 #ifndef RDPSCP_H
0002 #define RDPSCP_H
0003
0004 #if !defined(__arm__) && !defined(__aarch64__) && !defined(__powerpc64__) && !defined(__PPC64__) && \
0005 !defined(__powerpc__) && !defined(__riscv)
0006 #include <x86intrin.h>
0007 #include <cpuid.h>
0008 #ifdef __clang__
0009 bool has_rdtscp() { return true; }
0010
0011 inline uint64_t rdtsc() {
0012 uint32_t lo, hi;
0013
0014 __asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
0015 return (uint64_t)hi << 32 | lo;
0016 }
0017 #else
0018
0019 #ifndef bit_RDTSCP
0020 #define bit_RDTSCP (1 << 27)
0021 #endif
0022 namespace {
0023 inline bool has_rdtscp() {
0024 unsigned int eax, ebx, ecx, edx;
0025 if (__get_cpuid(0x80000001, &eax, &ebx, &ecx, &edx))
0026 return (edx & bit_RDTSCP) != 0;
0027 else
0028 return false;
0029 }
0030 unsigned int rdtscp_val = 0;
0031 inline unsigned long long rdtsc() { return __rdtscp(&rdtscp_val); }
0032 }
0033 #endif
0034 #else
0035 namespace {
0036 inline bool has_rdtscp() { return false; }
0037 inline unsigned long long rdtsc() { return 0; }
0038 }
0039 #endif
0040
0041 #endif