[2015] | 1 | // ===========================================================================
|
---|
| 2 | // (C) 1999 Vienna University of Technology
|
---|
| 3 | // ===========================================================================
|
---|
| 4 | // NAME: RDTSCTimer
|
---|
| 5 | // TYPE: c++ header
|
---|
| 6 | // PROJECT: Urban Viz/yare (yet another rendering engine)
|
---|
| 7 | // CONTENT: Very accurate timer for Win32 systems
|
---|
| 8 | // (uses Pentium clock cycle counter, usually microseconds)
|
---|
| 9 | // VERSION: 0.1
|
---|
| 10 | // ===========================================================================
|
---|
| 11 | // AUTHORS: mw Michael Wimmer
|
---|
| 12 | // ===========================================================================
|
---|
| 13 | // HISTORY:
|
---|
| 14 | //
|
---|
| 15 | // 15-jul-99 14:00:00 mw created
|
---|
| 16 | // ===========================================================================
|
---|
| 17 | // $Header: /usr/local/cvsyare/cvsyare/src/yareutils/RDTSCTimer.h,v 1.1 2002/09/24 16:53:56 wimmer Exp $
|
---|
| 18 | // ===========================================================================
|
---|
| 19 |
|
---|
| 20 | #ifndef NO_PRAGMA_ONCE
|
---|
| 21 | #pragma once
|
---|
| 22 | #endif
|
---|
| 23 |
|
---|
| 24 | #ifndef _RDTSCTIMER_H
|
---|
| 25 | #define _RDTSCTIMER_H
|
---|
| 26 |
|
---|
| 27 | // use outdated RDTSC instruction with opcodes and register backup, but without cpuid?
|
---|
| 28 | //#define OLD_RDTSC
|
---|
| 29 |
|
---|
| 30 | // use cpuid instruction to serialize execution
|
---|
| 31 | #define CPUID_RDTSC
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | #ifdef WIN32
|
---|
| 35 |
|
---|
| 36 | #if !(_MSC_VER >= 1200)
|
---|
| 37 | #define __forceinline inline
|
---|
| 38 | #endif
|
---|
| 39 |
|
---|
| 40 | // we definitely want timers to be inlined!
|
---|
| 41 | # define PERFTIMER_INLINE __forceinline
|
---|
| 42 |
|
---|
| 43 | // the time snapping instruction
|
---|
| 44 | #ifdef OLDRDTSC
|
---|
| 45 | #define RDTSC(_VAR) \
|
---|
| 46 | _asm { \
|
---|
| 47 | _asm push eax \
|
---|
| 48 | _asm push edx \
|
---|
| 49 | _asm _emit 0Fh \
|
---|
| 50 | _asm _emit 31h \
|
---|
| 51 | _asm mov _VAR.LowPart, eax \
|
---|
| 52 | _asm mov _VAR.HighPart, edx \
|
---|
| 53 | _asm pop edx \
|
---|
| 54 | _asm pop eax \
|
---|
| 55 | }
|
---|
| 56 | #else
|
---|
| 57 | #ifdef CPUID_RDTSC
|
---|
| 58 | #define RDTSC(_VAR) \
|
---|
| 59 | _asm { \
|
---|
| 60 | _asm xor eax, eax \
|
---|
| 61 | _asm cpuid \
|
---|
| 62 | _asm rdtsc \
|
---|
| 63 | _asm mov _VAR.LowPart, eax \
|
---|
| 64 | _asm mov _VAR.HighPart, edx \
|
---|
| 65 | }
|
---|
| 66 | #else
|
---|
| 67 | #define RDTSC(_VAR) \
|
---|
| 68 | _asm { \
|
---|
| 69 | _asm rdtsc \
|
---|
| 70 | _asm mov _VAR.LowPart, eax \
|
---|
| 71 | _asm mov _VAR.HighPart, edx \
|
---|
| 72 | }
|
---|
| 73 | #endif
|
---|
| 74 | #endif
|
---|
| 75 |
|
---|
| 76 | #ifndef WIN32_LEAN_AND_MEAN
|
---|
| 77 | #define WIN32_LEAN_AND_MEAN
|
---|
| 78 | #define NOMINMAX
|
---|
| 79 | #include <windows.h> // for LARGE_INTEGER
|
---|
| 80 | #endif
|
---|
| 81 |
|
---|
| 82 | #define PERFTIMER RDTSCTimer
|
---|
| 83 |
|
---|
| 84 | #define TIMEVAL_T LARGE_INTEGER
|
---|
| 85 | #define TIMEVAL_ZERO(__timval) (__timval).QuadPart = 0;
|
---|
| 86 | #define TIMEVAL_GET(__timval) { TIMEVAL_T temp; RDTSC(temp); __timval = temp; }
|
---|
| 87 | #define TIMEVAL_TODOUBLE(__timval) ((double)__timval.QuadPart / (double)frequency.QuadPart)
|
---|
| 88 | #define TIMEVAL_ASSIGN(__timval1, __timval2) __timval1.QuadPart = __timval2.QuadPart;
|
---|
| 89 |
|
---|
| 90 | #define TIMEVAL_ADD(total, end, start) \
|
---|
| 91 | if (end.QuadPart > start.QuadPart) \
|
---|
| 92 | total.QuadPart += end.QuadPart - start.QuadPart; \
|
---|
| 93 | else \
|
---|
| 94 | total.QuadPart += MAXLONGLONG - end.QuadPart + start.QuadPart;
|
---|
| 95 |
|
---|
| 96 | #include "PerfTimerSkeleton.h"
|
---|
| 97 |
|
---|
| 98 | #else
|
---|
| 99 | #define DUMMY_TIMER
|
---|
| 100 | #include "PerfTimerSkeleton.h"
|
---|
| 101 | #undef DUMMY_TIMER
|
---|
| 102 | #endif
|
---|
| 103 |
|
---|
| 104 | #undef PERFTIMER
|
---|
| 105 | #undef TIMEVAL_ZERO
|
---|
| 106 | #undef TIMEVAL_TODOUBLE
|
---|
| 107 | #undef TIMEVAL_ASSIGN
|
---|
| 108 | // still need these for macro versions
|
---|
| 109 | //#undef TIMEVAL_GET
|
---|
| 110 | //#undef TIMEVAL_ADD
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | #endif |
---|