cmake: test for lsx and lasx intrinsics for loongarch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 294f826..8ada68e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -139,6 +139,7 @@ check_cpu_architecture(x86 SDL_CPU_X86)
check_cpu_architecture(x64 SDL_CPU_X64)
check_cpu_architecture(arm32 SDL_CPU_ARM32)
check_cpu_architecture(arm64 SDL_CPU_ARM64)
+check_cpu_architecture(loongarch64 SDL_CPU_LOONGARCH64)
# Check for 64 or 32 bit
set(SIZEOF_VOIDP ${CMAKE_SIZEOF_VOID_P})
@@ -440,6 +441,8 @@ dep_option(SDL_3DNOW "Use 3Dnow! MMX assembly routines" ON "SDL_AS
dep_option(SDL_ALTIVEC "Use Altivec assembly routines" ON "SDL_ASSEMBLY" OFF)
dep_option(SDL_ARMSIMD "Use SIMD assembly blitters on ARM" OFF "SDL_ASSEMBLY;SDL_CPU_ARM32" OFF)
dep_option(SDL_ARMNEON "Use NEON assembly blitters on ARM" OFF "SDL_ASSEMBLY;SDL_CPU_ARM32" OFF)
+dep_option(SDL_LSX "Use LSX assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_LOONGARCH64" OFF)
+dep_option(SDL_LASX "Use LASX assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_LOONGARCH64" OFF)
set_option(SDL_LIBC "Use the system C library" ${OPT_DEF_LIBC})
set_option(SDL_GCC_ATOMICS "Use gcc builtin atomics" ${OPT_DEF_GCC_ATOMICS})
@@ -905,6 +908,39 @@ if(SDL_ASSEMBLY)
endif()
endif()
+ if(SDL_LSX)
+ cmake_push_check_state()
+ list(APPEND CMAKE_REQUIRED_FLAGS "-mlsx")
+ check_c_source_compiles([[
+ #ifndef __loongarch_sx
+ #error Assembler CPP flag not enabled
+ #endif
+ ]] CPU_HAS_LSX)
+ check_include_file("lsxintrin.h" HAVE_LSXINTRIN_H)
+ cmake_pop_check_state()
+
+ if(CPU_HAS_LSX AND HAVE_LSXINTRIN_H)
+ list(APPEND EXTRA_CFLAGS "-mlsx")
+ set(HAS_LSX TRUE)
+ endif()
+ endif()
+
+ if(SDL_LASX)
+ cmake_push_check_state()
+ list(APPEND CMAKE_REQUIRED_FLAGS "-mlasx")
+ check_c_source_compiles([[
+ #ifndef __loongarch_asx
+ #error Assembler CPP flag not enabled
+ #endif
+ ]] CPU_HAS_LASX)
+ check_include_file("lasxintrin.h" HAVE_LASXINTRIN_H)
+ cmake_pop_check_state()
+ if(CPU_HAS_LASX AND HAVE_LASXINTRIN_H)
+ list(APPEND EXTRA_CFLAGS "-mlasx")
+ set(HAS_LASX TRUE)
+ endif()
+ endif()
+
if(SDL_ARMSIMD)
set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x assembler-with-cpp")
diff --git a/cmake/CheckCPUArchitecture.cmake b/cmake/CheckCPUArchitecture.cmake
index 79639f1..7e3e459 100644
--- a/cmake/CheckCPUArchitecture.cmake
+++ b/cmake/CheckCPUArchitecture.cmake
@@ -32,6 +32,8 @@ function(check_cpu_architecture ARCH VARIABLE)
_internal_check_cpu_architecture("defined(__arm__) || defined(_M_ARM)" arm32 ${VARIABLE})
elseif(ARCH STREQUAL "arm64")
_internal_check_cpu_architecture("defined(__aarch64__) || defined(_M_ARM64)" arm64 ${VARIABLE})
+ elseif(ARCH STREQUAL "loongarch64")
+ _internal_check_cpu_architecture("defined(__loongarch64)" loongarch64 ${VARIABLE})
else()
message(WARNING "Unknown CPU architectures (${ARCH}).")
set(${VARIABLE} FALSE)