annotate fft/fftw/fftw-3.3.4/kernel/cycle.h @ 40:223f770b5341 kissfft-double tip

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