82 # include <sys/time.h>
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)
94 typedef hrtime_t ticks;
96 #define getticks gethrtime
98 INLINE_ELAPSED(
inline)
100 #define HAVE_TICK_COUNTER
105 #if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER)
106 typedef timebasestruct_t ticks;
108 static __inline ticks getticks(
void)
111 read_real_time(&t, TIMEBASE_SZ);
115 static __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)
131 typedef unsigned long long ticks;
133 static __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;
146 INLINE_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>
155 typedef uint64_t ticks;
156 #define getticks mach_absolute_time
157 INLINE_ELAPSED(__inline__)
158 #define HAVE_TICK_COUNTER
165 #if (defined(__GNUC__) || defined(__ICC)) && defined(__i386__) && !defined(HAVE_TICK_COUNTER)
166 typedef unsigned long long ticks;
168 static __inline__ ticks getticks(
void)
172 __asm__ __volatile__(
"rdtsc":
"=A" (ret));
177 INLINE_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)
186 typedef LARGE_INTEGER ticks;
187 #define RDTSC __asm __emit 0fh __asm __emit 031h
189 static __inline ticks getticks(
void)
195 mov retval.HighPart, edx
196 mov retval.LowPart, eax
201 static __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)
215 typedef unsigned long long ticks;
217 static __inline__ ticks getticks(
void)
220 asm volatile(
"rdtsc" :
"=a" (a),
"=d" (d));
221 return ((ticks)a) | (((ticks)d) << 32);
224 INLINE_ELAPSED(__inline__)
226 #define HAVE_TICK_COUNTER
227 #define TIME_MIN 5000.0
233 #if defined(__PGI) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
234 typedef unsigned long long ticks;
235 static ticks getticks(
void)
237 asm(
" rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; ");
239 INLINE_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)
249 typedef unsigned __int64 ticks;
250 #define getticks __rdtsc
251 INLINE_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)
264 typedef unsigned long ticks;
265 #include <ia64intrin.h>
267 static __inline__ ticks getticks(
void)
269 return __getReg(_IA64_REG_AR_ITC);
272 INLINE_ELAPSED(__inline__)
274 #define HAVE_TICK_COUNTER
278 #if defined(__GNUC__) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
279 typedef unsigned long ticks;
281 static __inline__ ticks getticks(
void)
285 __asm__ __volatile__ (
"mov %0=ar.itc" :
"=r"(ret));
289 INLINE_ELAPSED(__inline__)
291 #define HAVE_TICK_COUNTER
295 #if defined(__hpux) && defined(__ia64) && !defined(HAVE_TICK_COUNTER)
296 #include <machine/sys/inline.h>
297 typedef unsigned long ticks;
299 static inline ticks getticks(
void)
303 ret = _Asm_mov_from_ar (_AREG_ITC);
307 INLINE_ELAPSED(
inline)
309 #define HAVE_TICK_COUNTER
313 #if defined(_MSC_VER) && defined(_M_IA64) && !defined(HAVE_TICK_COUNTER)
314 typedef unsigned __int64 ticks;
319 ticks __getReg(
int whichReg);
320 #pragma intrinsic(__getReg)
322 static __inline ticks getticks(
void)
325 temp = __getReg(3116);
329 INLINE_ELAPSED(
inline)
331 #define HAVE_TICK_COUNTER
338 #if (defined(__hppa__) || defined(__hppa)) && !defined(HAVE_TICK_COUNTER)
339 typedef unsigned long ticks;
342 static __inline__ ticks getticks(
void)
346 __asm__ __volatile__(
"mfctl 16, %0":
"=r" (ret));
351 # include <machine/inline.h>
352 static inline unsigned long getticks(
void)
360 INLINE_ELAPSED(
inline)
362 #define HAVE_TICK_COUNTER
367 #if defined(__GNUC__) && defined(__s390__) && !defined(HAVE_TICK_COUNTER)
368 typedef unsigned long long ticks;
370 static __inline__ ticks getticks(
void)
373 __asm__(
"stck 0(%0)" : :
"a" (&(cycles)) :
"memory",
"cc");
377 INLINE_ELAPSED(__inline__)
379 #define HAVE_TICK_COUNTER
382 #if defined(__GNUC__) && defined(__alpha__) && !defined(HAVE_TICK_COUNTER)
387 typedef unsigned int ticks;
389 static __inline__ ticks getticks(
void)
392 __asm__ __volatile__ (
"rpcc %0" :
"=r"(cc));
393 return (cc & 0xFFFFFFFF);
396 INLINE_ELAPSED(__inline__)
398 #define HAVE_TICK_COUNTER
402 #if defined(__GNUC__) && defined(__sparc_v9__) && !defined(HAVE_TICK_COUNTER)
403 typedef unsigned long ticks;
405 static __inline__ ticks getticks(
void)
408 __asm__ __volatile__(
"rd %%tick, %0" :
"=r" (ret));
412 INLINE_ELAPSED(__inline__)
414 #define HAVE_TICK_COUNTER
418 #if (defined(__DECC) || defined(__DECCXX)) && defined(__alpha) && defined(HAVE_C_ASM_H) && !defined(HAVE_TICK_COUNTER)
420 typedef unsigned int ticks;
422 static __inline ticks getticks(
void)
425 cc =
asm(
"rpcc %v0");
426 return (cc & 0xFFFFFFFF);
429 INLINE_ELAPSED(__inline)
431 #define HAVE_TICK_COUNTER
435 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) && !defined(HAVE_TICK_COUNTER)
436 typedef struct timespec ticks;
438 static inline ticks getticks(
void)
441 clock_gettime(CLOCK_SGI_CYCLE, &t);
445 static 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>
460 typedef long long ticks;
462 #define getticks _rtc
464 INLINE_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)
473 #include <sys/mman.h>
477 typedef uint64_t ticks;
479 static 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) {
506 INLINE_ELAPSED(
inline)
508 #define HAVE_TICK_COUNTER