diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/utils/os_utils.cpp | 33 |
1 files changed, 12 insertions, 21 deletions
diff --git a/src/lib/utils/os_utils.cpp b/src/lib/utils/os_utils.cpp index 85248d11e..f98a3e68c 100644 --- a/src/lib/utils/os_utils.cpp +++ b/src/lib/utils/os_utils.cpp @@ -323,21 +323,23 @@ uint32_t OS::get_process_id() uint64_t OS::get_processor_timestamp() { + uint64_t rtc = 0; + #if defined(BOTAN_TARGET_OS_HAS_QUERY_PERF_COUNTER) LARGE_INTEGER tv; ::QueryPerformanceCounter(&tv); - return tv.QuadPart; + rtc = tv.QuadPart; #elif defined(BOTAN_USE_GCC_INLINE_ASM) #if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) - if(CPUID::has_rdtsc() == false) - return 0; - - uint32_t rtc_low = 0, rtc_high = 0; - asm volatile("rdtsc" : "=d" (rtc_high), "=a" (rtc_low)); - return (static_cast<uint64_t>(rtc_high) << 32) | rtc_low; + if(CPUID::has_rdtsc()) + { + uint32_t rtc_low = 0, rtc_high = 0; + asm volatile("rdtsc" : "=d" (rtc_high), "=a" (rtc_low)); + rtc = (static_cast<uint64_t>(rtc_high) << 32) | rtc_low; + } #elif defined(BOTAN_TARGET_ARCH_IS_PPC64) uint32_t rtc_low = 0, rtc_high = 0; @@ -349,43 +351,32 @@ uint64_t OS::get_processor_timestamp() */ if(rtc_high > 0 || rtc_low > 0) { - return (static_cast<uint64_t>(rtc_high) << 32) | rtc_low; + rtc = (static_cast<uint64_t>(rtc_high) << 32) | rtc_low; } #elif defined(BOTAN_TARGET_ARCH_IS_ALPHA) - uint64_t rtc = 0; asm volatile("rpcc %0" : "=r" (rtc)); - return rtc; // OpenBSD does not trap access to the %tick register #elif defined(BOTAN_TARGET_ARCH_IS_SPARC64) && !defined(BOTAN_TARGET_OS_IS_OPENBSD) - uint64_t rtc = 0; asm volatile("rd %%tick, %0" : "=r" (rtc)); - return rtc; #elif defined(BOTAN_TARGET_ARCH_IS_IA64) - uint64_t rtc = 0; asm volatile("mov %0=ar.itc" : "=r" (rtc)); - return rtc; #elif defined(BOTAN_TARGET_ARCH_IS_S390X) - uint64_t rtc = 0; asm volatile("stck 0(%0)" : : "a" (&rtc) : "memory", "cc"); - return rtc; #elif defined(BOTAN_TARGET_ARCH_IS_HPPA) - uint64_t rtc = 0; asm volatile("mfctl 16,%0" : "=r" (rtc)); // 64-bit only? - return rtc; #else //#warning "OS::get_processor_timestamp not implemented" - return 0; #endif -#else - return 0; #endif + + return rtc; } uint64_t OS::get_high_resolution_clock() |