-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[benchmark] Add MSVC ARM64 support #14021
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
From a31f7c3f8f215e66de00a0c3fb0c39607f182b81 Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= <[email protected]> | ||
Date: Mon, 5 Oct 2020 20:53:33 +0200 | ||
Subject: [PATCH] Add MSVC ARM64 support | ||
|
||
--- | ||
CMakeLists.txt | 11 +++++++++++ | ||
src/cycleclock.h | 8 +++++++- | ||
2 files changed, 18 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 67c0b70..d87f381 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -35,6 +35,17 @@ option(BENCHMARK_DOWNLOAD_DEPENDENCIES "Allow the downloading and in-tree buildi | ||
option(BENCHMARK_ENABLE_GTEST_TESTS "Enable building the unit tests which depend on gtest" ON) | ||
|
||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
+if(MSVC) | ||
+ # As of CMake 3.18, CMAKE_SYSTEM_PROCESSOR is not set properly for MSVC and | ||
+ # cross-compilation (e.g. Host=x86_64, target=aarch64) requires using the | ||
+ # undocumented, but working variable. | ||
+ # See https://gitlab.kitware.com/cmake/cmake/-/issues/15170 | ||
+ set(CMAKE_SYSTEM_PROCESSOR ${MSVC_CXX_ARCHITECTURE_ID}) | ||
+ if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ARM") | ||
+ set(CMAKE_CROSSCOMPILING TRUE) | ||
+ endif() | ||
+endif() | ||
+ | ||
set(ENABLE_ASSEMBLY_TESTS_DEFAULT OFF) | ||
function(should_enable_assembly_tests) | ||
if(CMAKE_BUILD_TYPE) | ||
diff --git a/src/cycleclock.h b/src/cycleclock.h | ||
index d5d62c4..338d68b 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 | ||
@@ -106,6 +106,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) | ||
-- | ||
2.28.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
Source: benchmark | ||
Version: 1.5.2 | ||
janisozaur marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Port-Version: 1 | ||
Homepage: https://github.com/google/benchmark | ||
Description: A library to support the benchmarking of functions, similar to unit-tests. | ||
Supports: !uwp | ||
Supports: !uwp | ||
JackBoosY marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a failure in the vcpkg windows toolchain not setting
CMAKE_SYSTEM_PROCESSOR
to arm for ARM builds.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While vcpkg might share the issue, it's a consequence of MSVC's quirks and not limited to vcpkg. Even building manually with ninja requires this fixup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it is a consequence of CMake always setting
CMAKE_SYSTEM_PROCESSOR
toCMAKE_HOST_SYSTEM_PROCESSOR
(in make land this would be --build and not --host) unless otherwise specified. So if you crosscompile with CMake you are expected to correctly set the values for crosscompiling in the toolchain