Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-07-30 05:19:43

0001 #ifndef RDPSCP_H
0002 #define RDPSCP_H
0003 // performance test
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 /** CPU cycles since processor startup */
0011 inline uint64_t rdtsc() {
0012   uint32_t lo, hi;
0013   /* We cannot use "=A", since this would use %rax on x86_64 */
0014   __asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
0015   return (uint64_t)hi << 32 | lo;
0016 }
0017 #else
0018 // CPUID, EAX = 0x80000001, EDX values
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 }  // namespace
0033 #endif
0034 #else   // !defined(__arm__) && !defined(__aarch64__)
0035 namespace {
0036   inline bool has_rdtscp() { return false; }
0037   inline unsigned long long rdtsc() { return 0; }
0038 }  // namespace
0039 #endif  // !defined(__arm__) && !defined(__aarch64__)
0040 
0041 #endif