test-ticks.h (1327B)
1 #include "ed25519-donna-portable-identify.h" 2 3 /* ticks - not tested on anything other than x86 */ 4 static uint64_t 5 get_ticks(void) { 6 #if defined(CPU_X86) || defined(CPU_X86_64) 7 #if defined(COMPILER_INTEL) 8 return _rdtsc(); 9 #elif defined(COMPILER_MSVC) 10 return __rdtsc(); 11 #elif defined(COMPILER_GCC) 12 uint32_t lo, hi; 13 __asm__ __volatile__("rdtsc" : "=a" (lo), "=d" (hi)); 14 return ((uint64_t)lo | ((uint64_t)hi << 32)); 15 #else 16 #error need rdtsc for this compiler 17 #endif 18 #elif defined(OS_SOLARIS) 19 return (uint64_t)gethrtime(); 20 #elif defined(CPU_SPARC) && !defined(OS_OPENBSD) 21 uint64_t t; 22 __asm__ __volatile__("rd %%tick, %0" : "=r" (t)); 23 return t; 24 #elif defined(CPU_PPC) 25 uint32_t lo = 0, hi = 0; 26 __asm__ __volatile__("mftbu %0; mftb %1" : "=r" (hi), "=r" (lo)); 27 return ((uint64_t)lo | ((uint64_t)hi << 32)); 28 #elif defined(CPU_IA64) 29 uint64_t t; 30 __asm__ __volatile__("mov %0=ar.itc" : "=r" (t)); 31 return t; 32 #elif defined(OS_NIX) 33 timeval t2; 34 gettimeofday(&t2, NULL); 35 t = ((uint64_t)t2.tv_usec << 32) | (uint64_t)t2.tv_sec; 36 return t; 37 #else 38 #error need ticks for this platform 39 #endif 40 } 41 42 #define timeit(x,minvar) \ 43 ticks = get_ticks(); \ 44 x; \ 45 ticks = get_ticks() - ticks; \ 46 if (ticks < minvar) \ 47 minvar = ticks; 48 49 #define maxticks 0xffffffffffffffffull