Go to the documentation of this file.
21 #ifndef BENCHMARK_CYCLECLOCK_H_
22 #define BENCHMARK_CYCLECLOCK_H_
26 #include "benchmark/benchmark.h"
27 #include "internal_macros.h"
29 #if defined(BENCHMARK_OS_MACOSX)
30 #include <mach/mach_time.h>
39 #if defined(COMPILER_MSVC) && !defined(_M_IX86)
40 extern "C" uint64_t __rdtsc();
41 #pragma intrinsic(__rdtsc)
44 #if !defined(BENCHMARK_OS_WINDOWS) || defined(BENCHMARK_OS_MINGW)
49 #ifdef BENCHMARK_OS_EMSCRIPTEN
50 #include <emscripten.h>
59 namespace cycleclock {
61 inline BENCHMARK_ALWAYS_INLINE int64_t
Now() {
62 #if defined(BENCHMARK_OS_MACOSX)
72 return mach_absolute_time();
73 #elif defined(BENCHMARK_OS_EMSCRIPTEN)
76 return static_cast<int64_t
>(emscripten_get_now() * 1e+6);
77 #elif defined(__i386__)
79 __asm__
volatile(
"rdtsc" :
"=A"(ret));
81 #elif defined(__x86_64__) || defined(__amd64__)
83 __asm__
volatile(
"rdtsc" :
"=a"(low),
"=d"(high));
84 return (high << 32) | low;
85 #elif defined(__powerpc__) || defined(__ppc__)
87 int64_t tbl, tbu0, tbu1;
88 asm(
"mftbu %0" :
"=r"(tbu0));
89 asm(
"mftb %0" :
"=r"(tbl));
90 asm(
"mftbu %0" :
"=r"(tbu1));
91 tbl &= -
static_cast<int64_t
>(tbu0 == tbu1);
93 return (tbu1 << 32) | tbl;
94 #elif defined(__sparc__)
96 asm(
".byte 0x83, 0x41, 0x00, 0x00");
97 asm(
"mov %%g1, %0" :
"=r"(tick));
99 #elif defined(__ia64__)
101 asm(
"mov %0 = ar.itc" :
"=r"(itc));
103 #elif defined(COMPILER_MSVC) && defined(_M_IX86)
109 #elif defined(COMPILER_MSVC)
111 #elif defined(BENCHMARK_OS_NACL)
124 struct timespec ts = {0, 0};
126 return static_cast<int64_t
>(ts.tv_sec) * 1000000000 + ts.tv_nsec;
127 #elif defined(__aarch64__)
132 int64_t virtual_timer_value;
133 asm volatile(
"mrs %0, cntvct_el0" :
"=r"(virtual_timer_value));
134 return virtual_timer_value;
135 #elif defined(__ARM_ARCH)
138 #if (__ARM_ARCH >= 6)
143 asm volatile(
"mrc p15, 0, %0, c9, c14, 0" :
"=r"(pmuseren));
145 asm volatile(
"mrc p15, 0, %0, c9, c12, 1" :
"=r"(pmcntenset));
146 if (pmcntenset & 0x80000000ul) {
147 asm volatile(
"mrc p15, 0, %0, c9, c13, 0" :
"=r"(pmccntr));
149 return static_cast<int64_t
>(pmccntr) * 64;
154 gettimeofday(&tv,
nullptr);
155 return static_cast<int64_t
>(tv.tv_sec) * 1000000 + tv.tv_usec;
156 #elif defined(__mips__)
160 gettimeofday(&tv,
nullptr);
161 return static_cast<int64_t
>(tv.tv_sec) * 1000000 + tv.tv_usec;
162 #elif defined(__s390__)
165 asm(
"stck %0" :
"=Q"(tsc) : :
"cc");
171 #error You need to define CycleTimer for your OS and CPU
177 #endif // BENCHMARK_CYCLECLOCK_H_
OMEtype threadContext
Definition: OMEthread.h:77
void * threadStack
Definition: OMEthread.h:41
OMEtype thisMethod
Definition: OMEthread.h:36
static const OME_FAST_CALL OMEdefOIL2func * findFunction(const OMEstring &fName)
Definition: copyIntrp.cpp:64
int convertLocalRelativeTimeToAbsolute(OMEthread *thread, OMEtype &result, const OMEtype &, const OMEtype &)
Definition: OILtime.cpp:55
void * OMEoil2StackCreate(const OMEinvocationData *mInfo)
Creates a stack for an OIL2 method.
Definition: copyIntrp.cpp:39
void initializeAsType(const enum OMEtypes_t t)
The fundamental tagged data type used through the FARGOS/VISTA infrastructure.
Definition: OMEtype.cpp:95
Definition: cycleclock.h:53
const char * typeName() const NONNULL_RETURN
Definition: OMEbaseType.h:874
SMV_StandaloneNumeric< uint32_t > OMEdebugFlag("debugFlag")
bool OMEokToAssignTypes(uint32_t srcType, uint32_t targetType, OMEthread *t)
Definition: OMEthread.cpp:1260
@ OME_POINTER
Definition: OMEmanifests.h:92
#define CLOCK_MONOTONIC
Definition: tmp.o.cpp:46
OME_FAST_CALL int returnReply(const OMEtype &result)
Definition: OMEthread.cpp:730
void yieldSlice()
Definition: OMEthread.cpp:1112
void OMEoil2StackDelete(const OMEinvocationData *mInfo, void *data)
Deletes a stack associated with an OIL2 method.
Definition: copyIntrp.cpp:51
const OMEtype & getThisObject() const OME_ALWAYS_INLINE
Definition: OMEthread.h:152
OME_CORE_CALL int(* oneFP)(OMEthread *, OMEtype &, const OMEtype &)
Definition: OMEthread.h:256
OME_FAST_CALL int callMethodWithSetArgument(const OMEtype &methodName, const uint32_t hashIndx, const OMEtype &argSet)
Definition: OMEthread.cpp:678
Implements text and binary string storage.
Definition: OMEstring.h:305
OMEtype & OILnextIterator(int *rc, OMEtype &setVar)
Definition: OMEthread.cpp:1243
Fundamental ANY type for FARGOS/VISTA Object Management Environment.
Definition: OMEbaseType.h:250
void noteLineNumber(int line, const char *fileName=nullptr) OME_ALWAYS_INLINE
Definition: OMEthread.h:193
OME_CORE_CALL int(* twoFP)(OMEthread *, OMEtype &, const OMEtype &, const OMEtype &)
Definition: OMEthread.h:258
uint32_t getPC() const OME_ALWAYS_INLINE
Definition: OMEthread.h:169
OME_CORE_CALL int(* eightFP)(OMEthread *, OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &)
Definition: OMEthread.h:278
OME_CORE_CALL int(* fourFP)(OMEthread *, OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &)
Definition: OMEthread.h:264
class OMEstring * s
Definition: OMEbaseType.h:299
OMEtype argv
Definition: OMEthread.h:38
OMEdefOIL2func * next
Definition: OMEthread.h:290
OME_CORE_CALL int(* threeFP)(OMEthread *, OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &)
Definition: OMEthread.h:261
int32_t i
Definition: OMEbaseType.h:285
void outputOnStream(std::ostream &o=std::cout) const
Definition: OMEthread.cpp:1172
const char * sourceFileName
Definition: OMEthread.h:84
void exitRoutine()
Definition: OMEthread.cpp:1004
#define OMEdebugOIL2instructions
Definition: OMEdebugInfo.h:26
OMEstring functionName
Definition: OMEthread.h:299
void suspendThread()
Definition: OMEthread.cpp:1086
OME_CORE_CALL int(* zeroFP)(OMEthread *, OMEtype &)
Definition: OMEthread.h:254
OMEarray localGlobals
Definition: OMEmethod.h:55
bool replyStillPending() const OME_ALWAYS_INLINE
Definition: OMEthread.h:113
OMEtype argc
Definition: OMEthread.h:37
OMEarray constantTable
Definition: OMEmethod.h:54
const char srcID[]
Definition: catSym.c:17
@ OME_STRING
Definition: OMEmanifests.h:85
OME_FAST_CALL int generateException(uint_fast32_t argc, const OMEarray &argv) const
Definition: OMEthread.cpp:1197
OME_FAST_CALL int sendMessageWithSetArgument(const OMEtype &methodName, const uint32_t hashIndx, const OMEtype &argSet, const OMEtype &destObj, const OMEtype &fromObj, const int32_t timeout)
Definition: OMEthread.cpp:593
int sourceLineNumber
Definition: OMEthread.h:83
uint32_t stackSize
Definition: OMEmethod.h:46
OMEtype * pointer
Definition: OMEbaseType.h:302
@ OME_NIL
Definition: OMEmanifests.h:78
const OMEtype & getReplyOID()
Definition: OMEthread.h:125
OMEcallStack * callStack
Definition: OMEthread.h:74
const OMEtype & getReplyResult() const OME_ALWAYS_INLINE
Definition: OMEthread.h:177
static OMEdefOIL2func * listStart
Definition: OMEthread.h:289
int display(OMEthread *thread, OMEtype &result, const OMEtype &argSet)
Definition: OILdebug.cpp:112
int convertCase(OMEthread *thread, OMEtype &result, const OMEtype &, const OMEtype &)
Definition: OILtypeFuncs.cpp:780
uint32_t ui
Definition: OMEbaseType.h:286
OMEtype fromObject
Definition: OMEthread.h:78
const char srcID[] OME_USED
Definition: tick_time.cpp:24
OME_CORE_CALL int(* sevenFP)(OMEthread *, OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &)
Definition: OMEthread.h:274
Record to define the implementation of an OIL2 function.
Definition: OMEthread.h:287
Record to describe the implementation of the method of an OME class.
Definition: OMEmethod.h:35
int argCount
Definition: OMEthread.h:301
void setResultPending() OME_ALWAYS_INLINE
Definition: OMEthread.h:111
BENCHMARK_ALWAYS_INLINE int64_t Now()
Definition: cycleclock.h:61
OME_CORE_CALL int(* fiveFP)(OMEthread *, OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &)
Definition: OMEthread.h:267
Implements sparse array of OMEtype elements.
Definition: OMEarray.h:75
Public interface to an OME thread.
Definition: OMEthread.h:60
@ OME_ANY
Definition: OMEmanifests.h:93
void * function
Definition: OMEthread.h:300
OME_FAST_CALL void * getInstanceData() const
Definition: OMEthread.cpp:1036
uint32_t type
Definition: OMEbaseType.h:304
unsigned __int64 rdtsc()
Definition: IAPerf.h:101
OMEtype & OMEgetObjectCreatorOID(const OMEtype &userInfo)
Definition: OMEcreate.cpp:117
OME_CORE_CALL int(* sixFP)(OMEthread *, OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &, const OMEtype &)
Definition: OMEthread.h:270
@ OME_ARRAY
Definition: OMEmanifests.h:86
OME_FAST_CALL void setPC(uint32_t pc) OME_ALWAYS_INLINE
Definition: OMEthread.h:165
#define OMEtype
Definition: tmp.o.cpp:396
void resetIterator()
Reset the internal iterator to the beginning of the list.
Definition: OMEset.cpp:264
class OMEset * set
Definition: OMEbaseType.h:298
OMEtype threadErrorCode
Definition: OMEthread.h:81
const OMEtype & getUserID() const OME_ALWAYS_INLINE
Definition: OMEthread.h:146
@ OME_ASSOC
Definition: OMEmanifests.h:87
const OMEinvocationData * methodBody
Definition: OMEthread.h:34
void noteObjectModified() OME_ALWAYS_INLINE
Definition: OMEthread.h:191
@ OME_INT32
Definition: OMEmanifests.h:79
int OMEoil2Interpreter(OMEthread *thread, const OMEtype &codeBody)
Entry point for the OIL2 Architecture Neutral Format interpreter.
Definition: copyIntrp.cpp:288