diff --git a/trunk/src/nvcore/CMakeLists.txt b/trunk/src/nvcore/CMakeLists.txt index 8cfe35c..ee8bdc0 100644 --- a/trunk/src/nvcore/CMakeLists.txt +++ b/trunk/src/nvcore/CMakeLists.txt @@ -18,7 +18,7 @@ SET(CORE_SRCS Stream.h StdStream.h TextWriter.h TextWriter.cpp - Timer.h + Timer.h Timer.cpp Utils.h) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/trunk/src/nvcore/Debug.cpp b/trunk/src/nvcore/Debug.cpp index fe25788..d855a0b 100644 --- a/trunk/src/nvcore/Debug.cpp +++ b/trunk/src/nvcore/Debug.cpp @@ -763,19 +763,19 @@ bool debug::attachToDebugger() if (isDebuggerPresent() == FALSE) { Path process(1024); process.copy("\""); - GetSystemDirectory(process.str() + 1, 1024 - 1); + GetSystemDirectoryA(process.str() + 1, 1024 - 1); process.appendSeparator(); process.appendFormat("VSJitDebugger.exe\" -p %lu", ::GetCurrentProcessId()); - STARTUPINFO sSi; + STARTUPINFOA sSi; memset(&sSi, 0, sizeof(sSi)); PROCESS_INFORMATION sPi; memset(&sPi, 0, sizeof(sPi)); - BOOL b = CreateProcess(NULL, process.str(), NULL, NULL, FALSE, 0, NULL, NULL, &sSi, &sPi); + BOOL b = CreateProcessA(NULL, process.str(), NULL, NULL, FALSE, 0, NULL, NULL, &sSi, &sPi); if (b != FALSE) { ::WaitForSingleObject(sPi.hProcess, INFINITE); @@ -802,4 +802,4 @@ bool debug::attachToDebugger() #endif // NV_OS_WIN32 return true; -} \ No newline at end of file +} diff --git a/trunk/src/nvcore/DefsGnucDarwin.h b/trunk/src/nvcore/DefsGnucDarwin.h index 0c6579b..9e250cd 100644 --- a/trunk/src/nvcore/DefsGnucDarwin.h +++ b/trunk/src/nvcore/DefsGnucDarwin.h @@ -3,7 +3,7 @@ #endif #include // uint8_t, int8_t, ... uintptr_t -#include // operator new, size_t, NULL +//#include // operator new, size_t, NULL // Function linkage #define DLL_IMPORT diff --git a/trunk/src/nvcore/Timer.cpp b/trunk/src/nvcore/Timer.cpp new file mode 100644 index 0000000..6df8361 --- /dev/null +++ b/trunk/src/nvcore/Timer.cpp @@ -0,0 +1,44 @@ +// This code is in the public domain -- castano@gmail.com + +#include "Timer.h" + +using namespace nv; + + +#if NV_OS_WIN32 + +#define WINDOWS_LEAN_AND_MEAN +#define VC_EXTRALEAN +#define NOMINMAX +#include // QueryPerformanceFrequency, QueryPerformanceCounter + + +uint64 nv::systemClockFrequency() +{ + uint64 frequency; + QueryPerformanceFrequency((LARGE_INTEGER*) &frequency); + return frequency; +} + +uint64 nv::systemClock() +{ + uint64 counter; + QueryPerformanceCounter((LARGE_INTEGER*) &counter); + return counter; +} + +#else + +#include // clock + +uint64 nv::systemClockFrequency() +{ + return CLOCKS_PER_SEC; +} + +uint64 nv::systemClock() +{ + return clock(); +} + +#endif diff --git a/trunk/src/nvcore/Timer.h b/trunk/src/nvcore/Timer.h index d411b60..45f2c06 100644 --- a/trunk/src/nvcore/Timer.h +++ b/trunk/src/nvcore/Timer.h @@ -6,60 +6,44 @@ #include "nvcore.h" -#if 1 - -#include //clock - namespace nv { +#if NV_CC_MSVC + NV_FORCEINLINE uint64 fastCpuClock() { return rdtsc(); } +#elif NV_CC_GNUC && NV_CPU_X86 + NV_FORCEINLINE uint64 fastCpuClock() { + uint64 val; + __asm__ volatile (".byte 0x0f, 0x31" : "=A" (val)); + return val; + } +#elif NV_CC_GNUC && NV_CPU_X86_64 + NV_FORCEINLINE uint64 fastCpuClock() { + uint hi, lo; + __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi)); + return uint64(lo) | (uint64(hi) << 32); + } +#else + NV_FORCEINLINE uint64 fastCpuClock() { return 0; } +#endif + + uint64 systemClockFrequency(); + uint64 systemClock(); + class NVCORE_CLASS Timer { public: Timer() {} - void start() { m_start = clock(); } - void stop() { m_stop = clock(); } + void start() { m_start = systemClock(); } + void stop() { m_stop = systemClock(); } - float elapsed() const { return float(m_stop - m_start) / CLOCKS_PER_SEC; } + float elapsed() const { return float(m_stop - m_start) / systemClockFrequency(); } private: - clock_t m_start; - clock_t m_stop; + uint64 m_start; + uint64 m_stop; }; } // nv namespace -#else - -#define WINDOWS_LEAN_AND_MEAN -#define VC_EXTRALEAN -#define NOMINMAX -#include - -class NVCORE_CLASS Timer -{ -public: - Timer() { - // get the tick frequency from the OS - QueryPerformanceFrequency((LARGE_INTEGER*) &m_frequency); - } - - void start() { QueryPerformanceCounter((LARGE_INTEGER*) &m_start); } - void stop() { QueryPerformanceCounter((LARGE_INTEGER*) &m_stop); } - - int elapsed() const { - return (int)1000 * ((double)m_stop.QuadPart - (double)m_start.QuadPart) / (double)m_frequency.QuadPart; - } - -private: - LARGE_INTEGER m_frequency; - LARGE_INTEGER m_start; - LARGE_INTEGER m_stop; - -}; - -#endif // 0 - - - #endif // NV_CORE_TIMER_H diff --git a/trunk/src/nvcore/nvcore.h b/trunk/src/nvcore/nvcore.h index a4ebd89..22b9631 100644 --- a/trunk/src/nvcore/nvcore.h +++ b/trunk/src/nvcore/nvcore.h @@ -84,9 +84,7 @@ // Compiler: // NV_CC_GNUC // NV_CC_MSVC -// @@ NV_CC_MSVC6 -// @@ NV_CC_MSVC7 -// @@ NV_CC_MSVC8 +// NV_CC_CLANG #if defined POSH_COMPILER_CLANG # define NV_CC_CLANG 1 @@ -148,7 +146,7 @@ typedef uint32 uint; #define NV_FORBID_COPY(C) \ private: \ C( const C & ); \ - C &operator=( const C & ); + C &operator=( const C & ) // Disable dynamic allocation on the heap. @@ -156,7 +154,7 @@ typedef uint32 uint; #define NV_FORBID_HEAPALLOC() \ private: \ void *operator new(size_t size); \ - void *operator new[](size_t size); + void *operator new[](size_t size) //static void *operator new(size_t size); \ //static void *operator new[](size_t size); @@ -218,7 +216,7 @@ NV_COMPILER_CHECK(sizeof(uint32) == 4); NV_STRING_JOIN2(AtStartup_, __LINE__)() { some_code; } \ } \ NV_STRING_JOIN3(AtStartup_, __LINE__, Instance); \ - }; + } // Indicate the compiler that the parameter is not used to suppress compier warnings. #define NV_UNUSED(a) ((a)=(a))