81 #if TIME_WITH_SYS_TIME
82 # include <sys/time.h>
86 # include <sys/time.h>
92 #define INLINE_ELAPSED(INL) static INL double elapsed(ticks t1, ticks t0) \
94 return (double)t1 - (double)t0; \
99 #if defined(HAVE_GETHRTIME) && defined(HAVE_HRTIME_T) && !defined(HAVE_TICK_COUNTER)
100 typedef hrtime_t ticks;
102 #define getticks gethrtime
104 INLINE_ELAPSED(
inline)
106 #define HAVE_TICK_COUNTER
111 #if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER)
112 typedef timebasestruct_t ticks;
114 static __inline ticks getticks(
void)
117 read_real_time(&t, TIMEBASE_SZ);
121 static __inline
double elapsed(ticks t1, ticks t0)
123 time_base_to_time(&t1, TIMEBASE_SZ);
124 time_base_to_time(&t0, TIMEBASE_SZ);
125 return (((
double)t1.tb_high - (
double)t0.tb_high) * 1.0e9 +
126 ((
double)t1.tb_low - (
double)t0.tb_low));
129 #define HAVE_TICK_COUNTER
136 #if ((((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh)))) || (defined(__IBM_GCC_ASM) && (defined(__powerpc__) || defined(__ppc__)))) && !defined(HAVE_TICK_COUNTER)
137 typedef unsigned long long ticks;
139 static __inline__ ticks getticks(
void)
141 unsigned int tbl, tbu0, tbu1;
144 __asm__ __volatile__ (
"mftbu %0" :
"=r"(tbu0));
145 __asm__ __volatile__ (
"mftb %0" :
"=r"(tbl));
146 __asm__ __volatile__ (
"mftbu %0" :
"=r"(tbu1));
147 }
while (tbu0 != tbu1);
149 return (((
unsigned long long)tbu0) << 32) | tbl;
152 INLINE_ELAPSED(__inline__)
154 #define HAVE_TICK_COUNTER
159 #if defined(HAVE_MACH_ABSOLUTE_TIME) && defined(HAVE_MACH_MACH_TIME_H) && !defined(HAVE_TICK_COUNTER)
160 #include <mach/mach_time.h>
161 typedef uint64_t ticks;
162 #define getticks mach_absolute_time
163 INLINE_ELAPSED(__inline__)
164 #define HAVE_TICK_COUNTER
171 #if (defined(__GNUC__) || defined(__ICC)) && defined(__i386__) && !defined(HAVE_TICK_COUNTER)
172 typedef unsigned long long ticks;
174 static __inline__ ticks getticks(
void)
178 __asm__ __volatile__(
"rdtsc":
"=A" (ret));
183 INLINE_ELAPSED(__inline__)
185 #define HAVE_TICK_COUNTER
186 #define TIME_MIN 5000.0
190 #if defined(_MSC_VER) && _MSC_VER >= 1200 && _M_IX86 >= 500 && !defined(HAVE_TICK_COUNTER)
192 typedef LARGE_INTEGER ticks;
193 #define RDTSC __asm __emit 0fh __asm __emit 031h
195 static __inline ticks getticks(
void)
201 mov retval.HighPart, edx
202 mov retval.LowPart, eax
207 static __inline
double elapsed(ticks t1, ticks t0)
209 return (
double)t1.QuadPart - (double)t0.QuadPart;
212 #define HAVE_TICK_COUNTER
213 #define TIME_MIN 5000.0
220 #if (defined(__GNUC__) || defined(__ICC) || defined(__SUNPRO_C)) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
221 typedef unsigned long long ticks;
223 static __inline__ ticks getticks(
void)
226 asm volatile(
"rdtsc" :
"=a" (a),
"=d" (d));
227 return ((ticks)a) | (((ticks)d) << 32);
230 INLINE_ELAPSED(__inline__)
232 #define HAVE_TICK_COUNTER
233 #define TIME_MIN 5000.0
239 #if defined(__PGI) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
240 typedef unsigned long long ticks;
241 static ticks getticks(
void)
243 asm(
" rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; ");
245 INLINE_ELAPSED(__inline__)
246 #define HAVE_TICK_COUNTER
247 #define TIME_MIN 5000.0
251 #if defined(_MSC_VER) && _MSC_VER >= 1400 && (defined(_M_AMD64) || defined(_M_X64)) && !defined(HAVE_TICK_COUNTER)
254 #pragma intrinsic(__rdtsc)
255 typedef unsigned __int64 ticks;
256 #define getticks __rdtsc
257 INLINE_ELAPSED(__inline)
259 #define HAVE_TICK_COUNTER
260 #define TIME_MIN 5000.0
269 #if (defined(__EDG_VERSION) || defined(__ECC)) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
270 typedef unsigned long ticks;
271 #include <ia64intrin.h>
273 static __inline__ ticks getticks(
void)
275 return __getReg(_IA64_REG_AR_ITC);
278 INLINE_ELAPSED(__inline__)
280 #define HAVE_TICK_COUNTER
284 #if defined(__GNUC__) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
285 typedef unsigned long ticks;
287 static __inline__ ticks getticks(
void)
291 __asm__ __volatile__ (
"mov %0=ar.itc" :
"=r"(ret));
295 INLINE_ELAPSED(__inline__)
297 #define HAVE_TICK_COUNTER
301 #if defined(__hpux) && defined(__ia64) && !defined(HAVE_TICK_COUNTER)
302 #include <machine/sys/inline.h>
303 typedef unsigned long ticks;
305 static inline ticks getticks(
void)
309 ret = _Asm_mov_from_ar (_AREG_ITC);
313 INLINE_ELAPSED(
inline)
315 #define HAVE_TICK_COUNTER
319 #if defined(_MSC_VER) && defined(_M_IA64) && !defined(HAVE_TICK_COUNTER)
320 typedef unsigned __int64 ticks;
325 ticks __getReg(
int whichReg);
326 #pragma intrinsic(__getReg)
328 static __inline ticks getticks(
void)
331 temp = __getReg(3116);
335 INLINE_ELAPSED(
inline)
337 #define HAVE_TICK_COUNTER
344 #if (defined(__hppa__) || defined(__hppa)) && !defined(HAVE_TICK_COUNTER)
345 typedef unsigned long ticks;
348 static __inline__ ticks getticks(
void)
352 __asm__ __volatile__(
"mfctl 16, %0":
"=r" (ret));
357 # include <machine/inline.h>
358 static inline unsigned long getticks(
void)
366 INLINE_ELAPSED(
inline)
368 #define HAVE_TICK_COUNTER
373 #if defined(__GNUC__) && defined(__s390__) && !defined(HAVE_TICK_COUNTER)
374 typedef unsigned long long ticks;
376 static __inline__ ticks getticks(
void)
379 __asm__(
"stck 0(%0)" : :
"a" (&(cycles)) :
"memory",
"cc");
383 INLINE_ELAPSED(__inline__)
385 #define HAVE_TICK_COUNTER
388 #if defined(__GNUC__) && defined(__alpha__) && !defined(HAVE_TICK_COUNTER)
393 typedef unsigned int ticks;
395 static __inline__ ticks getticks(
void)
398 __asm__ __volatile__ (
"rpcc %0" :
"=r"(cc));
399 return (cc & 0xFFFFFFFF);
402 INLINE_ELAPSED(__inline__)
404 #define HAVE_TICK_COUNTER
408 #if defined(__GNUC__) && defined(__sparc_v9__) && !defined(HAVE_TICK_COUNTER)
409 typedef unsigned long ticks;
411 static __inline__ ticks getticks(
void)
414 __asm__ __volatile__(
"rd %%tick, %0" :
"=r" (ret));
418 INLINE_ELAPSED(__inline__)
420 #define HAVE_TICK_COUNTER
424 #if (defined(__DECC) || defined(__DECCXX)) && defined(__alpha) && defined(HAVE_C_ASM_H) && !defined(HAVE_TICK_COUNTER)
426 typedef unsigned int ticks;
428 static __inline ticks getticks(
void)
431 cc =
asm(
"rpcc %v0");
432 return (cc & 0xFFFFFFFF);
435 INLINE_ELAPSED(__inline)
437 #define HAVE_TICK_COUNTER
441 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) && !defined(HAVE_TICK_COUNTER)
442 typedef struct timespec ticks;
444 static inline ticks getticks(
void)
447 clock_gettime(CLOCK_SGI_CYCLE, &t);
451 static inline double elapsed(ticks t1, ticks t0)
453 return ((
double)t1.tv_sec - (
double)t0.tv_sec) * 1.0E9 +
454 ((double)t1.tv_nsec - (
double)t0.tv_nsec);
456 #define HAVE_TICK_COUNTER
461 #if defined(HAVE__RTC) && !defined(HAVE_TICK_COUNTER)
462 #ifdef HAVE_INTRINSICS_H
463 # include <intrinsics.h>
466 typedef long long ticks;
468 #define getticks _rtc
470 INLINE_ELAPSED(
inline)
472 #define HAVE_TICK_COUNTER
477 #if defined(HAVE_MIPS_ZBUS_TIMER) && HAVE_MIPS_ZBUS_TIMER
478 #if defined(__mips__) && !defined(HAVE_TICK_COUNTER)
479 #include <sys/mman.h>
483 typedef uint64_t ticks;
485 static inline ticks getticks(
void)
487 static uint64_t* addr = 0;
491 uint32_t rq_addr = 0x10030000;
495 pgsize = getpagesize();
496 fd = open (
"/dev/mem", O_RDONLY | O_SYNC, 0);
501 addr = mmap(0, pgsize, PROT_READ, MAP_SHARED, fd, rq_addr);
503 if (addr == (uint64_t *)-1) {
512 INLINE_ELAPSED(
inline)
514 #define HAVE_TICK_COUNTER