15 #undef RDTSC_AVAILABLE 19 #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) && !defined(RDTSC_AVAILABLE) 25 #define RDTSC_AVAILABLE 29 #if defined (__WATCOMC__) && !defined(RDTSC_AVAILABLE) 31 # pragma aux ottd_rdtsc = 0x0F 0x31 value [edx eax] parm nomemory modify exact [edx eax] nomemory; 32 # define RDTSC_AVAILABLE 36 #if (defined(__i386__) || defined(__x86_64__)) && !defined(RDTSC_AVAILABLE) 40 __asm__ __volatile__ (
"rdtsc" :
"=a" (low),
"=d" (high));
41 return ((uint64)high << 32) | low;
43 # define RDTSC_AVAILABLE 47 #if (defined(__POWERPC__) || defined(__powerpc__)) && !defined(RDTSC_AVAILABLE) 50 uint32 high = 0, high2 = 0, low;
61 :
"=r" (high),
"=r" (low),
"=r" (high2)
62 :
"0" (high),
"2" (high2)
64 return ((uint64)high << 32) | low;
66 # define RDTSC_AVAILABLE 71 #if !defined(RDTSC_AVAILABLE) 72 #warning "(non-fatal) No support for rdtsc(), you won't be able to profile with TIC/TOC" 88 #if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) 93 #elif defined(__x86_64__) || defined(__i386) 96 #if defined(__i386) && defined(__PIC__) 103 __asm__ __volatile__ (
104 "xchgl %%ebx, %1 \n\t" 106 "xchgl %%ebx, %1 \n\t" 107 :
"=a" (info[0]),
"=r" (info[1]),
"=c" (info[2]),
"=d" (info[3])
114 __asm__ __volatile__ (
116 :
"=a" (info[0]),
"=b" (info[1]),
"=c" (info[2]),
"=d" (info[3])
124 info[0] = info[1] = info[2] = info[3] = 0;
130 int cpu_info[4] = {-1};
132 uint max_info_type = cpu_info[0];
133 if (max_info_type < type)
return false;
136 return HasBit(cpu_info[index], bit);
Functions related to bit mathematics.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
bool HasCPUIDFlag(uint type, uint index, uint bit)
Check whether the current CPU has the given flag.
void ottd_cpuid(int info[4], int type)
Definitions for CPU detection:
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
uint64 ottd_rdtsc()
Get the tick counter from the CPU (high precision timing).