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 _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
238 #if defined(__PGI) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
239 typedef unsigned long long ticks;
240 static ticks getticks(
void)
242 asm(
" rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; ");
244 INLINE_ELAPSED(__inline__)
245 #define HAVE_TICK_COUNTER
249 #if _MSC_VER >= 1400 && (defined(_M_AMD64) || defined(_M_X64)) && !defined(HAVE_TICK_COUNTER)
252 #pragma intrinsic(__rdtsc)
253 typedef unsigned __int64 ticks;
254 #define getticks __rdtsc
255 INLINE_ELAPSED(__inline)
257 #define HAVE_TICK_COUNTER
266 #if (defined(__EDG_VERSION) || defined(__ECC)) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
267 typedef unsigned long ticks;
268 #include <ia64intrin.h>
270 static __inline__ ticks getticks(
void)
272 return __getReg(_IA64_REG_AR_ITC);
275 INLINE_ELAPSED(__inline__)
277 #define HAVE_TICK_COUNTER
281 #if defined(__GNUC__) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
282 typedef unsigned long ticks;
284 static __inline__ ticks getticks(
void)
288 __asm__ __volatile__ (
"mov %0=ar.itc" :
"=r"(ret));
292 INLINE_ELAPSED(__inline__)
294 #define HAVE_TICK_COUNTER
298 #if defined(__hpux) && defined(__ia64) && !defined(HAVE_TICK_COUNTER)
299 #include <machine/sys/inline.h>
300 typedef unsigned long ticks;
302 static inline ticks getticks(
void)
306 ret = _Asm_mov_from_ar (_AREG_ITC);
310 INLINE_ELAPSED(
inline)
312 #define HAVE_TICK_COUNTER
316 #if defined(_MSC_VER) && defined(_M_IA64) && !defined(HAVE_TICK_COUNTER)
317 typedef unsigned __int64 ticks;
322 ticks __getReg(
int whichReg);
323 #pragma intrinsic(__getReg)
325 static __inline ticks getticks(
void)
328 temp = __getReg(3116);
332 INLINE_ELAPSED(
inline)
334 #define HAVE_TICK_COUNTER
341 #if defined(__hppa__) || defined(__hppa) && !defined(HAVE_TICK_COUNTER)
342 typedef unsigned long ticks;
345 static __inline__ ticks getticks(
void)
349 __asm__ __volatile__(
"mfctl 16, %0":
"=r" (ret));
354 # include <machine/inline.h>
355 static inline unsigned long getticks(
void)
363 INLINE_ELAPSED(
inline)
365 #define HAVE_TICK_COUNTER
370 #if defined(__GNUC__) && defined(__s390__) && !defined(HAVE_TICK_COUNTER)
371 typedef unsigned long long ticks;
373 static __inline__ ticks getticks(
void)
376 __asm__(
"stck 0(%0)" : :
"a" (&(cycles)) :
"memory",
"cc");
380 INLINE_ELAPSED(__inline__)
382 #define HAVE_TICK_COUNTER
385 #if defined(__GNUC__) && defined(__alpha__) && !defined(HAVE_TICK_COUNTER)
390 typedef unsigned int ticks;
392 static __inline__ ticks getticks(
void)
395 __asm__ __volatile__ (
"rpcc %0" :
"=r"(cc));
396 return (cc & 0xFFFFFFFF);
399 INLINE_ELAPSED(__inline__)
401 #define HAVE_TICK_COUNTER
405 #if defined(__GNUC__) && defined(__sparc_v9__) && !defined(HAVE_TICK_COUNTER)
406 typedef unsigned long ticks;
408 static __inline__ ticks getticks(
void)
411 __asm__ __volatile__(
"rd %%tick, %0" :
"=r" (ret));
415 INLINE_ELAPSED(__inline__)
417 #define HAVE_TICK_COUNTER
421 #if (defined(__DECC) || defined(__DECCXX)) && defined(__alpha) && defined(HAVE_C_ASM_H) && !defined(HAVE_TICK_COUNTER)
423 typedef unsigned int ticks;
425 static __inline ticks getticks(
void)
428 cc =
asm(
"rpcc %v0");
429 return (cc & 0xFFFFFFFF);
432 INLINE_ELAPSED(__inline)
434 #define HAVE_TICK_COUNTER
438 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) && !defined(HAVE_TICK_COUNTER)
439 typedef struct timespec ticks;
441 static inline ticks getticks(
void)
444 clock_gettime(CLOCK_SGI_CYCLE, &t);
448 static inline double elapsed(ticks t1, ticks t0)
450 return ((
double)t1.tv_sec - (
double)t0.tv_sec) * 1.0E9 +
451 ((double)t1.tv_nsec - (
double)t0.tv_nsec);
453 #define HAVE_TICK_COUNTER
458 #if defined(HAVE__RTC) && !defined(HAVE_TICK_COUNTER)
459 #ifdef HAVE_INTRINSICS_H
460 # include <intrinsics.h>
463 typedef long long ticks;
465 #define getticks _rtc
467 INLINE_ELAPSED(
inline)
469 #define HAVE_TICK_COUNTER
474 #if HAVE_MIPS_ZBUS_TIMER
475 #if defined(__mips__) && !defined(HAVE_TICK_COUNTER)
476 #include <sys/mman.h>
480 typedef uint64_t ticks;
482 static inline ticks getticks(
void)
484 static uint64_t* addr = 0;
488 uint32_t rq_addr = 0x10030000;
492 pgsize = getpagesize();
493 fd = open (
"/dev/mem", O_RDONLY | O_SYNC, 0);
498 addr = mmap(0, pgsize, PROT_READ, MAP_SHARED, fd, rq_addr);
500 if (addr == (uint64_t *)-1) {
509 INLINE_ELAPSED(
inline)
511 #define HAVE_TICK_COUNTER