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)
100typedef hrtime_t ticks;
102#define getticks gethrtime
104INLINE_ELAPSED(
inline)
106#define HAVE_TICK_COUNTER
111#if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER)
112typedef timebasestruct_t ticks;
114static __inline ticks getticks(
void)
117 read_real_time(&t, TIMEBASE_SZ);
121static __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)
137typedef unsigned long long ticks;
139static __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;
152INLINE_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>
161typedef uint64_t ticks;
162#define getticks mach_absolute_time
163INLINE_ELAPSED(__inline__)
164#define HAVE_TICK_COUNTER
171#if (defined(__GNUC__) || defined(__ICC)) && defined(__i386__) && !defined(HAVE_TICK_COUNTER)
172typedef unsigned long long ticks;
174static __inline__ ticks getticks(
void)
178 __asm__ __volatile__(
"rdtsc":
"=A" (ret));
183INLINE_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)
192typedef LARGE_INTEGER ticks;
193#define RDTSC __asm __emit 0fh __asm __emit 031h
195static __inline ticks getticks(
void)
201 mov retval.HighPart, edx
202 mov retval.LowPart, eax
207static __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)
221typedef unsigned long long ticks;
223static __inline__ ticks getticks(
void)
226 __asm__ __volatile__ (
"rdtsc" :
"=a" (a),
"=d" (d));
227 return ((ticks)a) | (((ticks)d) << 32);
230INLINE_ELAPSED(__inline__)
232#define HAVE_TICK_COUNTER
233#define TIME_MIN 5000.0
239#if defined(__PGI) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
240typedef unsigned long long ticks;
241static ticks getticks(
void)
243 asm(
" rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; ");
245INLINE_ELAPSED(__inline__)
246#define HAVE_TICK_COUNTER
247#define TIME_MIN 5000.0
251#if _MSC_VER >= 1400 && (defined(_M_AMD64) || defined(_M_X64)) && !defined(HAVE_TICK_COUNTER)
254#pragma intrinsic(__rdtsc)
255typedef unsigned __int64 ticks;
256#define getticks __rdtsc
257INLINE_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)
270typedef unsigned long ticks;
271#include <ia64intrin.h>
273static __inline__ ticks getticks(
void)
275 return __getReg(_IA64_REG_AR_ITC);
278INLINE_ELAPSED(__inline__)
280#define HAVE_TICK_COUNTER
284#if defined(__GNUC__) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
285typedef unsigned long ticks;
287static __inline__ ticks getticks(
void)
291 __asm__ __volatile__ (
"mov %0=ar.itc" :
"=r"(ret));
295INLINE_ELAPSED(__inline__)
297#define HAVE_TICK_COUNTER
301#if defined(__hpux) && defined(__ia64) && !defined(HAVE_TICK_COUNTER)
302#include <machine/sys/inline.h>
303typedef unsigned long ticks;
305static inline ticks getticks(
void)
309 ret = _Asm_mov_from_ar (_AREG_ITC);
313INLINE_ELAPSED(
inline)
315#define HAVE_TICK_COUNTER
319#if defined(_MSC_VER) && defined(_M_IA64) && !defined(HAVE_TICK_COUNTER)
320typedef unsigned __int64 ticks;
325ticks __getReg(
int whichReg);
326#pragma intrinsic(__getReg)
328static __inline ticks getticks(
void)
331 temp = __getReg(3116);
335INLINE_ELAPSED(
inline)
337#define HAVE_TICK_COUNTER
344#if (defined(__hppa__) || defined(__hppa)) && !defined(HAVE_TICK_COUNTER)
345typedef unsigned long ticks;
348static __inline__ ticks getticks(
void)
352 __asm__ __volatile__(
"mfctl 16, %0":
"=r" (ret));
357# include <machine/inline.h>
358static inline unsigned long getticks(
void)
366INLINE_ELAPSED(
inline)
368#define HAVE_TICK_COUNTER
373#if defined(__GNUC__) && defined(__s390__) && !defined(HAVE_TICK_COUNTER)
374typedef unsigned long long ticks;
376static __inline__ ticks getticks(
void)
379 __asm__(
"stck 0(%0)" : :
"a" (&(cycles)) :
"memory",
"cc");
383INLINE_ELAPSED(__inline__)
385#define HAVE_TICK_COUNTER
388#if defined(__GNUC__) && defined(__alpha__) && !defined(HAVE_TICK_COUNTER)
393typedef unsigned int ticks;
395static __inline__ ticks getticks(
void)
398 __asm__ __volatile__ (
"rpcc %0" :
"=r"(cc));
399 return (cc & 0xFFFFFFFF);
402INLINE_ELAPSED(__inline__)
404#define HAVE_TICK_COUNTER
408#if defined(__GNUC__) && defined(__sparc_v9__) && !defined(HAVE_TICK_COUNTER)
409typedef unsigned long ticks;
411static __inline__ ticks getticks(
void)
414 __asm__ __volatile__(
"rd %%tick, %0" :
"=r" (ret));
418INLINE_ELAPSED(__inline__)
420#define HAVE_TICK_COUNTER
424#if (defined(__DECC) || defined(__DECCXX)) && defined(__alpha) && defined(HAVE_C_ASM_H) && !defined(HAVE_TICK_COUNTER)
426typedef unsigned int ticks;
428static __inline ticks getticks(
void)
431 cc =
asm(
"rpcc %v0");
432 return (cc & 0xFFFFFFFF);
435INLINE_ELAPSED(__inline)
437#define HAVE_TICK_COUNTER
441#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) && !defined(HAVE_TICK_COUNTER) && !defined(__ANDROID__)
442typedef struct timespec ticks;
444static inline ticks getticks(
void)
447 clock_gettime(CLOCK_SGI_CYCLE, &t);
451static 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>
466typedef long long ticks;
470INLINE_ELAPSED(
inline)
472#define HAVE_TICK_COUNTER
477#if HAVE_MIPS_ZBUS_TIMER
478#if defined(__mips__) && !defined(HAVE_TICK_COUNTER)
483typedef uint64_t ticks;
485static 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) {
512INLINE_ELAPSED(
inline)
514#define HAVE_TICK_COUNTER
518#if defined(HAVE_ARMV7A_CNTVCT)
519typedef uint64_t ticks;
520static inline ticks getticks(
void)
522 uint32_t Rt, Rt2 = 0;
523 asm volatile(
"mrrc p15, 1, %0, %1, c14" :
"=r"(Rt),
"=r"(Rt2));
524 return ((uint64_t)Rt) | (((uint64_t)Rt2) << 32);
526INLINE_ELAPSED(
inline)
527#define HAVE_TICK_COUNTER
530#if defined(HAVE_ARMV7A_PMCCNTR)
531typedef uint64_t ticks;
532static inline ticks getticks(
void)
535 asm volatile(
"mrc p15, 0, %0, c9, c13, 0" :
"=r"(r) );
538INLINE_ELAPSED(
inline)
539#define HAVE_TICK_COUNTER
542#if defined(__aarch64__) && defined(HAVE_ARMV8_CNTVCT_EL0) && !defined(HAVE_ARMV8_PMCCNTR_EL0)
543typedef uint64_t ticks;
544static inline ticks getticks(
void)
547 asm volatile(
"mrs %0, CNTVCT_EL0" :
"=r" (Rt));
550INLINE_ELAPSED(
inline)
551#define HAVE_TICK_COUNTER
554#if defined(__aarch64__) && defined(HAVE_ARMV8_PMCCNTR_EL0)
555typedef uint64_t ticks;
556static inline ticks getticks(
void)
559 asm volatile(
"mrs %0, PMCCNTR_EL0" :
"=r"(cc));
562INLINE_ELAPSED(
inline)
563#define HAVE_TICK_COUNTER
567#if !defined(HAVE_TICK_COUNTER)
568typedef unsigned long long ticks;
569#define getticks() __builtin_readcyclecounter()
570#define HAVE_TICK_COUNTER
HRESULT close()
Closes the main window, while the application / simulation continues to run.