diff options
Diffstat (limited to 'libtommath/etc/tune.c')
-rw-r--r-- | libtommath/etc/tune.c | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/libtommath/etc/tune.c b/libtommath/etc/tune.c index 14aace2..d054d10 100644 --- a/libtommath/etc/tune.c +++ b/libtommath/etc/tune.c @@ -10,13 +10,44 @@ */ #define TIMES (1UL<<14UL) +/* RDTSC from Scott Duplichan */ +static ulong64 TIMFUNC (void) + { + #if defined __GNUC__ + #if defined(__i386__) || defined(__x86_64__) + unsigned long long a; + __asm__ __volatile__ ("rdtsc\nmovl %%eax,%0\nmovl %%edx,4+%0\n"::"m"(a):"%eax","%edx"); + return a; + #else /* gcc-IA64 version */ + unsigned long result; + __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); + while (__builtin_expect ((int) result == -1, 0)) + __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); + return result; + #endif + + // Microsoft and Intel Windows compilers + #elif defined _M_IX86 + __asm rdtsc + #elif defined _M_AMD64 + return __rdtsc (); + #elif defined _M_IA64 + #if defined __INTEL_COMPILER + #include <ia64intrin.h> + #endif + return __getReg (3116); + #else + #error need rdtsc function for this build + #endif + } + #ifndef X86_TIMER /* generic ISO C timer */ ulong64 LBL_T; -void t_start(void) { LBL_T = clock(); } -ulong64 t_read(void) { return clock() - LBL_T; } +void t_start(void) { LBL_T = TIMFUNC(); } +ulong64 t_read(void) { return TIMFUNC() - LBL_T; } #else extern void t_start(void); |