diff --git a/src/arch/arm/sve.cpp b/src/arch/arm/sve.cpp index 1499ac77..b15abc1e 100644 --- a/src/arch/arm/sve.cpp +++ b/src/arch/arm/sve.cpp @@ -1,9 +1,12 @@ /// /// @file sve.cpp /// @brief Check if the CPU and OS support the SVE instruction set. +/// Compiling and linking of sve.cpp is tested by the CMake +/// build system using multiarch_sve_arm.cmake. +/// /// In order to generate optimal code, we need to be able to -/// check if the ARM CPU supports the SVE instruction set in -/// a global initializer when the program is loaded. +/// check if the ARM CPU supports the SVE instruction set +/// in a global initializer when the program is loaded. /// /// __builtin_cpu_supports() from Clang >= 19.0.0 does not /// work when running in a global initializer. Usually the @@ -21,27 +24,7 @@ /// file in the top level directory. /// -#ifndef __has_builtin - #define __has_builtin(x) 0 -#endif - -#if __has_builtin(__builtin_cpu_init) && \ - __has_builtin(__builtin_cpu_supports) - -namespace primesieve { - -bool has_arm_sve() -{ - __builtin_cpu_init(); - if (__builtin_cpu_supports("sve")) - return true; - else - return false; -} - -} // namespace - -#elif defined(_WIN32) +#if defined(_WIN32) #include @@ -91,4 +74,30 @@ bool has_arm_sve() } // namespace +#else + +#ifndef __has_builtin + #define __has_builtin(x) 0 +#endif + +#if __has_builtin(__builtin_cpu_init) && \ + __has_builtin(__builtin_cpu_supports) + +namespace primesieve { + +bool has_arm_sve() +{ + // Since __builtin_cpu_init() and __builtin_cpu_supports() are + // currently (2025) not yet supported for ARM64 CPUs by both + // GCC and Clang, we only use them as a fallback option if + // none of the other more reliable methods work. + __builtin_cpu_init(); + if (__builtin_cpu_supports("sve")) + return true; + else + return false; +} + +} // namespace + #endif