From d86984a256baab8a3ffc932d26bbe8a8d326d686 Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Tue, 15 Aug 2017 15:46:35 +0200 Subject: [PATCH] Fix os_time_get_nano() to roll over less --- src/gallium/auxiliary/os/os_time.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/os/os_time.c b/src/gallium/auxiliary/os/os_time.c index e169139..b02d86a 100644 --- a/src/gallium/auxiliary/os/os_time.c +++ b/src/gallium/auxiliary/os/os_time.c @@ -69,10 +69,15 @@ os_time_get_nano(void) static LARGE_INTEGER frequency; LARGE_INTEGER counter; + int64_t secs, nanosecs; if(!frequency.QuadPart) QueryPerformanceFrequency(&frequency); QueryPerformanceCounter(&counter); - return counter.QuadPart*INT64_C(1000000000)/frequency.QuadPart; + /* Compute seconds and nanoseconds parts separately to + * reduce severity of precision loss */ + secs = counter.QuadPart / frequency.QuadPart; + nanosecs = (counter.QuadPart % frequency.QuadPart)*INT64_C(1000000000) / frequency.QuadPart; + return secs*INT64_C(1000000000) + nanosecs; #else -- 2.11.1.windows.1