Skip to content

Commit 12ff2c2

Browse files
authored
Fix build when targetting Arm64EC using Clang (#2012)
1 parent 77c03fb commit 12ff2c2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/cycleclock.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
// declarations of some other intrinsics, breaking compilation.
3737
// Therefore, we simply declare __rdtsc ourselves. See also
3838
// http://connect.microsoft.com/VisualStudio/feedback/details/262047
39+
//
40+
// Note that MSVC defines the x64 preprocessor macros when building
41+
// for Arm64EC, despite it using Arm64 assembly instructions.
3942
#if defined(COMPILER_MSVC) && !defined(_M_IX86) && !defined(_M_ARM64) && \
4043
!defined(_M_ARM64EC)
4144
extern "C" uint64_t __rdtsc();
@@ -79,7 +82,10 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
7982
int64_t ret;
8083
__asm__ volatile("rdtsc" : "=A"(ret));
8184
return ret;
82-
#elif defined(__x86_64__) || defined(__amd64__)
85+
86+
// Note that Clang, like MSVC, defines the x64 preprocessor macros when building
87+
// for Arm64EC, despite it using Arm64 assembly instructions.
88+
#elif (defined(__x86_64__) || defined(__amd64__)) && !defined(__arm64ec__)
8389
uint64_t low, high;
8490
__asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
8591
return static_cast<int64_t>((high << 32) | low);
@@ -139,7 +145,7 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
139145
struct timespec ts = {0, 0};
140146
clock_gettime(CLOCK_MONOTONIC, &ts);
141147
return static_cast<int64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec;
142-
#elif defined(__aarch64__)
148+
#elif defined(__aarch64__) || defined(__arm64ec__)
143149
// System timer of ARMv8 runs at a different frequency than the CPU's.
144150
// The frequency is fixed, typically in the range 1-50MHz. It can be
145151
// read at CNTFRQ special register. We assume the OS has set up

0 commit comments

Comments
 (0)