Skip to content
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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions ports/benchmark/0001-Add-MSVC-ARM64-support.patch
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()
Comment on lines +19 to +28
Copy link
Contributor

@Neumann-A Neumann-A Oct 14, 2020

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@Neumann-A Neumann-A Oct 14, 2020

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 to CMAKE_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

+
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

3 changes: 2 additions & 1 deletion ports/benchmark/CONTROL
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
4 changes: 3 additions & 1 deletion ports/benchmark/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ vcpkg_from_github(
REF 73d4d5e8d6d449fc8663765a42aa8aeeee844489 # v1.5.2
SHA512 b87a7c207eb85187165df8ff99ab1bbf5d38fc2a6d839e267a71987951c94e33b55fd7fbee6f2b59202b0379a7e9705b73b193edaea0b9c742eddf3fcbe5f48e
HEAD_REF master
PATCHES
0001-Add-MSVC-ARM64-support.patch # https://github.com/google/benchmark/pull/1052
)

vcpkg_configure_cmake(
Expand All @@ -30,4 +32,4 @@ file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)

# Handle copyright
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
1 change: 0 additions & 1 deletion scripts/ci.baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ bde:x64-uwp=fail
bde:x64-windows=fail
bde:x64-windows-static=fail
bde:x86-windows=fail
benchmark:arm64-windows=fail
benchmark:arm-uwp=fail
benchmark:x64-uwp=fail
berkeleydb:arm-uwp=fail
Expand Down