17 #undef RDTSC_AVAILABLE 21 #if defined(_MSC_VER) && !defined(RDTSC_AVAILABLE) && !defined(WINCE) 27 #define RDTSC_AVAILABLE 31 #if defined (__WATCOMC__) && !defined(RDTSC_AVAILABLE) 33 # pragma aux ottd_rdtsc = 0x0F 0x31 value [edx eax] parm nomemory modify exact [edx eax] nomemory; 34 # define RDTSC_AVAILABLE 38 #if (defined(__i386__) || defined(__x86_64__)) && !defined(__DJGPP__) && !defined(RDTSC_AVAILABLE) 42 __asm__ __volatile__ (
"rdtsc" :
"=a" (low),
"=d" (high));
43 return ((uint64)high << 32) | low;
45 # define RDTSC_AVAILABLE 49 #if (defined(__POWERPC__) || defined(__powerpc__)) && !defined(RDTSC_AVAILABLE) 52 uint32 high = 0, high2 = 0, low;
63 :
"=r" (high),
"=r" (low),
"=r" (high2)
64 :
"0" (high),
"2" (high2)
66 return ((uint64)high << 32) | low;
68 # define RDTSC_AVAILABLE 73 #if !defined(RDTSC_AVAILABLE) 75 # if !defined(_MSC_VER) 76 #warning "(non-fatal) No support for rdtsc(), you won't be able to profile with TIC/TOC" 98 #elif defined(__x86_64__) || defined(__i386) 101 #if defined(__i386) && defined(__PIC__) 108 __asm__ __volatile__ (
109 "xchgl %%ebx, %1 \n\t" 111 "xchgl %%ebx, %1 \n\t" 112 :
"=a" (info[0]),
"=r" (info[1]),
"=c" (info[2]),
"=d" (info[3])
119 __asm__ __volatile__ (
121 :
"=a" (info[0]),
"=b" (info[1]),
"=c" (info[2]),
"=d" (info[3])
129 info[0] = info[1] = info[2] = info[3] = 0;
135 int cpu_info[4] = {-1};
137 uint max_info_type = cpu_info[0];
138 if (max_info_type < type)
return false;
141 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).