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(ticks t1, ticks t0) \
98 return (double)t1 - (double)t0; \
103 #if defined(HAVE_GETHRTIME) && defined(HAVE_HRTIME_T) && !defined(HAVE_TICK_COUNTER)
104 typedef hrtime_t ticks;
106 #define getticks gethrtime
108 INLINE_ELAPSED(
inline)
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 ticks;
118 static __inline ticks getticks(
void)
121 read_real_time(&t, TIMEBASE_SZ);
125 static __inline
double elapsed(ticks t1, ticks t0)
127 time_base_to_time(&t1, TIMEBASE_SZ);
128 time_base_to_time(&t0, TIMEBASE_SZ);
129 return (((
double)t1.tb_high - (
double)t0.tb_high) * 1.0e9 +
130 ((
double)t1.tb_low - (
double)t0.tb_low));
133 #define HAVE_TICK_COUNTER
140 #if ((((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh)))) || (defined(__IBM_GCC_ASM) && (defined(__powerpc__) || defined(__ppc__)))) && !defined(HAVE_TICK_COUNTER)
141 typedef unsigned long long ticks;
143 static __inline__ ticks getticks(
void)
145 unsigned int tbl, tbu0, tbu1;
148 __asm__ __volatile__ (
"mftbu %0" :
"=r"(tbu0));
149 __asm__ __volatile__ (
"mftb %0" :
"=r"(tbl));
150 __asm__ __volatile__ (
"mftbu %0" :
"=r"(tbu1));
151 }
while (tbu0 != tbu1);
153 return (((
unsigned long long)tbu0) << 32) | tbl;
156 INLINE_ELAPSED(__inline__)
158 #define HAVE_TICK_COUNTER
163 #if defined(HAVE_MACH_ABSOLUTE_TIME) && defined(HAVE_MACH_MACH_TIME_H) && !defined(HAVE_TICK_COUNTER)
164 #include <mach/mach_time.h>
165 typedef uint64_t ticks;
166 #define getticks mach_absolute_time
167 INLINE_ELAPSED(__inline__)
168 #define HAVE_TICK_COUNTER
175 #if (defined(__GNUC__) || defined(__ICC)) && defined(__i386__) && !defined(HAVE_TICK_COUNTER)
176 typedef unsigned long long ticks;
178 static __inline__ ticks getticks(
void)
182 __asm__ __volatile__(
"rdtsc":
"=A" (ret));
187 INLINE_ELAPSED(__inline__)
189 #define HAVE_TICK_COUNTER
190 #define TIME_MIN 5000.0
194 #if _MSC_VER >= 1200 && _M_IX86 >= 500 && !defined(HAVE_TICK_COUNTER)
196 typedef LARGE_INTEGER ticks;
197 #define RDTSC __asm __emit 0fh __asm __emit 031h
199 static __inline ticks getticks(
void)
205 mov retval.HighPart, edx
206 mov retval.LowPart, eax
213 static __inline
double elapsed(ticks t1, ticks t0)
215 return (
double)t1.QuadPart - (double)t0.QuadPart;
218 #define HAVE_TICK_COUNTER
219 #define TIME_MIN 5000.0
226 #if (defined(__GNUC__) || defined(__ICC) || defined(__SUNPRO_C)) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
227 typedef unsigned long long ticks;
229 static __inline__ ticks getticks(
void)
232 asm volatile(
"rdtsc" :
"=a" (a),
"=d" (d));
233 return ((ticks)a) | (((ticks)d) << 32);
236 INLINE_ELAPSED(__inline__)
238 #define HAVE_TICK_COUNTER
244 #if defined(__PGI) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
245 typedef unsigned long long ticks;
246 static ticks getticks(
void)
248 asm(
" rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; ");
250 INLINE_ELAPSED(__inline__)
251 #define HAVE_TICK_COUNTER
255 #if _MSC_VER >= 1400 && (defined(_M_AMD64) || defined(_M_X64)) && !defined(HAVE_TICK_COUNTER)
258 #pragma intrinsic(__rdtsc)
259 typedef unsigned __int64 ticks;
260 #define getticks __rdtsc
261 INLINE_ELAPSED(__inline)
263 #define HAVE_TICK_COUNTER
272 #if (defined(__EDG_VERSION) || defined(__ECC)) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
273 typedef unsigned long ticks;
274 #include <ia64intrin.h>
276 static __inline__ ticks getticks(
void)
278 return __getReg(_IA64_REG_AR_ITC);
281 INLINE_ELAPSED(__inline__)
283 #define HAVE_TICK_COUNTER
287 #if defined(__GNUC__) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
288 typedef unsigned long ticks;
290 static __inline__ ticks getticks(
void)
294 __asm__ __volatile__ (
"mov %0=ar.itc" :
"=r"(ret));
298 INLINE_ELAPSED(__inline__)
300 #define HAVE_TICK_COUNTER
304 #if defined(__hpux) && defined(__ia64) && !defined(HAVE_TICK_COUNTER)
305 #include <machine/sys/inline.h>
306 typedef unsigned long ticks;
308 static inline ticks getticks(
void)
312 ret = _Asm_mov_from_ar (_AREG_ITC);
316 INLINE_ELAPSED(
inline)
318 #define HAVE_TICK_COUNTER
322 #if defined(_MSC_VER) && defined(_M_IA64) && !defined(HAVE_TICK_COUNTER)
323 typedef unsigned __int64 ticks;
328 ticks __getReg(
int whichReg);
329 #pragma intrinsic(__getReg)
331 static __inline ticks getticks(
void)
334 temp = __getReg(3116);
338 INLINE_ELAPSED(
inline)
340 #define HAVE_TICK_COUNTER
347 #if defined(__hppa__) || defined(__hppa) && !defined(HAVE_TICK_COUNTER)
348 typedef unsigned long ticks;
351 static __inline__ ticks getticks(
void)
355 __asm__ __volatile__(
"mfctl 16, %0":
"=r" (ret));
360 # include <machine/inline.h>
361 static inline unsigned long getticks(
void)
369 INLINE_ELAPSED(
inline)
371 #define HAVE_TICK_COUNTER
376 #if defined(__GNUC__) && defined(__s390__) && !defined(HAVE_TICK_COUNTER)
377 typedef unsigned long long ticks;
379 static __inline__ ticks getticks(
void)
382 __asm__(
"stck 0(%0)" : :
"a" (&(cycles)) :
"memory",
"cc");
386 INLINE_ELAPSED(__inline__)
388 #define HAVE_TICK_COUNTER
391 #if defined(__GNUC__) && defined(__alpha__) && !defined(HAVE_TICK_COUNTER)
396 typedef unsigned int ticks;
398 static __inline__ ticks getticks(
void)
401 __asm__ __volatile__ (
"rpcc %0" :
"=r"(cc));
402 return (cc & 0xFFFFFFFF);
405 INLINE_ELAPSED(__inline__)
407 #define HAVE_TICK_COUNTER
411 #if defined(__GNUC__) && defined(__sparc_v9__) && !defined(HAVE_TICK_COUNTER)
412 typedef unsigned long ticks;
414 static __inline__ ticks getticks(
void)
417 __asm__ __volatile__(
"rd %%tick, %0" :
"=r" (ret));
421 INLINE_ELAPSED(__inline__)
423 #define HAVE_TICK_COUNTER
427 #if (defined(__DECC) || defined(__DECCXX)) && defined(__alpha) && defined(HAVE_C_ASM_H) && !defined(HAVE_TICK_COUNTER)
429 typedef unsigned int ticks;
431 static __inline ticks getticks(
void)
434 cc =
asm(
"rpcc %v0");
435 return (cc & 0xFFFFFFFF);
438 INLINE_ELAPSED(__inline)
440 #define HAVE_TICK_COUNTER
444 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) && !defined(HAVE_TICK_COUNTER)
445 typedef struct timespec ticks;
447 static inline ticks getticks(
void)
450 clock_gettime(CLOCK_SGI_CYCLE, &t);
454 static inline double elapsed(ticks t1, ticks t0)
456 return ((
double)t1.tv_sec - (
double)t0.tv_sec) * 1.0E9 +
457 ((double)t1.tv_nsec - (
double)t0.tv_nsec);
459 #define HAVE_TICK_COUNTER
464 #if defined(HAVE__RTC) && !defined(HAVE_TICK_COUNTER)
465 #ifdef HAVE_INTRINSICS_H
466 # include <intrinsics.h>
469 typedef long long ticks;
471 #define getticks _rtc
473 INLINE_ELAPSED(
inline)
475 #define HAVE_TICK_COUNTER
480 #if HAVE_MIPS_ZBUS_TIMER
481 #if defined(__mips__) && !defined(HAVE_TICK_COUNTER)
482 #include <sys/mman.h>
486 typedef uint64_t ticks;
488 static inline ticks getticks(
void)
490 static uint64_t* addr = 0;
494 uint32_t rq_addr = 0x10030000;
498 pgsize = getpagesize();
499 fd = open (
"/dev/mem", O_RDONLY | O_SYNC, 0);
504 addr = mmap(0, pgsize, PROT_READ, MAP_SHARED, fd, rq_addr);
506 if (addr == (uint64_t *)-1) {
515 INLINE_ELAPSED(
inline)
517 #define HAVE_TICK_COUNTER