From 3af95e61fe90b4dbc5b536757cb794c0affc0376 Mon Sep 17 00:00:00 2001 From: Arrehn Date: Wed, 29 Dec 2010 18:37:56 -0500 Subject: [PATCH] Nicky Dasmijn : FIRE-134 , patch fast timers for 64bit & other builds Experimental! --- indra/llcommon/llfasttimer.h | 40 ++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/indra/llcommon/llfasttimer.h b/indra/llcommon/llfasttimer.h index 4ff93a553c..6d400ca005 100644 --- a/indra/llcommon/llfasttimer.h +++ b/indra/llcommon/llfasttimer.h @@ -128,20 +128,48 @@ inline U32 LLFastTimer::getCPUClockCount32() #if (LL_LINUX || LL_SOLARIS || LL_DARWIN) && (defined(__i386__) || defined(__amd64__)) +// 64bit comp patch + +#ifdef __amd64__ + +inline void getRDTSC() +{ + __asm volatile( "PUSHQ %RDX\n\t" + "XOR %RAX, %RAX\n\t" + "XOR %RDX, %RDX\n\t" + "RDTSC\n\t" + "SHL $0x20,%RDX\n\t" + "OR %RDX, %RAX\n\t" + "POPQ %RDX" ); +} + +#else + +inline void getRDTSC() +{ + __asm volatile( "RDTSC" ); +} + +#endif + +inline U64 getRDTSCImpl() +{ + typedef unsigned long long (*tGetRDTSC)(); + + tGetRDTSC pGetRDTSC( (tGetRDTSC)getRDTSC ); + return (*pGetRDTSC)(); +} + // // Mac+Linux+Solaris FAST x86 implementation of CPU clock inline U32 LLFastTimer::getCPUClockCount32() { - U64 x; - __asm__ volatile (".byte 0x0f, 0x31": "=A"(x)); - return (U32)(x >> 8); + return (U32)(getRDTSCImpl() >> 8 ); } inline U64 LLFastTimer::getCPUClockCount64() { - U64 x; - __asm__ volatile (".byte 0x0f, 0x31": "=A"(x)); - return x; + return getRDTSCImpl(); } #endif