|
| 1 | +##===- DetectLoongArchSupportVector.cmake ---------------------------------===## |
| 2 | +# |
| 3 | +# Performs a try_run with a simple program calling LSX/LASX builtin |
| 4 | +# to determine if the LoongArch CPU supports vector instructions. |
| 5 | +# This is not used for cross compile. |
| 6 | +# |
| 7 | +##===----------------------------------------------------------------------===## |
| 8 | +function(detect_loongarch_cpu_supports_sx variable) |
| 9 | + file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/SimpleProgramCallLSXBuiltin.c |
| 10 | + "#include <lsxintrin.h> |
| 11 | + int main(void) { |
| 12 | + __m128i a, b, c; |
| 13 | + c = __lsx_vand_v(a, b); |
| 14 | + return 0; |
| 15 | + }") |
| 16 | + set(SX_FLAG "-mlsx") |
| 17 | + try_run(HAVE_RUN_${variable} HAVE_COMPILE_${variable} |
| 18 | + ${CMAKE_BINARY_DIR} |
| 19 | + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/SimpleProgramCallLSXBuiltin.c |
| 20 | + CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${SX_FLAG}" |
| 21 | + COMPILE_OUTPUT_VARIABLE COMP_OUTPUT |
| 22 | + RUN_OUTPUT_VARIABLE RUN_OUTPUT) |
| 23 | + |
| 24 | + set(${variable} false PARENT_SCOPE) |
| 25 | + if(HAVE_COMPILE_${variable} AND (HAVE_RUN_${variable} EQUAL 0)) |
| 26 | + message(STATUS "Check if LoongArch cpu supports SX - Success") |
| 27 | + set(${variable} true PARENT_SCOPE) |
| 28 | + else() |
| 29 | + message(STATUS "Check if LoongArch cpu supports SX - Failed") |
| 30 | + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log |
| 31 | + "LoongArch cpu does not support SX with the following output:\n${COMP_OUTPUT}\n${RUN_OUTPUT}") |
| 32 | + endif() |
| 33 | + |
| 34 | +endfunction(detect_loongarch_cpu_supports_sx) |
| 35 | + |
| 36 | +function(detect_loongarch_cpu_supports_asx variable) |
| 37 | + file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/SimpleProgramCallLASXBuiltin.c |
| 38 | + "#include <lasxintrin.h> |
| 39 | + int main(void) { |
| 40 | + __m256i a, b, c; |
| 41 | + c = __lasx_xvand_v(a, b); |
| 42 | + return 0; |
| 43 | + }") |
| 44 | + set(ASX_FLAG "-mlasx") |
| 45 | + try_run(HAVE_RUN_${variable} HAVE_COMPILE_${variable} |
| 46 | + ${CMAKE_BINARY_DIR} |
| 47 | + ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/SimpleProgramCallLASXBuiltin.c |
| 48 | + CMAKE_FLAGS "-DCOMPILE_DEFINITIONS=${ASX_FLAG}" |
| 49 | + COMPILE_OUTPUT_VARIABLE COMP_OUTPUT |
| 50 | + RUN_OUTPUT_VARIABLE RUN_OUTPUT) |
| 51 | + |
| 52 | + set(${variable} false PARENT_SCOPE) |
| 53 | + if(HAVE_COMPILE_${variable} AND (HAVE_RUN_${variable} EQUAL 0)) |
| 54 | + message(STATUS "Check if LoongArch cpu supports ASX - Success") |
| 55 | + set(${variable} true PARENT_SCOPE) |
| 56 | + else() |
| 57 | + message(STATUS "Check if LoongArch cpu supports ASX - Failed") |
| 58 | + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log |
| 59 | + "LoongArch cpu does not support ASX with the following output:\n${COMP_OUTPUT}\n${RUN_OUTPUT}") |
| 60 | + endif() |
| 61 | + |
| 62 | +endfunction(detect_loongarch_cpu_supports_asx) |
0 commit comments