Fix _our_GetThreadCycles for clang/xarch.
authorPat Gavlin <pagavlin@microsoft.com>
Sat, 25 Feb 2017 18:09:00 +0000 (10:09 -0800)
committerPat Gavlin <pagavlin@microsoft.com>
Sat, 25 Feb 2017 18:09:00 +0000 (10:09 -0800)
The `"=A"` constraint in `asm volatile("rdtsc" : "=A"(cycles))` does not work as expected
on AMD64. Instead, the assembly must use an output constraint for both `eax` and `edx`
(i.e. `=a"(lo), "=d"(hi)`).

Commit migrated from https://github.com/dotnet/coreclr/commit/6be8d477451eb69861cd000330990487ffa4fcc6

src/coreclr/src/jit/compiler.cpp

index a9eba55..cd9fa4d 100644 (file)
@@ -73,9 +73,9 @@ inline bool _our_GetThreadCycles(unsigned __int64* cycleOut)
 
 inline bool _our_GetThreadCycles(unsigned __int64* cycleOut)
 {
-    uint64_t cycles;
-    asm volatile("rdtsc" : "=A"(cycles));
-    *cycleOut = cycles;
+    uint32_t hi, lo;
+    __asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
+    *cycleOut = (static_cast<unsigned __int64>(hi) << 32) | static_cast<unsigned __int64>(lo);
     return true;
 }