From b3499f6bea8bc49f92b5dcfc250da90e86fc5ebb Mon Sep 17 00:00:00 2001 From: Yves Chemisky Date: Fri, 13 Feb 2026 23:14:09 +0100 Subject: [PATCH] Guard CPUID/rdtsc for non-x86 and add stubs Add explicit x86/x86_64 guards and non-x86 fallbacks for CPUID and rdtsc. In Fastor/config/cpuid.h, avoid using inline asm on non-x86 targets by checking for __x86_64__/__i386__ and provide a safe zeroed fallback for regs otherwise. In Fastor/util/timeit.h, restrict the GCC inline-asm rdtsc implementation to x86 and add ARM/non-x86 stub implementations that return 0. These changes prevent build failures on non-x86 platforms and make the codebase more portable. --- Fastor/config/cpuid.h | 5 ++++- Fastor/util/timeit.h | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Fastor/config/cpuid.h b/Fastor/config/cpuid.h index 498883f..cb0cd5e 100644 --- a/Fastor/config/cpuid.h +++ b/Fastor/config/cpuid.h @@ -43,11 +43,14 @@ class CPUID { #ifdef _WIN32 __cpuid((int *)regs, (int)i); -#else +#elif defined(__x86_64__) || defined(__i386__) asm volatile ("cpuid" : "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3]) : "a" (i), "c" (0)); // ECX is set to zero for CPUID function 4 +#else + (void)i; + regs[0] = regs[1] = regs[2] = regs[3] = 0; #endif } diff --git a/Fastor/util/timeit.h b/Fastor/util/timeit.h index 3fae970..9539886 100644 --- a/Fastor/util/timeit.h +++ b/Fastor/util/timeit.h @@ -101,7 +101,7 @@ inline uint64_t rdtsc_end() { return __rdtsc(); } // Linux/GCC -#else +#elif defined(__x86_64__) || defined(__i386__) inline uint64_t rdtsc() { unsigned int lo, hi; // This does not clobber the register so rdtsc overwrites @@ -158,6 +158,11 @@ inline uint64_t rdtsc_end() { inline uint64_t rdtsc_begin() { return rdtsc();} inline uint64_t rdtsc_end() { return rdtsc();} #endif +#else +// ARM/non-x86 stubs +inline uint64_t rdtsc() { return 0; } +inline uint64_t rdtsc_begin() { return 0; } +inline uint64_t rdtsc_end() { return 0; } #endif