[dasher] Avoid _asm RDTSC assembler
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher] Avoid _asm RDTSC assembler
- Date: Thu, 28 Feb 2013 17:04:38 +0000 (UTC)
commit 3cf4b54461607ef834e91b76132dce8f38983df4
Author: Patrick Welche <prlw1 cam ac uk>
Date: Thu Feb 28 14:17:04 2013 +0000
Avoid _asm RDTSC assembler
- it doesn't work on 64-bit architecture
- QueryPerformanceCounter() copes with variable CPU frequency / threads
moving between CPUs, and indeed may use a different hardware counter
altogether
Src/DasherCore/FileLogger.cpp | 31 +++++--------------------------
Src/DasherCore/FileLogger.h | 20 ++------------------
2 files changed, 7 insertions(+), 44 deletions(-)
---
diff --git a/Src/DasherCore/FileLogger.cpp b/Src/DasherCore/FileLogger.cpp
index b53851d..e02a346 100644
--- a/Src/DasherCore/FileLogger.cpp
+++ b/Src/DasherCore/FileLogger.cpp
@@ -15,11 +15,6 @@ static char THIS_FILE[] = __FILE__;
#endif
-
-#ifdef _WIN32
-#include <windows.h>
-#endif
-
#ifdef _WIN32
#include <sys/timeb.h>
#else
@@ -436,18 +431,9 @@ CFunctionLogger::CFunctionLogger(const std::string& strFunctionName, CFileLogger
if (!m_pLogger->GetFunctionTiming())
m_pLogger->LogFunctionEntry(m_strFunctionName);
else
- {
#ifdef _WIN32
- BigInt iStartTicks;
- _asm
- {
- RDTSC
- mov iStartTicks.int32val.i32[0], eax
- mov iStartTicks.int32val.i32[4], edx
- }
- m_iStartTicks = iStartTicks;
+ QueryPerformanceCounter(&m_iStartTicks);
#endif
- }
}
}
@@ -461,20 +447,13 @@ CFunctionLogger::~CFunctionLogger()
else
{
#ifdef _WIN32
- BigInt iEndTicks;
-
- _asm
- {
- RDTSC
- mov iEndTicks.int32val.i32[0], eax
- mov iEndTicks.int32val.i32[4], edx
- }
+ LARGE_INTEGER iEndTicks;
+ QueryPerformanceCounter(&iEndTicks);
// Add our total ticks to the tracking map object in the logger object
- m_pLogger->LogFunctionTicks(m_strFunctionName,
- iEndTicks.int64val.i64 - m_iStartTicks.int64val.i64);
+ m_pLogger->LogFunctionTicks(m_strFunctionName,
+ iEndTicks.QuadPart - m_iStartTicks.QuadPart);
#endif
}
-
}
}
diff --git a/Src/DasherCore/FileLogger.h b/Src/DasherCore/FileLogger.h
index fb225bd..9f1104d 100644
--- a/Src/DasherCore/FileLogger.h
+++ b/Src/DasherCore/FileLogger.h
@@ -64,23 +64,7 @@
#ifdef _WIN32
// Types required by our high resolution WIN32 timing routines
-
-typedef struct _BinInt32
-{
- __int32 i32[2];
-} BigInt32;
-
-typedef struct _BigInt64
-{
- __int64 i64;
-} BigInt64;
-
-typedef union _bigInt
-{
- BigInt32 int32val;
- BigInt64 int64val;
-} BigInt;
-
+#include "WinCommon.h"
typedef std::map<std::string, __int64> MAP_STRING_INT64;
#endif
@@ -166,7 +150,7 @@ private:
CFileLogger* m_pLogger; // Pointer to the logging object to use
#ifdef _WIN32
- BigInt m_iStartTicks; // Tick count at start of timing
+ LARGE_INTEGER m_iStartTicks; // Tick count at start of timing
#endif
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]