Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Feb 28, 2025
1 parent 2123e8e commit 859bef7
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions src/arch/arm/sve.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <windows.h>

Expand Down Expand Up @@ -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

0 comments on commit 859bef7

Please sign in to comment.