From f55bd056a9cc7da4252e18dcc7ef32bf43b9ef6a Mon Sep 17 00:00:00 2001 From: Marcos Slomp Date: Mon, 22 Dec 2025 11:43:51 -0800 Subject: [PATCH] switch to using ARM64's CNTVCT_EL0 instruction instead of std::chrono::high_resolution_clock on macOS --- public/client/TracyProfiler.hpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/public/client/TracyProfiler.hpp b/public/client/TracyProfiler.hpp index aacfa16b..90be4ced 100644 --- a/public/client/TracyProfiler.hpp +++ b/public/client/TracyProfiler.hpp @@ -28,7 +28,7 @@ # include #endif -#if ( (defined _WIN32 && !(defined _M_ARM64 || defined _M_ARM)) || ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) || ( defined TARGET_OS_IOS && TARGET_OS_IOS == 1 ) ) +#if ( (defined _WIN32 && !(defined _M_ARM64 || defined _M_ARM)) || ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) || ( defined TARGET_OS_IOS && TARGET_OS_IOS == 1 ) || ( defined __APPLE__ && defined __MACH__ && TARGET_CPU_ARM64 ) ) # define TRACY_HW_TIMER #endif @@ -200,6 +200,19 @@ public: #ifdef TRACY_HW_TIMER # if defined TARGET_OS_IOS && TARGET_OS_IOS == 1 if( HardwareSupportsInvariantTSC() ) return mach_absolute_time(); +# elif defined(__APPLE__) && defined(__MACH__) && TARGET_CPU_ARM64 + if( HardwareSupportsInvariantTSC() ) + { + uint64_t value; + __asm__ __volatile__( + //"isb \n" // ommitting "Instruction Synchronization Barrier" + "mrs %0, CNTVCT_EL0" + : "=r" (value) // Output: write 'register %0' to 'value' + : // No inputs + : "memory" // Clobber list: memory (e.g., compiler barrier) + ); + return value; + } # elif defined _WIN32 # ifdef TRACY_TIMER_QPC return GetTimeQpc();