From e7e8e1c59a318225a044f3b463c2d473ceb2ee92 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Tue, 25 Apr 2017 00:26:11 +0300 Subject: [PATCH] test: refine reciprocal division (chrono). --- test/chrono.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/chrono.cc b/test/chrono.cc index bea5392d..444aca66 100644 --- a/test/chrono.cc +++ b/test/chrono.cc @@ -89,13 +89,13 @@ time now_realtime() { time now_motonic() { #if defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS) - static uint32_t reciprocal; + static uint64_t reciprocal; static LARGE_INTEGER Frequency; if (reciprocal == 0) { if (!QueryPerformanceFrequency(&Frequency)) failure_perror("QueryPerformanceFrequency()", GetLastError()); - reciprocal = (uint32_t)(((UINT64_C(1) << 32) + Frequency.QuadPart / 2) / - Frequency.QuadPart); + reciprocal = (((UINT64_C(1) << 48) + Frequency.QuadPart / 2 + 1) / + Frequency.QuadPart); assert(reciprocal); } @@ -104,10 +104,9 @@ time now_motonic() { failure_perror("QueryPerformanceCounter()", GetLastError()); time result; - result.integer = (uint32_t)(Counter.QuadPart / Frequency.QuadPart); + result.fixedpoint = (Counter.QuadPart / Frequency.QuadPart) << 32; uint64_t mod = Counter.QuadPart % Frequency.QuadPart; - assert(mod < UINT32_MAX); - result.fractional = UInt32x32To64((uint32_t)mod, reciprocal); + result.fixedpoint += (mod * reciprocal) >> 16; return result; #else struct timespec ts;