From f46a48c35d48db1155fec681d69687be09e7ae85 Mon Sep 17 00:00:00 2001 From: night1rider Date: Fri, 17 Jul 2026 15:57:51 -0600 Subject: [PATCH] benchmark: build the AArch64 cycle counter under MSVC/ARM64 --- wolfcrypt/benchmark/benchmark.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index b0f7e79078b..86d73dc7580 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -81,6 +81,12 @@ #include #include +#if defined(_MSC_VER) && defined(_M_ARM64) + /* MSVC has no inline asm on ARM64. Pull in the system register intrinsics + * (_ReadStatusReg, __isb) the AArch64 cycle counter below uses. */ + #include +#endif + #ifdef WOLFSSL_LINUXKM /* remap current_time() -- collides with a function in kernel linux/fs.h */ #define current_time benchmark_current_time @@ -4867,6 +4873,12 @@ static void print_cpu_features(void) static void print_clock_freq(void) { #ifdef __aarch64__ +#if defined(_MSC_VER) + /* MSVC/ARM64: no inline asm. Read CNTFRQ_EL0 (3,3,14,0,0) via the + * system register intrinsic. */ + __isb(_ARM64_BARRIER_SY); + tick_freq = (word64)_ReadStatusReg(ARM64_SYSREG(3, 3, 14, 0, 0)); +#else __asm__ __volatile__ ( "isb\n\t" "mrs %[freq], cntfrq_el0\n\t" @@ -4874,6 +4886,7 @@ static void print_clock_freq(void) : : ); +#endif if (tick_freq != 0 && actual_freq != 0) { printf("Tick frequency: %ld Hz, Clock frequency: %ld Hz\n", tick_freq, actual_freq); @@ -17315,6 +17328,12 @@ void bench_mldsaKeySign(byte level) static WC_INLINE word64 get_aarch64_cycles(void) { word64 ticks; + #if defined(_MSC_VER) + /* MSVC/ARM64: no inline asm. Read CNTVCT_EL0 (3,3,14,0,2) via the + * system register intrinsic. */ + __isb(_ARM64_BARRIER_SY); + ticks = (word64)_ReadStatusReg(ARM64_SYSREG(3, 3, 14, 0, 2)); + #else __asm__ __volatile__ ( "isb\n\t" #ifdef __APPLE__ @@ -17326,6 +17345,7 @@ void bench_mldsaKeySign(byte level) : : ); + #endif if ((tick_freq != 0) && (actual_freq != 0)) { ticks *= actual_freq / tick_freq; }