From 3d147a032c688342dfa681d9f82e157f9ef42682 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 31 Jan 2017 17:51:12 +0200 Subject: [PATCH] Proper RDTSC implementation for x86_64 targets Higher 32 bits of Time Stamp Counter were ignored in non-MSVC Windows and macOS builds --- src/stats.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/stats.h b/src/stats.h index 8ac1e978a..f18159616 100644 --- a/src/stats.h +++ b/src/stats.h @@ -102,7 +102,7 @@ private: #else -// Windows +// Windows and macOS #include "x86.h" extern double PerfToSec, PerfToMillisec; @@ -126,15 +126,19 @@ inline unsigned __int64 rdtsc() #else inline unsigned long long rdtsc() { -#ifndef __amd64__ +#ifdef __amd64__ + unsigned long long tsc; + asm volatile ("rdtsc; shlq $32, %%rdx; orq %%rdx, %%rax" : "=a" (tsc) :: "%rdx"); + return tsc; +#else // i386 if (CPU.bRDTSC) -#endif { unsigned long long tsc; asm volatile ("\trdtsc\n" : "=A" (tsc)); return tsc; } return 0; +#endif // __amd64__ } #endif