[ODE] Fw: timer.cpp portability (was Re: building on intel OSX)
gl
gl at ntlworld.com
Fri Apr 7 04:06:51 MST 2006
Aren't there problems with using rdtsc raw? IIRC you have to know or
measure the exact freq to get accurate time-elapsed results, it doesn't work
well on multi-processor systems, and can get confused by real-time clock
changes from power-saving setups. That's why QueryPerformanceCounter is
usually recommended on x86.
--
gl
> ----- Original Message -----
> From: "Tanguy Fautre" <tanguy.fautre at spaceapplications.com>
> To: "ode-list" <ODE at q12.org>
> Sent: Friday, April 07, 2006 9:37 AM
> Subject: [ODE] timer.cpp portability (was Re: building on intel OSX)
>
>
>> Hampus Soderstrom wrote:
>>> Hi,
>>>
>>> Here is a patch to get timer.cpp to compile on Intel OS X.
>>>
>>> RCS file: /cvsroot/opende/ode/ode/src/timer.cpp,v
>>> retrieving revision 1.11.2.2
>>> diff -r1.11.2.2 timer.cpp
>>> 128c128
>>> < "mov $0,%%eax\n"
>>> ---
>>> > "mov %%ebx,%%edi\n"
>>> 130c130
>>> < : : : "%eax","%ebx","%ecx","%edx","cc","memory");
>>> ---
>>> > : : : "%eax","%edi","%ecx","%edx","cc","memory");
>>>
>>>
>>
>>
>> How about using something a little more portable (cf. following piece of
>> code) ?
>>
>> That's what I use for our projects. It works on both x86 and x86_64,
>> Linux, Windows (VC++ 6.0, 7.0, 7.1, 8.0), and QNX.
>>
>> Also, note how the GCC path seems more portable that ODE current code
>> for RDTSC.
>>
>> Tanguy
>>
>>
>>
>>
>> #ifndef HEADER_GUARD_TIMER_X86_RDTSC_H
>> #define HEADER_GUARD_TIMER_X86_RDTSC_H
>>
>> // Visual C++ 8.0 has a __rdtsc() intrinsic
>> #if ((defined _MSC_VER) && (_MSC_VER > 1310))
>> #include <intrin.h>
>> #endif
>>
>> #if defined __QNX__
>> #include <sys/neutrino.h>
>> #endif
>>
>>
>>
>> namespace timer
>> {
>>
>> uint64_t x86_rdtsc();
>>
>> }
>>
>>
>>
>>
>>
>> namespace timer {
>>
>>
>>
>> inline uint64_t x86_rdtsc()
>> {
>>
>> // Visual C++ 8.0 has a __rdtsc() intrinsic
>> #if ((defined _MSC_VER) && (_MSC_VER > 1310))
>>
>> return __rdtsc();
>>
>> // Visual C++ 7.1 or lower have to use inline assembly
>> #elif (defined _MSC_VER) && (_MSC_VER <= 1310)
>>
>> __asm
>> {
>> rdtsc
>> }
>>
>> // QNX supports a more portable call: ClockCycles()
>> #elif defined __QNX__
>>
>> return ClockCycles();
>>
>> // GCC supports "portable" assembly for both x86 and x86_64
>> #elif defined __GNUC__
>>
>> volatile uint32_t Low, High;
>>
>> asm volatile ("rdtsc" : "=a" (Low), "=d" (High));
>>
>> return (uint64_t(High) << 32) + Low;
>>
>> // RDTSC not supported
>> #elif
>>
>> return 0;
>>
>> #endif
>>
>> }
>>
>>
>>
>> } // namespace timer
>>
>>
>>
>> #endif // HEADER_GUARD_TIMER_X86_RDTSC_H
>>
>> _______________________________________________
>> ODE mailing list
>> ODE at q12.org
>> http://q12.org/mailman/listinfo/ode
>
More information about the ODE
mailing list