Chris@42
|
1 /*
|
Chris@42
|
2 * Copyright (c) 2003, 2007-14 Matteo Frigo
|
Chris@42
|
3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
|
Chris@42
|
4 *
|
Chris@42
|
5 * Permission is hereby granted, free of charge, to any person obtaining
|
Chris@42
|
6 * a copy of this software and associated documentation files (the
|
Chris@42
|
7 * "Software"), to deal in the Software without restriction, including
|
Chris@42
|
8 * without limitation the rights to use, copy, modify, merge, publish,
|
Chris@42
|
9 * distribute, sublicense, and/or sell copies of the Software, and to
|
Chris@42
|
10 * permit persons to whom the Software is furnished to do so, subject to
|
Chris@42
|
11 * the following conditions:
|
Chris@42
|
12 *
|
Chris@42
|
13 * The above copyright notice and this permission notice shall be
|
Chris@42
|
14 * included in all copies or substantial portions of the Software.
|
Chris@42
|
15 *
|
Chris@42
|
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@42
|
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@42
|
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@42
|
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
Chris@42
|
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
Chris@42
|
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@42
|
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@42
|
23 *
|
Chris@42
|
24 */
|
Chris@42
|
25
|
Chris@42
|
26
|
Chris@42
|
27 /* machine-dependent cycle counters code. Needs to be inlined. */
|
Chris@42
|
28
|
Chris@42
|
29 /***************************************************************************/
|
Chris@42
|
30 /* To use the cycle counters in your code, simply #include "cycle.h" (this
|
Chris@42
|
31 file), and then use the functions/macros:
|
Chris@42
|
32
|
Chris@42
|
33 ticks getticks(void);
|
Chris@42
|
34
|
Chris@42
|
35 ticks is an opaque typedef defined below, representing the current time.
|
Chris@42
|
36 You extract the elapsed time between two calls to gettick() via:
|
Chris@42
|
37
|
Chris@42
|
38 double elapsed(ticks t1, ticks t0);
|
Chris@42
|
39
|
Chris@42
|
40 which returns a double-precision variable in arbitrary units. You
|
Chris@42
|
41 are not expected to convert this into human units like seconds; it
|
Chris@42
|
42 is intended only for *comparisons* of time intervals.
|
Chris@42
|
43
|
Chris@42
|
44 (In order to use some of the OS-dependent timer routines like
|
Chris@42
|
45 Solaris' gethrtime, you need to paste the autoconf snippet below
|
Chris@42
|
46 into your configure.ac file and #include "config.h" before cycle.h,
|
Chris@42
|
47 or define the relevant macros manually if you are not using autoconf.)
|
Chris@42
|
48 */
|
Chris@42
|
49
|
Chris@42
|
50 /***************************************************************************/
|
Chris@42
|
51 /* This file uses macros like HAVE_GETHRTIME that are assumed to be
|
Chris@42
|
52 defined according to whether the corresponding function/type/header
|
Chris@42
|
53 is available on your system. The necessary macros are most
|
Chris@42
|
54 conveniently defined if you are using GNU autoconf, via the tests:
|
Chris@42
|
55
|
Chris@42
|
56 dnl ---------------------------------------------------------------------
|
Chris@42
|
57
|
Chris@42
|
58 AC_C_INLINE
|
Chris@42
|
59 AC_HEADER_TIME
|
Chris@42
|
60 AC_CHECK_HEADERS([sys/time.h c_asm.h intrinsics.h mach/mach_time.h])
|
Chris@42
|
61
|
Chris@42
|
62 AC_CHECK_TYPE([hrtime_t],[AC_DEFINE(HAVE_HRTIME_T, 1, [Define to 1 if hrtime_t is defined in <sys/time.h>])],,[#if HAVE_SYS_TIME_H
|
Chris@42
|
63 #include <sys/time.h>
|
Chris@42
|
64 #endif])
|
Chris@42
|
65
|
Chris@42
|
66 AC_CHECK_FUNCS([gethrtime read_real_time time_base_to_time clock_gettime mach_absolute_time])
|
Chris@42
|
67
|
Chris@42
|
68 dnl Cray UNICOS _rtc() (real-time clock) intrinsic
|
Chris@42
|
69 AC_MSG_CHECKING([for _rtc intrinsic])
|
Chris@42
|
70 rtc_ok=yes
|
Chris@42
|
71 AC_TRY_LINK([#ifdef HAVE_INTRINSICS_H
|
Chris@42
|
72 #include <intrinsics.h>
|
Chris@42
|
73 #endif], [_rtc()], [AC_DEFINE(HAVE__RTC,1,[Define if you have the UNICOS _rtc() intrinsic.])], [rtc_ok=no])
|
Chris@42
|
74 AC_MSG_RESULT($rtc_ok)
|
Chris@42
|
75
|
Chris@42
|
76 dnl ---------------------------------------------------------------------
|
Chris@42
|
77 */
|
Chris@42
|
78
|
Chris@42
|
79 /***************************************************************************/
|
Chris@42
|
80
|
Chris@42
|
81 #if TIME_WITH_SYS_TIME
|
Chris@42
|
82 # include <sys/time.h>
|
Chris@42
|
83 # include <time.h>
|
Chris@42
|
84 #else
|
Chris@42
|
85 # if HAVE_SYS_TIME_H
|
Chris@42
|
86 # include <sys/time.h>
|
Chris@42
|
87 # else
|
Chris@42
|
88 # include <time.h>
|
Chris@42
|
89 # endif
|
Chris@42
|
90 #endif
|
Chris@42
|
91
|
Chris@42
|
92 #define INLINE_ELAPSED(INL) static INL double elapsed(ticks t1, ticks t0) \
|
Chris@42
|
93 { \
|
Chris@42
|
94 return (double)t1 - (double)t0; \
|
Chris@42
|
95 }
|
Chris@42
|
96
|
Chris@42
|
97 /*----------------------------------------------------------------*/
|
Chris@42
|
98 /* Solaris */
|
Chris@42
|
99 #if defined(HAVE_GETHRTIME) && defined(HAVE_HRTIME_T) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
100 typedef hrtime_t ticks;
|
Chris@42
|
101
|
Chris@42
|
102 #define getticks gethrtime
|
Chris@42
|
103
|
Chris@42
|
104 INLINE_ELAPSED(inline)
|
Chris@42
|
105
|
Chris@42
|
106 #define HAVE_TICK_COUNTER
|
Chris@42
|
107 #endif
|
Chris@42
|
108
|
Chris@42
|
109 /*----------------------------------------------------------------*/
|
Chris@42
|
110 /* AIX v. 4+ routines to read the real-time clock or time-base register */
|
Chris@42
|
111 #if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
112 typedef timebasestruct_t ticks;
|
Chris@42
|
113
|
Chris@42
|
114 static __inline ticks getticks(void)
|
Chris@42
|
115 {
|
Chris@42
|
116 ticks t;
|
Chris@42
|
117 read_real_time(&t, TIMEBASE_SZ);
|
Chris@42
|
118 return t;
|
Chris@42
|
119 }
|
Chris@42
|
120
|
Chris@42
|
121 static __inline double elapsed(ticks t1, ticks t0) /* time in nanoseconds */
|
Chris@42
|
122 {
|
Chris@42
|
123 time_base_to_time(&t1, TIMEBASE_SZ);
|
Chris@42
|
124 time_base_to_time(&t0, TIMEBASE_SZ);
|
Chris@42
|
125 return (((double)t1.tb_high - (double)t0.tb_high) * 1.0e9 +
|
Chris@42
|
126 ((double)t1.tb_low - (double)t0.tb_low));
|
Chris@42
|
127 }
|
Chris@42
|
128
|
Chris@42
|
129 #define HAVE_TICK_COUNTER
|
Chris@42
|
130 #endif
|
Chris@42
|
131
|
Chris@42
|
132 /*----------------------------------------------------------------*/
|
Chris@42
|
133 /*
|
Chris@42
|
134 * PowerPC ``cycle'' counter using the time base register.
|
Chris@42
|
135 */
|
Chris@42
|
136 #if ((((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh)))) || (defined(__IBM_GCC_ASM) && (defined(__powerpc__) || defined(__ppc__)))) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
137 typedef unsigned long long ticks;
|
Chris@42
|
138
|
Chris@42
|
139 static __inline__ ticks getticks(void)
|
Chris@42
|
140 {
|
Chris@42
|
141 unsigned int tbl, tbu0, tbu1;
|
Chris@42
|
142
|
Chris@42
|
143 do {
|
Chris@42
|
144 __asm__ __volatile__ ("mftbu %0" : "=r"(tbu0));
|
Chris@42
|
145 __asm__ __volatile__ ("mftb %0" : "=r"(tbl));
|
Chris@42
|
146 __asm__ __volatile__ ("mftbu %0" : "=r"(tbu1));
|
Chris@42
|
147 } while (tbu0 != tbu1);
|
Chris@42
|
148
|
Chris@42
|
149 return (((unsigned long long)tbu0) << 32) | tbl;
|
Chris@42
|
150 }
|
Chris@42
|
151
|
Chris@42
|
152 INLINE_ELAPSED(__inline__)
|
Chris@42
|
153
|
Chris@42
|
154 #define HAVE_TICK_COUNTER
|
Chris@42
|
155 #endif
|
Chris@42
|
156
|
Chris@42
|
157 /* MacOS/Mach (Darwin) time-base register interface (unlike UpTime,
|
Chris@42
|
158 from Carbon, requires no additional libraries to be linked). */
|
Chris@42
|
159 #if defined(HAVE_MACH_ABSOLUTE_TIME) && defined(HAVE_MACH_MACH_TIME_H) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
160 #include <mach/mach_time.h>
|
Chris@42
|
161 typedef uint64_t ticks;
|
Chris@42
|
162 #define getticks mach_absolute_time
|
Chris@42
|
163 INLINE_ELAPSED(__inline__)
|
Chris@42
|
164 #define HAVE_TICK_COUNTER
|
Chris@42
|
165 #endif
|
Chris@42
|
166
|
Chris@42
|
167 /*----------------------------------------------------------------*/
|
Chris@42
|
168 /*
|
Chris@42
|
169 * Pentium cycle counter
|
Chris@42
|
170 */
|
Chris@42
|
171 #if (defined(__GNUC__) || defined(__ICC)) && defined(__i386__) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
172 typedef unsigned long long ticks;
|
Chris@42
|
173
|
Chris@42
|
174 static __inline__ ticks getticks(void)
|
Chris@42
|
175 {
|
Chris@42
|
176 ticks ret;
|
Chris@42
|
177
|
Chris@42
|
178 __asm__ __volatile__("rdtsc": "=A" (ret));
|
Chris@42
|
179 /* no input, nothing else clobbered */
|
Chris@42
|
180 return ret;
|
Chris@42
|
181 }
|
Chris@42
|
182
|
Chris@42
|
183 INLINE_ELAPSED(__inline__)
|
Chris@42
|
184
|
Chris@42
|
185 #define HAVE_TICK_COUNTER
|
Chris@42
|
186 #define TIME_MIN 5000.0 /* unreliable pentium IV cycle counter */
|
Chris@42
|
187 #endif
|
Chris@42
|
188
|
Chris@42
|
189 /* Visual C++ -- thanks to Morten Nissov for his help with this */
|
Chris@42
|
190 #if _MSC_VER >= 1200 && _M_IX86 >= 500 && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
191 #include <windows.h>
|
Chris@42
|
192 typedef LARGE_INTEGER ticks;
|
Chris@42
|
193 #define RDTSC __asm __emit 0fh __asm __emit 031h /* hack for VC++ 5.0 */
|
Chris@42
|
194
|
Chris@42
|
195 static __inline ticks getticks(void)
|
Chris@42
|
196 {
|
Chris@42
|
197 ticks retval;
|
Chris@42
|
198
|
Chris@42
|
199 __asm {
|
Chris@42
|
200 RDTSC
|
Chris@42
|
201 mov retval.HighPart, edx
|
Chris@42
|
202 mov retval.LowPart, eax
|
Chris@42
|
203 }
|
Chris@42
|
204 return retval;
|
Chris@42
|
205 }
|
Chris@42
|
206
|
Chris@42
|
207 static __inline double elapsed(ticks t1, ticks t0)
|
Chris@42
|
208 {
|
Chris@42
|
209 return (double)t1.QuadPart - (double)t0.QuadPart;
|
Chris@42
|
210 }
|
Chris@42
|
211
|
Chris@42
|
212 #define HAVE_TICK_COUNTER
|
Chris@42
|
213 #define TIME_MIN 5000.0 /* unreliable pentium IV cycle counter */
|
Chris@42
|
214 #endif
|
Chris@42
|
215
|
Chris@42
|
216 /*----------------------------------------------------------------*/
|
Chris@42
|
217 /*
|
Chris@42
|
218 * X86-64 cycle counter
|
Chris@42
|
219 */
|
Chris@42
|
220 #if (defined(__GNUC__) || defined(__ICC) || defined(__SUNPRO_C)) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
221 typedef unsigned long long ticks;
|
Chris@42
|
222
|
Chris@42
|
223 static __inline__ ticks getticks(void)
|
Chris@42
|
224 {
|
Chris@42
|
225 unsigned a, d;
|
Chris@42
|
226 asm volatile("rdtsc" : "=a" (a), "=d" (d));
|
Chris@42
|
227 return ((ticks)a) | (((ticks)d) << 32);
|
Chris@42
|
228 }
|
Chris@42
|
229
|
Chris@42
|
230 INLINE_ELAPSED(__inline__)
|
Chris@42
|
231
|
Chris@42
|
232 #define HAVE_TICK_COUNTER
|
Chris@42
|
233 #define TIME_MIN 5000.0
|
Chris@42
|
234 #endif
|
Chris@42
|
235
|
Chris@42
|
236 /* PGI compiler, courtesy Cristiano Calonaci, Andrea Tarsi, & Roberto Gori.
|
Chris@42
|
237 NOTE: this code will fail to link unless you use the -Masmkeyword compiler
|
Chris@42
|
238 option (grrr). */
|
Chris@42
|
239 #if defined(__PGI) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
240 typedef unsigned long long ticks;
|
Chris@42
|
241 static ticks getticks(void)
|
Chris@42
|
242 {
|
Chris@42
|
243 asm(" rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; ");
|
Chris@42
|
244 }
|
Chris@42
|
245 INLINE_ELAPSED(__inline__)
|
Chris@42
|
246 #define HAVE_TICK_COUNTER
|
Chris@42
|
247 #define TIME_MIN 5000.0
|
Chris@42
|
248 #endif
|
Chris@42
|
249
|
Chris@42
|
250 /* Visual C++, courtesy of Dirk Michaelis */
|
Chris@42
|
251 #if _MSC_VER >= 1400 && (defined(_M_AMD64) || defined(_M_X64)) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
252
|
Chris@42
|
253 #include <intrin.h>
|
Chris@42
|
254 #pragma intrinsic(__rdtsc)
|
Chris@42
|
255 typedef unsigned __int64 ticks;
|
Chris@42
|
256 #define getticks __rdtsc
|
Chris@42
|
257 INLINE_ELAPSED(__inline)
|
Chris@42
|
258
|
Chris@42
|
259 #define HAVE_TICK_COUNTER
|
Chris@42
|
260 #define TIME_MIN 5000.0
|
Chris@42
|
261 #endif
|
Chris@42
|
262
|
Chris@42
|
263 /*----------------------------------------------------------------*/
|
Chris@42
|
264 /*
|
Chris@42
|
265 * IA64 cycle counter
|
Chris@42
|
266 */
|
Chris@42
|
267
|
Chris@42
|
268 /* intel's icc/ecc compiler */
|
Chris@42
|
269 #if (defined(__EDG_VERSION) || defined(__ECC)) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
270 typedef unsigned long ticks;
|
Chris@42
|
271 #include <ia64intrin.h>
|
Chris@42
|
272
|
Chris@42
|
273 static __inline__ ticks getticks(void)
|
Chris@42
|
274 {
|
Chris@42
|
275 return __getReg(_IA64_REG_AR_ITC);
|
Chris@42
|
276 }
|
Chris@42
|
277
|
Chris@42
|
278 INLINE_ELAPSED(__inline__)
|
Chris@42
|
279
|
Chris@42
|
280 #define HAVE_TICK_COUNTER
|
Chris@42
|
281 #endif
|
Chris@42
|
282
|
Chris@42
|
283 /* gcc */
|
Chris@42
|
284 #if defined(__GNUC__) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
285 typedef unsigned long ticks;
|
Chris@42
|
286
|
Chris@42
|
287 static __inline__ ticks getticks(void)
|
Chris@42
|
288 {
|
Chris@42
|
289 ticks ret;
|
Chris@42
|
290
|
Chris@42
|
291 __asm__ __volatile__ ("mov %0=ar.itc" : "=r"(ret));
|
Chris@42
|
292 return ret;
|
Chris@42
|
293 }
|
Chris@42
|
294
|
Chris@42
|
295 INLINE_ELAPSED(__inline__)
|
Chris@42
|
296
|
Chris@42
|
297 #define HAVE_TICK_COUNTER
|
Chris@42
|
298 #endif
|
Chris@42
|
299
|
Chris@42
|
300 /* HP/UX IA64 compiler, courtesy Teresa L. Johnson: */
|
Chris@42
|
301 #if defined(__hpux) && defined(__ia64) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
302 #include <machine/sys/inline.h>
|
Chris@42
|
303 typedef unsigned long ticks;
|
Chris@42
|
304
|
Chris@42
|
305 static inline ticks getticks(void)
|
Chris@42
|
306 {
|
Chris@42
|
307 ticks ret;
|
Chris@42
|
308
|
Chris@42
|
309 ret = _Asm_mov_from_ar (_AREG_ITC);
|
Chris@42
|
310 return ret;
|
Chris@42
|
311 }
|
Chris@42
|
312
|
Chris@42
|
313 INLINE_ELAPSED(inline)
|
Chris@42
|
314
|
Chris@42
|
315 #define HAVE_TICK_COUNTER
|
Chris@42
|
316 #endif
|
Chris@42
|
317
|
Chris@42
|
318 /* Microsoft Visual C++ */
|
Chris@42
|
319 #if defined(_MSC_VER) && defined(_M_IA64) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
320 typedef unsigned __int64 ticks;
|
Chris@42
|
321
|
Chris@42
|
322 # ifdef __cplusplus
|
Chris@42
|
323 extern "C"
|
Chris@42
|
324 # endif
|
Chris@42
|
325 ticks __getReg(int whichReg);
|
Chris@42
|
326 #pragma intrinsic(__getReg)
|
Chris@42
|
327
|
Chris@42
|
328 static __inline ticks getticks(void)
|
Chris@42
|
329 {
|
Chris@42
|
330 volatile ticks temp;
|
Chris@42
|
331 temp = __getReg(3116);
|
Chris@42
|
332 return temp;
|
Chris@42
|
333 }
|
Chris@42
|
334
|
Chris@42
|
335 INLINE_ELAPSED(inline)
|
Chris@42
|
336
|
Chris@42
|
337 #define HAVE_TICK_COUNTER
|
Chris@42
|
338 #endif
|
Chris@42
|
339
|
Chris@42
|
340 /*----------------------------------------------------------------*/
|
Chris@42
|
341 /*
|
Chris@42
|
342 * PA-RISC cycle counter
|
Chris@42
|
343 */
|
Chris@42
|
344 #if (defined(__hppa__) || defined(__hppa)) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
345 typedef unsigned long ticks;
|
Chris@42
|
346
|
Chris@42
|
347 # ifdef __GNUC__
|
Chris@42
|
348 static __inline__ ticks getticks(void)
|
Chris@42
|
349 {
|
Chris@42
|
350 ticks ret;
|
Chris@42
|
351
|
Chris@42
|
352 __asm__ __volatile__("mfctl 16, %0": "=r" (ret));
|
Chris@42
|
353 /* no input, nothing else clobbered */
|
Chris@42
|
354 return ret;
|
Chris@42
|
355 }
|
Chris@42
|
356 # else
|
Chris@42
|
357 # include <machine/inline.h>
|
Chris@42
|
358 static inline unsigned long getticks(void)
|
Chris@42
|
359 {
|
Chris@42
|
360 register ticks ret;
|
Chris@42
|
361 _MFCTL(16, ret);
|
Chris@42
|
362 return ret;
|
Chris@42
|
363 }
|
Chris@42
|
364 # endif
|
Chris@42
|
365
|
Chris@42
|
366 INLINE_ELAPSED(inline)
|
Chris@42
|
367
|
Chris@42
|
368 #define HAVE_TICK_COUNTER
|
Chris@42
|
369 #endif
|
Chris@42
|
370
|
Chris@42
|
371 /*----------------------------------------------------------------*/
|
Chris@42
|
372 /* S390, courtesy of James Treacy */
|
Chris@42
|
373 #if defined(__GNUC__) && defined(__s390__) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
374 typedef unsigned long long ticks;
|
Chris@42
|
375
|
Chris@42
|
376 static __inline__ ticks getticks(void)
|
Chris@42
|
377 {
|
Chris@42
|
378 ticks cycles;
|
Chris@42
|
379 __asm__("stck 0(%0)" : : "a" (&(cycles)) : "memory", "cc");
|
Chris@42
|
380 return cycles;
|
Chris@42
|
381 }
|
Chris@42
|
382
|
Chris@42
|
383 INLINE_ELAPSED(__inline__)
|
Chris@42
|
384
|
Chris@42
|
385 #define HAVE_TICK_COUNTER
|
Chris@42
|
386 #endif
|
Chris@42
|
387 /*----------------------------------------------------------------*/
|
Chris@42
|
388 #if defined(__GNUC__) && defined(__alpha__) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
389 /*
|
Chris@42
|
390 * The 32-bit cycle counter on alpha overflows pretty quickly,
|
Chris@42
|
391 * unfortunately. A 1GHz machine overflows in 4 seconds.
|
Chris@42
|
392 */
|
Chris@42
|
393 typedef unsigned int ticks;
|
Chris@42
|
394
|
Chris@42
|
395 static __inline__ ticks getticks(void)
|
Chris@42
|
396 {
|
Chris@42
|
397 unsigned long cc;
|
Chris@42
|
398 __asm__ __volatile__ ("rpcc %0" : "=r"(cc));
|
Chris@42
|
399 return (cc & 0xFFFFFFFF);
|
Chris@42
|
400 }
|
Chris@42
|
401
|
Chris@42
|
402 INLINE_ELAPSED(__inline__)
|
Chris@42
|
403
|
Chris@42
|
404 #define HAVE_TICK_COUNTER
|
Chris@42
|
405 #endif
|
Chris@42
|
406
|
Chris@42
|
407 /*----------------------------------------------------------------*/
|
Chris@42
|
408 #if defined(__GNUC__) && defined(__sparc_v9__) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
409 typedef unsigned long ticks;
|
Chris@42
|
410
|
Chris@42
|
411 static __inline__ ticks getticks(void)
|
Chris@42
|
412 {
|
Chris@42
|
413 ticks ret;
|
Chris@42
|
414 __asm__ __volatile__("rd %%tick, %0" : "=r" (ret));
|
Chris@42
|
415 return ret;
|
Chris@42
|
416 }
|
Chris@42
|
417
|
Chris@42
|
418 INLINE_ELAPSED(__inline__)
|
Chris@42
|
419
|
Chris@42
|
420 #define HAVE_TICK_COUNTER
|
Chris@42
|
421 #endif
|
Chris@42
|
422
|
Chris@42
|
423 /*----------------------------------------------------------------*/
|
Chris@42
|
424 #if (defined(__DECC) || defined(__DECCXX)) && defined(__alpha) && defined(HAVE_C_ASM_H) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
425 # include <c_asm.h>
|
Chris@42
|
426 typedef unsigned int ticks;
|
Chris@42
|
427
|
Chris@42
|
428 static __inline ticks getticks(void)
|
Chris@42
|
429 {
|
Chris@42
|
430 unsigned long cc;
|
Chris@42
|
431 cc = asm("rpcc %v0");
|
Chris@42
|
432 return (cc & 0xFFFFFFFF);
|
Chris@42
|
433 }
|
Chris@42
|
434
|
Chris@42
|
435 INLINE_ELAPSED(__inline)
|
Chris@42
|
436
|
Chris@42
|
437 #define HAVE_TICK_COUNTER
|
Chris@42
|
438 #endif
|
Chris@42
|
439 /*----------------------------------------------------------------*/
|
Chris@42
|
440 /* SGI/Irix */
|
Chris@42
|
441 #if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
442 typedef struct timespec ticks;
|
Chris@42
|
443
|
Chris@42
|
444 static inline ticks getticks(void)
|
Chris@42
|
445 {
|
Chris@42
|
446 struct timespec t;
|
Chris@42
|
447 clock_gettime(CLOCK_SGI_CYCLE, &t);
|
Chris@42
|
448 return t;
|
Chris@42
|
449 }
|
Chris@42
|
450
|
Chris@42
|
451 static inline double elapsed(ticks t1, ticks t0)
|
Chris@42
|
452 {
|
Chris@42
|
453 return ((double)t1.tv_sec - (double)t0.tv_sec) * 1.0E9 +
|
Chris@42
|
454 ((double)t1.tv_nsec - (double)t0.tv_nsec);
|
Chris@42
|
455 }
|
Chris@42
|
456 #define HAVE_TICK_COUNTER
|
Chris@42
|
457 #endif
|
Chris@42
|
458
|
Chris@42
|
459 /*----------------------------------------------------------------*/
|
Chris@42
|
460 /* Cray UNICOS _rtc() intrinsic function */
|
Chris@42
|
461 #if defined(HAVE__RTC) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
462 #ifdef HAVE_INTRINSICS_H
|
Chris@42
|
463 # include <intrinsics.h>
|
Chris@42
|
464 #endif
|
Chris@42
|
465
|
Chris@42
|
466 typedef long long ticks;
|
Chris@42
|
467
|
Chris@42
|
468 #define getticks _rtc
|
Chris@42
|
469
|
Chris@42
|
470 INLINE_ELAPSED(inline)
|
Chris@42
|
471
|
Chris@42
|
472 #define HAVE_TICK_COUNTER
|
Chris@42
|
473 #endif
|
Chris@42
|
474
|
Chris@42
|
475 /*----------------------------------------------------------------*/
|
Chris@42
|
476 /* MIPS ZBus */
|
Chris@42
|
477 #if HAVE_MIPS_ZBUS_TIMER
|
Chris@42
|
478 #if defined(__mips__) && !defined(HAVE_TICK_COUNTER)
|
Chris@42
|
479 #include <sys/mman.h>
|
Chris@42
|
480 #include <unistd.h>
|
Chris@42
|
481 #include <fcntl.h>
|
Chris@42
|
482
|
Chris@42
|
483 typedef uint64_t ticks;
|
Chris@42
|
484
|
Chris@42
|
485 static inline ticks getticks(void)
|
Chris@42
|
486 {
|
Chris@42
|
487 static uint64_t* addr = 0;
|
Chris@42
|
488
|
Chris@42
|
489 if (addr == 0)
|
Chris@42
|
490 {
|
Chris@42
|
491 uint32_t rq_addr = 0x10030000;
|
Chris@42
|
492 int fd;
|
Chris@42
|
493 int pgsize;
|
Chris@42
|
494
|
Chris@42
|
495 pgsize = getpagesize();
|
Chris@42
|
496 fd = open ("/dev/mem", O_RDONLY | O_SYNC, 0);
|
Chris@42
|
497 if (fd < 0) {
|
Chris@42
|
498 perror("open");
|
Chris@42
|
499 return NULL;
|
Chris@42
|
500 }
|
Chris@42
|
501 addr = mmap(0, pgsize, PROT_READ, MAP_SHARED, fd, rq_addr);
|
Chris@42
|
502 close(fd);
|
Chris@42
|
503 if (addr == (uint64_t *)-1) {
|
Chris@42
|
504 perror("mmap");
|
Chris@42
|
505 return NULL;
|
Chris@42
|
506 }
|
Chris@42
|
507 }
|
Chris@42
|
508
|
Chris@42
|
509 return *addr;
|
Chris@42
|
510 }
|
Chris@42
|
511
|
Chris@42
|
512 INLINE_ELAPSED(inline)
|
Chris@42
|
513
|
Chris@42
|
514 #define HAVE_TICK_COUNTER
|
Chris@42
|
515 #endif
|
Chris@42
|
516 #endif /* HAVE_MIPS_ZBUS_TIMER */
|
Chris@42
|
517
|
Chris@42
|
518 #if defined(__ARM_ARCH_7A__) && defined(ARMV7A_HAS_CNTCVT)
|
Chris@42
|
519 typedef uint64_t ticks;
|
Chris@42
|
520 static inline ticks getticks(void)
|
Chris@42
|
521 {
|
Chris@42
|
522 uint32_t Rt, Rt2 = 0;
|
Chris@42
|
523 asm volatile("mrrc p15, 1, %0, %1, c14" : "=r"(Rt), "=r"(Rt2));
|
Chris@42
|
524 return ((uint64_t)Rt) | (((uint64_t)Rt2) << 32);
|
Chris@42
|
525 }
|
Chris@42
|
526 INLINE_ELAPSED(inline)
|
Chris@42
|
527 #define HAVE_TICK_COUNTER
|
Chris@42
|
528 #endif
|
Chris@42
|
529
|
Chris@42
|
530 #if defined(__aarch64__) && defined(ARMV8_HAS_CNTCVT_EL0) && !defined(HAVE_ARMV8CC)
|
Chris@42
|
531 typedef uint64_t ticks;
|
Chris@42
|
532 static inline ticks getticks(void)
|
Chris@42
|
533 {
|
Chris@42
|
534 uint64_t Rt;
|
Chris@42
|
535 asm volatile("mrs %0, CNTVCT_EL0" : "=r" (Rt));
|
Chris@42
|
536 return Rt;
|
Chris@42
|
537 }
|
Chris@42
|
538 INLINE_ELAPSED(inline)
|
Chris@42
|
539 #define HAVE_TICK_COUNTER
|
Chris@42
|
540 #endif
|
Chris@42
|
541
|
Chris@42
|
542 #if defined(__aarch64__) && defined(HAVE_ARMV8CC)
|
Chris@42
|
543 typedef uint64_t ticks;
|
Chris@42
|
544 static inline ticks getticks(void)
|
Chris@42
|
545 {
|
Chris@42
|
546 uint64_t cc = 0;
|
Chris@42
|
547 asm volatile("mrs %0, PMCCNTR_EL0" : "=r"(cc));
|
Chris@42
|
548 return cc;
|
Chris@42
|
549 }
|
Chris@42
|
550 INLINE_ELAPSED(inline)
|
Chris@42
|
551 #define HAVE_TICK_COUNTER
|
Chris@42
|
552 #endif
|