aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2008-03-27 18:40:38 -0500
committerErik Schnetter <schnetter@cct.lsu.edu>2008-03-27 18:40:38 -0500
commit6d4ea13bd72d10a1c3ea082dab48b9d497bc7326 (patch)
tree72d60917fcd5e073ba4a4bae70610ac3869d00a7
parent7a0bf5119fdddbd979d40b3072f3aada36c6627c (diff)
CarpetLib: Update cycle.h
Update the file cycle.h from FFTW. This file defines the low-level and system-dependend timers. This update should add support for IBM compilers on PPC architectures.
-rw-r--r--Carpet/CarpetLib/src/cycle.h76
1 files changed, 61 insertions, 15 deletions
diff --git a/Carpet/CarpetLib/src/cycle.h b/Carpet/CarpetLib/src/cycle.h
index d2b0a7dc2..e6367c3ea 100644
--- a/Carpet/CarpetLib/src/cycle.h
+++ b/Carpet/CarpetLib/src/cycle.h
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 2003, 2006 Matteo Frigo
- * Copyright (c) 2003, 2006 Massachusetts Institute of Technology
+ * Copyright (c) 2003, 2007 Matteo Frigo
+ * Copyright (c) 2003, 2007 Massachusetts Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -23,7 +23,6 @@
*
*/
-/* $Id: cycle.h,v 1.52 2006-02-08 02:36:47 athena Exp $ */
/* machine-dependent cycle counters code. Needs to be inlined. */
@@ -92,7 +91,7 @@
#define INLINE_ELAPSED(INL) static INL double elapsed(ticks t1, ticks t0) \
{ \
- return (double)(t1 - t0); \
+ return (double)t1 - (double)t0; \
}
/*----------------------------------------------------------------*/
@@ -112,18 +111,19 @@ INLINE_ELAPSED(inline)
#if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER)
typedef timebasestruct_t ticks;
-static inline ticks getticks(void)
+static __inline ticks getticks(void)
{
ticks t;
read_real_time(&t, TIMEBASE_SZ);
return t;
}
-static inline double elapsed(ticks t1, ticks t0) /* time in nanoseconds */
+static __inline double elapsed(ticks t1, ticks t0) /* time in nanoseconds */
{
time_base_to_time(&t1, TIMEBASE_SZ);
time_base_to_time(&t0, TIMEBASE_SZ);
- return ((t1.tb_high - t0.tb_high) * 1e9 + (t1.tb_low - t0.tb_low));
+ return (((double)t1.tb_high - (double)t0.tb_high) * 1.0e9 +
+ ((double)t1.tb_low - (double)t0.tb_low));
}
#define HAVE_TICK_COUNTER
@@ -133,7 +133,7 @@ static inline double elapsed(ticks t1, ticks t0) /* time in nanoseconds */
/*
* PowerPC ``cycle'' counter using the time base register.
*/
-#if ((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh))) && !defined(HAVE_TICK_COUNTER)
+#if ((((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh)))) || (defined(__IBM_GCC_ASM) && (defined(__powerpc__) || defined(__ppc__)))) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long long ticks;
static __inline__ ticks getticks(void)
@@ -206,7 +206,7 @@ static __inline ticks getticks(void)
static __inline double elapsed(ticks t1, ticks t0)
{
- return (double)(t1.QuadPart - t0.QuadPart);
+ return (double)t1.QuadPart - (double)t0.QuadPart;
}
#define HAVE_TICK_COUNTER
@@ -217,7 +217,7 @@ static __inline double elapsed(ticks t1, ticks t0)
/*
* X86-64 cycle counter
*/
-#if (defined(__GNUC__) || defined(__ICC)) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
+#if (defined(__GNUC__) || defined(__ICC) || defined(__SUNPRO_C)) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long long ticks;
static __inline__ ticks getticks(void)
@@ -245,12 +245,13 @@ INLINE_ELAPSED(__inline__)
#define HAVE_TICK_COUNTER
#endif
-/* Visual C++ */
+/* Visual C++, courtesy of Dirk Michaelis */
#if _MSC_VER >= 1400 && (defined(_M_AMD64) || defined(_M_X64)) && !defined(HAVE_TICK_COUNTER)
-typedef ULONG64 ticks;
+#include <intrin.h>
+#pragma intrinsic(__rdtsc)
+typedef unsigned __int64 ticks;
#define getticks __rdtsc
-
INLINE_ELAPSED(__inline)
#define HAVE_TICK_COUNTER
@@ -328,6 +329,8 @@ static __inline ticks getticks(void)
return temp;
}
+INLINE_ELAPSED(inline)
+
#define HAVE_TICK_COUNTER
#endif
@@ -444,8 +447,8 @@ static inline ticks getticks(void)
static inline double elapsed(ticks t1, ticks t0)
{
- return (double)(t1.tv_sec - t0.tv_sec) * 1.0E9 +
- (double)(t1.tv_nsec - t0.tv_nsec);
+ return ((double)t1.tv_sec - (double)t0.tv_sec) * 1.0E9 +
+ ((double)t1.tv_nsec - (double)t0.tv_nsec);
}
#define HAVE_TICK_COUNTER
#endif
@@ -465,3 +468,46 @@ INLINE_ELAPSED(inline)
#define HAVE_TICK_COUNTER
#endif
+
+/*----------------------------------------------------------------*/
+/* MIPS ZBus */
+#if HAVE_MIPS_ZBUS_TIMER
+#if defined(__mips__) && !defined(HAVE_TICK_COUNTER)
+#include <sys/mman.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+typedef uint64_t ticks;
+
+static inline ticks getticks(void)
+{
+ static uint64_t* addr = 0;
+
+ if (addr == 0)
+ {
+ uint32_t rq_addr = 0x10030000;
+ int fd;
+ int pgsize;
+
+ pgsize = getpagesize();
+ fd = open ("/dev/mem", O_RDONLY | O_SYNC, 0);
+ if (fd < 0) {
+ perror("open");
+ return NULL;
+ }
+ addr = mmap(0, pgsize, PROT_READ, MAP_SHARED, fd, rq_addr);
+ close(fd);
+ if (addr == (uint64_t *)-1) {
+ perror("mmap");
+ return NULL;
+ }
+ }
+
+ return *addr;
+}
+
+INLINE_ELAPSED(inline)
+
+#define HAVE_TICK_COUNTER
+#endif
+#endif /* HAVE_MIPS_ZBUS_TIMER */