From 26944eb21a4c3e267eb44d7bebd1fc9e14b2edfe Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Tue, 16 Jun 2026 01:14:59 -0400 Subject: [PATCH] LoongArch64: Some further cleaning and tweaking of the run-time support - Wrap the CPU detection code with HAVE_GETAUXVAL - Have run-time support only enabled on Linux so far - Quiet warning about benableavx512 --- source/CMakeLists.txt | 2 +- source/common/cpu.cpp | 1 + source/common/loongarch64/cpu.h | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 06924e954..c9380d301 100755 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -138,7 +138,7 @@ elseif(LOONGARCH64MATCH GREATER "-1") message(STATUS "Detected LOONGARCH64 target processor") option(LOONGARCH64_RUNTIME_CPU_DETECT "Enable LOONGARCH64 run-time CPU feature detection" ON) - if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux|FreeBSD|OpenBSD") + if(NOT CMAKE_SYSTEM_NAME MATCHES "Linux") set(LOONGARCH64_RUNTIME_CPU_DETECT OFF CACHE BOOL "" FORCE) message(STATUS "Run-time CPU feature detection unsupported on this platform") endif() diff --git a/source/common/cpu.cpp b/source/common/cpu.cpp index 800f51f9f..0749d44b5 100644 --- a/source/common/cpu.cpp +++ b/source/common/cpu.cpp @@ -461,6 +461,7 @@ uint32_t cpu_detect(bool benableavx512) uint32_t cpu_detect( bool benableavx512 ) { + (void)benableavx512; uint32_t flags = 0; #ifdef ENABLE_ASSEMBLY diff --git a/source/common/loongarch64/cpu.h b/source/common/loongarch64/cpu.h index ccdda892b..cff089b75 100644 --- a/source/common/loongarch64/cpu.h +++ b/source/common/loongarch64/cpu.h @@ -28,12 +28,14 @@ #if LOONGARCH64_RUNTIME_CPU_DETECT +#if HAVE_GETAUXVAL + #include #define LA_HWCAP_LSX ( 1U << 4 ) #define LA_HWCAP_LASX ( 1U << 5 ) -static inline uint32_t loongarch64_cpu_detect() +static inline uint32_t loongarch64_get_cpu_flags() { uint32_t flags = 0; #if HAVE_LSX || HAVE_LSX @@ -52,6 +54,20 @@ static inline uint32_t loongarch64_cpu_detect() return flags; } +#else // HAVE_GETAUXVAL +#error \ + "Run-time CPU feature detection selected, but no detection method" \ + "available for your platform. Rerun cmake configure with" \ + "-DLOONGARCH64_RUNTIME_CPU_DETECT=OFF." +#endif // HAVE_GETAUXVAL + +static inline uint32_t loongarch64_cpu_detect() +{ + uint32_t flags = loongarch64_get_cpu_flags(); + + return flags; +} + #else // if LOONGARCH64_RUNTIME_CPU_DETECT static inline uint32_t loongarch64_cpu_detect()