86#define INLINE_ELAPSED(INL) static INL double elapsed(ticks t1, ticks t0) \
88 return (double)t1 - (double)t0; \
93#if defined(HAVE_GETHRTIME) && defined(HAVE_HRTIME_T) && !defined(HAVE_TICK_COUNTER)
94typedef hrtime_t ticks;
96#define getticks gethrtime
100#define HAVE_TICK_COUNTER
105#if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER)
106typedef timebasestruct_t ticks;
108static __inline ticks getticks(
void)
111 read_real_time(&t, TIMEBASE_SZ);
115static __inline
double elapsed(ticks t1, ticks t0)
117 time_base_to_time(&t1, TIMEBASE_SZ);
118 time_base_to_time(&t0, TIMEBASE_SZ);
119 return (((
double)t1.tb_high - (
double)t0.tb_high) * 1.0e9 +
120 ((
double)t1.tb_low - (
double)t0.tb_low));
123#define HAVE_TICK_COUNTER
130#if ((((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh)))) || (defined(__IBM_GCC_ASM) && (defined(__powerpc__) || defined(__ppc__)))) && !defined(HAVE_TICK_COUNTER)
131typedef unsigned long long ticks;
133static __inline__ ticks getticks(
void)
135 unsigned int tbl, tbu0, tbu1;
138 __asm__ __volatile__ (
"mftbu %0" :
"=r"(tbu0));
139 __asm__ __volatile__ (
"mftb %0" :
"=r"(tbl));
140 __asm__ __volatile__ (
"mftbu %0" :
"=r"(tbu1));
141 }
while (tbu0 != tbu1);
143 return (((
unsigned long long)tbu0) << 32) | tbl;
146INLINE_ELAPSED(__inline__)
148#define HAVE_TICK_COUNTER
153#if defined(HAVE_MACH_ABSOLUTE_TIME) && defined(HAVE_MACH_MACH_TIME_H) && !defined(HAVE_TICK_COUNTER)
154#include <mach/mach_time.h>
155typedef uint64_t ticks;
156#define getticks mach_absolute_time
157INLINE_ELAPSED(__inline__)
158#define HAVE_TICK_COUNTER
165#if (defined(__GNUC__) || defined(__ICC)) && defined(__i386__) && !defined(HAVE_TICK_COUNTER)
166typedef unsigned long long ticks;
168static __inline__ ticks getticks(
void)
172 __asm__ __volatile__(
"rdtsc":
"=A" (ret));
177INLINE_ELAPSED(__inline__)
179#define HAVE_TICK_COUNTER
180#define TIME_MIN 5000.0
184#if defined(_MSC_VER) && _MSC_VER >= 1200 && _M_IX86 >= 500 && !defined(HAVE_TICK_COUNTER)
186typedef LARGE_INTEGER ticks;
187#define RDTSC __asm __emit 0fh __asm __emit 031h
189static __inline ticks getticks(
void)
195 mov retval.HighPart, edx
196 mov retval.LowPart, eax
201static __inline
double elapsed(ticks t1, ticks t0)
203 return (
double)t1.QuadPart - (double)t0.QuadPart;
206#define HAVE_TICK_COUNTER
207#define TIME_MIN 5000.0
214#if (defined(__GNUC__) || defined(__ICC) || defined(__SUNPRO_C)) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
215typedef unsigned long long ticks;
217static __inline__ ticks getticks(
void)
220 asm volatile(
"rdtsc" :
"=a" (a),
"=d" (d));
221 return ((ticks)a) | (((ticks)d) << 32);
224INLINE_ELAPSED(__inline__)
226#define HAVE_TICK_COUNTER
227#define TIME_MIN 5000.0
233#if defined(__PGI) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
234typedef unsigned long long ticks;
235static ticks getticks(
void)
237 asm(
" rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; ");
239INLINE_ELAPSED(__inline__)
240#define HAVE_TICK_COUNTER
241#define TIME_MIN 5000.0
245#if defined(_MSC_VER) && _MSC_VER >= 1400 && (defined(_M_AMD64) || defined(_M_X64)) && !defined(HAVE_TICK_COUNTER)
248#pragma intrinsic(__rdtsc)
249typedef unsigned __int64 ticks;
250#define getticks __rdtsc
251INLINE_ELAPSED(__inline)
253#define HAVE_TICK_COUNTER
254#define TIME_MIN 5000.0
263#if (defined(__EDG_VERSION) || defined(__ECC)) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
264typedef unsigned long ticks;
265#include <ia64intrin.h>
267static __inline__ ticks getticks(
void)
269 return __getReg(_IA64_REG_AR_ITC);
272INLINE_ELAPSED(__inline__)
274#define HAVE_TICK_COUNTER
278#if defined(__GNUC__) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
279typedef unsigned long ticks;
281static __inline__ ticks getticks(
void)
285 __asm__ __volatile__ (
"mov %0=ar.itc" :
"=r"(ret));
289INLINE_ELAPSED(__inline__)
291#define HAVE_TICK_COUNTER
295#if defined(__hpux) && defined(__ia64) && !defined(HAVE_TICK_COUNTER)
296#include <machine/sys/inline.h>
297typedef unsigned long ticks;
299static inline ticks getticks(
void)
303 ret = _Asm_mov_from_ar (_AREG_ITC);
307INLINE_ELAPSED(
inline)
309#define HAVE_TICK_COUNTER
313#if defined(_MSC_VER) && defined(_M_IA64) && !defined(HAVE_TICK_COUNTER)
314typedef unsigned __int64 ticks;
319ticks __getReg(
int whichReg);
320#pragma intrinsic(__getReg)
322static __inline ticks getticks(
void)
325 temp = __getReg(3116);
329INLINE_ELAPSED(
inline)
331#define HAVE_TICK_COUNTER
338#if (defined(__hppa__) || defined(__hppa)) && !defined(HAVE_TICK_COUNTER)
339typedef unsigned long ticks;
342static __inline__ ticks getticks(
void)
346 __asm__ __volatile__(
"mfctl 16, %0":
"=r" (ret));
351# include <machine/inline.h>
352static inline unsigned long getticks(
void)
360INLINE_ELAPSED(
inline)
362#define HAVE_TICK_COUNTER
367#if defined(__GNUC__) && defined(__s390__) && !defined(HAVE_TICK_COUNTER)
368typedef unsigned long long ticks;
370static __inline__ ticks getticks(
void)
373 __asm__(
"stck 0(%0)" : :
"a" (&(cycles)) :
"memory",
"cc");
377INLINE_ELAPSED(__inline__)
379#define HAVE_TICK_COUNTER
382#if defined(__GNUC__) && defined(__alpha__) && !defined(HAVE_TICK_COUNTER)
387typedef unsigned int ticks;
389static __inline__ ticks getticks(
void)
392 __asm__ __volatile__ (
"rpcc %0" :
"=r"(cc));
393 return (cc & 0xFFFFFFFF);
396INLINE_ELAPSED(__inline__)
398#define HAVE_TICK_COUNTER
402#if defined(__GNUC__) && defined(__sparc_v9__) && !defined(HAVE_TICK_COUNTER)
403typedef unsigned long ticks;
405static __inline__ ticks getticks(
void)
408 __asm__ __volatile__(
"rd %%tick, %0" :
"=r" (ret));
412INLINE_ELAPSED(__inline__)
414#define HAVE_TICK_COUNTER
418#if (defined(__DECC) || defined(__DECCXX)) && defined(__alpha) && defined(HAVE_C_ASM_H) && !defined(HAVE_TICK_COUNTER)
420typedef unsigned int ticks;
422static __inline ticks getticks(
void)
425 cc =
asm(
"rpcc %v0");
426 return (cc & 0xFFFFFFFF);
429INLINE_ELAPSED(__inline)
431#define HAVE_TICK_COUNTER
435#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) && !defined(HAVE_TICK_COUNTER)
436typedef struct timespec ticks;
438static inline ticks getticks(
void)
441 clock_gettime(CLOCK_SGI_CYCLE, &t);
445static inline double elapsed(ticks t1, ticks t0)
447 return ((
double)t1.tv_sec - (
double)t0.tv_sec) * 1.0E9 +
448 ((double)t1.tv_nsec - (
double)t0.tv_nsec);
450#define HAVE_TICK_COUNTER
455#if defined(HAVE__RTC) && !defined(HAVE_TICK_COUNTER)
456#ifdef HAVE_INTRINSICS_H
457# include <intrinsics.h>
460typedef long long ticks;
464INLINE_ELAPSED(
inline)
466#define HAVE_TICK_COUNTER
471#if defined(HAVE_MIPS_ZBUS_TIMER) && HAVE_MIPS_ZBUS_TIMER
472#if defined(__mips__) && !defined(HAVE_TICK_COUNTER)
477typedef uint64_t ticks;
479static inline ticks getticks(
void)
481 static uint64_t* addr = 0;
485 uint32_t rq_addr = 0x10030000;
489 pgsize = getpagesize();
490 fd = open (
"/dev/mem", O_RDONLY | O_SYNC, 0);
495 addr = mmap(0, pgsize, PROT_READ, MAP_SHARED, fd, rq_addr);
497 if (addr == (uint64_t *)-1) {
506INLINE_ELAPSED(
inline)
508#define HAVE_TICK_COUNTER