[ODE] timer.cpp portability (was Re: building on intel OSX)
Tanguy Fautre
tanguy.fautre at spaceapplications.com
Fri Apr 7 01:37:15 MST 2006
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
More information about the ODE
mailing list