82 #ifndef QBENCHLIB_CYCLE_H 83 #define QBENCHLIB_CYCLE_H 85 #if TIME_WITH_SYS_TIME 86 # include <sys/time.h> 90 # include <sys/time.h> 96 #define INLINE_ELAPSED(INL) static INL double elapsed(CycleCounterTicks t1, CycleCounterTicks t0) \ 98 return (double)(t1 - t0); \ 103 #if defined(HAVE_GETHRTIME) && defined(HAVE_HRTIME_T) && !defined(HAVE_TICK_COUNTER) 104 typedef hrtime_t CycleCounterTicks;
106 #define getticks gethrtime 110 #define HAVE_TICK_COUNTER 115 #if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER) 116 typedef timebasestruct_t CycleCounterTicks;
118 static inline CycleCounterTicks
getticks(
void)
121 read_real_time(&t, TIMEBASE_SZ);
125 static inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0)
127 time_base_to_time(&t1, TIMEBASE_SZ);
128 time_base_to_time(&t0, TIMEBASE_SZ);
129 return ((t1.tb_high - t0.tb_high) * 1e9 + (t1.tb_low - t0.tb_low));
132 #define HAVE_TICK_COUNTER 139 #if ((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh))) && !defined(HAVE_TICK_COUNTER) 140 typedef unsigned long long CycleCounterTicks;
142 static __inline__ CycleCounterTicks
getticks(
void)
144 unsigned int tbl, tbu0, tbu1;
147 __asm__ __volatile__ (
"mftbu %0" :
"=r"(tbu0));
148 __asm__ __volatile__ (
"mftb %0" :
"=r"(tbl));
149 __asm__ __volatile__ (
"mftbu %0" :
"=r"(tbu1));
150 }
while (tbu0 != tbu1);
152 return (((
unsigned long long)tbu0) << 32) | tbl;
157 #define HAVE_TICK_COUNTER 162 #if defined(HAVE_MACH_ABSOLUTE_TIME) && defined(HAVE_MACH_MACH_TIME_H) && !defined(HAVE_TICK_COUNTER) 163 #include <mach/mach_time.h> 164 typedef uint64_t CycleCounterTicks;
165 #define getticks mach_absolute_time 167 #define HAVE_TICK_COUNTER 174 #if (defined(__GNUC__) || defined(__ICC)) && defined(__i386__) && !defined(HAVE_TICK_COUNTER) 175 typedef unsigned long long CycleCounterTicks;
177 static __inline__ CycleCounterTicks
getticks(
void)
179 CycleCounterTicks ret;
181 __asm__ __volatile__(
"rdtsc":
"=A" (ret));
188 #define HAVE_TICK_COUNTER 189 #define TIME_MIN 5000.0 193 #if defined(_MSC_VER) 194 #if _MSC_VER >= 1200 && (_M_IX86 >= 500 || (defined(_WIN32_WCE) && defined(_X86_))) && !defined(HAVE_TICK_COUNTER) 196 typedef LARGE_INTEGER CycleCounterTicks;
197 #define RDTSC __asm __emit 0fh __asm __emit 031h 199 static __inline CycleCounterTicks
getticks(
void)
201 CycleCounterTicks retval;
205 mov retval.HighPart, edx
206 mov retval.LowPart, eax
211 static __inline
double elapsed(CycleCounterTicks t1, CycleCounterTicks t0)
213 return (
double)(t1.QuadPart - t0.QuadPart);
216 #define HAVE_TICK_COUNTER 217 #define TIME_MIN 5000.0 221 #if _MSC_VER >= 1400 && defined(_WIN32_WCE) && !defined(HAVE_TICK_COUNTER) 223 typedef DWORD CycleCounterTicks;
225 static __inline CycleCounterTicks
getticks(
void)
227 return GetTickCount();
230 static __inline
double elapsed(CycleCounterTicks t1, CycleCounterTicks t0)
232 return (
double)(t1 - t0);
235 #define HAVE_TICK_COUNTER 236 #define TIME_MIN 5000.0 243 #if (defined(__GNUC__) || defined(__ICC)) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER) 244 typedef unsigned long long CycleCounterTicks;
246 static __inline__ CycleCounterTicks
getticks(
void)
249 asm volatile(
"rdtsc" :
"=a" (
a),
"=d" (d));
250 return ((CycleCounterTicks)
a) | (((CycleCounterTicks)
d) << 32);
255 #define HAVE_TICK_COUNTER 261 #if defined(__PGI) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER) 262 typedef unsigned long long CycleCounterTicks;
263 static CycleCounterTicks
getticks(
void)
265 asm(
" rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; ");
268 #define HAVE_TICK_COUNTER 272 #if _MSC_VER >= 1400 && (defined(_M_AMD64) || defined(_M_X64)) && !defined(HAVE_TICK_COUNTER) 275 typedef unsigned __int64 CycleCounterTicks;
277 #define getticks __rdtsc 281 #define HAVE_TICK_COUNTER 290 #if (defined(__EDG_VERSION) || defined(__ECC)) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER) 291 typedef unsigned long CycleCounterTicks;
292 #include <ia64intrin.h> 294 static __inline__ CycleCounterTicks
getticks(
void)
296 return __getReg(_IA64_REG_AR_ITC);
301 #define HAVE_TICK_COUNTER 305 #if defined(__GNUC__) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER) 306 typedef unsigned long CycleCounterTicks;
308 static __inline__ CycleCounterTicks
getticks(
void)
310 CycleCounterTicks ret;
312 __asm__ __volatile__ (
"mov %0=ar.itc" :
"=r"(ret));
318 #define HAVE_TICK_COUNTER 322 #if defined(__hpux) && defined(__ia64) && !defined(HAVE_TICK_COUNTER) 323 #include <machine/sys/inline.h> 324 typedef unsigned long CycleCounterTicks;
326 static inline CycleCounterTicks
getticks(
void)
328 CycleCounterTicks ret;
330 ret = _Asm_mov_from_ar (_AREG_ITC);
336 #define HAVE_TICK_COUNTER 340 #if defined(_MSC_VER) && defined(_M_IA64) && !defined(HAVE_TICK_COUNTER) 341 typedef unsigned __int64 CycleCounterTicks;
346 ticks __getReg(
int whichReg);
347 #pragma intrinsic(__getReg) 349 static __inline CycleCounterTicks
getticks(
void)
351 volatile CycleCounterTicks temp;
352 temp = __getReg(3116);
356 #define HAVE_TICK_COUNTER 363 #if (defined(__hppa__) || defined(__hppa)) && !defined(HAVE_TICK_COUNTER) 364 typedef unsigned long CycleCounterTicks;
367 static __inline__ CycleCounterTicks
getticks(
void)
369 CycleCounterTicks ret;
371 __asm__ __volatile__(
"mfctl 16, %0":
"=r" (ret));
378 #define HAVE_TICK_COUNTER 380 # elif 0 // Doesn't compile 381 # include <machine/inline.h> 382 static inline unsigned long getticks(
void)
384 register CycleCounterTicks ret;
394 #if defined(__GNUC__) && defined(__s390__) && !defined(HAVE_TICK_COUNTER) 395 typedef unsigned long long CycleCounterTicks;
397 static __inline__ CycleCounterTicks
getticks(
void)
399 CycleCounterTicks cycles;
400 __asm__(
"stck 0(%0)" : :
"a" (&(cycles)) :
"memory",
"cc");
406 #define HAVE_TICK_COUNTER 409 #if defined(__GNUC__) && defined(__alpha__) && !defined(HAVE_TICK_COUNTER) 414 typedef unsigned int CycleCounterTicks;
416 static __inline__ CycleCounterTicks
getticks(
void)
419 __asm__ __volatile__ (
"rpcc %0" :
"=r"(cc));
420 return (cc & 0xFFFFFFFF);
425 #define HAVE_TICK_COUNTER 429 #if defined(__GNUC__) && defined(__sparc_v9__) && !defined(HAVE_TICK_COUNTER) 430 typedef unsigned long CycleCounterTicks;
432 static __inline__ CycleCounterTicks
getticks(
void)
434 CycleCounterTicks ret;
435 __asm__ __volatile__(
"rd %%tick, %0" :
"=r" (ret));
441 #define HAVE_TICK_COUNTER 445 #if (defined(__DECC) || defined(__DECCXX)) && defined(__alpha) && defined(HAVE_C_ASM_H) && !defined(HAVE_TICK_COUNTER) 447 typedef unsigned int CycleCounterTicks;
449 static __inline CycleCounterTicks
getticks(
void)
452 cc =
asm(
"rpcc %v0");
453 return (cc & 0xFFFFFFFF);
458 #define HAVE_TICK_COUNTER 462 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) && !defined(HAVE_TICK_COUNTER) 463 typedef struct timespec CycleCounterTicks;
465 static inline CycleCounterTicks
getticks(
void)
468 clock_gettime(CLOCK_SGI_CYCLE, &t);
472 static inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0)
474 return (
double)(t1.tv_sec - t0.tv_sec) * 1.0E9 +
475 (
double)(t1.tv_nsec - t0.tv_nsec);
477 #define HAVE_TICK_COUNTER 482 #if defined(HAVE__RTC) && !defined(HAVE_TICK_COUNTER) 483 #ifdef HAVE_INTRINSICS_H 484 # include <intrinsics.h> 487 typedef long long CycleCounterTicks;
489 #define getticks _rtc 493 #define HAVE_TICK_COUNTER 498 #if defined(__SYMBIAN32__) && !defined(HAVE_TICK_COUNTER) 501 typedef TUint32 CycleCounterTicks;
503 static inline CycleCounterTicks
getticks(
void)
505 return User::FastCounter();
510 #define HAVE_TICK_COUNTER 513 #endif // QBENCHLIB_CYCLE_H
#define INLINE_ELAPSED(INL)
static double elapsed(qint64 after, qint64 before)
long ASN1_INTEGER_get ASN1_INTEGER * a