aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaƂ Janiszewski <janisozaur@users.noreply.github.com>2021-02-12 11:30:26 +0100
committerGitHub <noreply@github.com>2021-02-12 13:30:26 +0300
commitea5a5bbff491fd625c6e3458f6edd680b8bd5452 (patch)
tree2802b5552f8f79850d2c4c6bd9c050d0a398d794
parent8df87f6c879cbcabd17c5cfcec7b89687df36953 (diff)
downloadgoogle-benchmark-ea5a5bbff491fd625c6e3458f6edd680b8bd5452.tar.gz
Add MSVC ARM64 support for reading clocks (#1052)
Lacks CMake support, see https://github.com/google/benchmark/pull/1090
-rw-r--r--src/cycleclock.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/cycleclock.h b/src/cycleclock.h
index 89de86f..6843b69 100644
--- a/src/cycleclock.h
+++ b/src/cycleclock.h
@@ -36,7 +36,7 @@
// declarations of some other intrinsics, breaking compilation.
// Therefore, we simply declare __rdtsc ourselves. See also
// http://connect.microsoft.com/VisualStudio/feedback/details/262047
-#if defined(COMPILER_MSVC) && !defined(_M_IX86)
+#if defined(COMPILER_MSVC) && !defined(_M_IX86) && !defined(_M_ARM64)
extern "C" uint64_t __rdtsc();
#pragma intrinsic(__rdtsc)
#endif
@@ -114,6 +114,12 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
// when I know it will work. Otherwise, I'll use __rdtsc and hope
// the code is being compiled with a non-ancient compiler.
_asm rdtsc
+#elif defined(COMPILER_MSVC) && defined(_M_ARM64)
+ // See https://docs.microsoft.com/en-us/cpp/intrinsics/arm64-intrinsics?view=vs-2019
+ // and https://reviews.llvm.org/D53115
+ int64_t virtual_timer_value;
+ virtual_timer_value = _ReadStatusReg(ARM64_CNTVCT);
+ return virtual_timer_value;
#elif defined(COMPILER_MSVC)
return __rdtsc();
#elif defined(BENCHMARK_OS_NACL)