Skip to content

Commit 8084d55

Browse files
authored
cmake : ARM intrinsics detection for MSVC (#5401)
1 parent aa23412 commit 8084d55

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,11 +855,21 @@ if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64" OR CMAKE_GENERATOR_PLATFORM_LWR STR
855855
CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm.*|ARM64)$"))
856856
message(STATUS "ARM detected")
857857
if (MSVC)
858+
add_compile_definitions(__aarch64__) # MSVC defines _M_ARM64 instead
858859
add_compile_definitions(__ARM_NEON)
859860
add_compile_definitions(__ARM_FEATURE_FMA)
860-
add_compile_definitions(__ARM_FEATURE_DOTPROD)
861-
# add_compile_definitions(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) # MSVC doesn't support vdupq_n_f16, vld1q_f16, vst1q_f16
862-
add_compile_definitions(__aarch64__) # MSVC defines _M_ARM64 instead
861+
862+
set(CMAKE_REQUIRED_FLAGS_PREV ${CMAKE_REQUIRED_FLAGS})
863+
string(JOIN " " CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} "/arch:armv8.2")
864+
check_cxx_source_compiles("#include <arm_neon.h>\nint main() { int8x16_t _a, _b; int32x4_t _s = vdotq_s32(_s, _a, _b); return 0; }" GGML_COMPILER_SUPPORT_DOTPROD)
865+
if (GGML_COMPILER_SUPPORT_DOTPROD)
866+
add_compile_definitions(__ARM_FEATURE_DOTPROD)
867+
endif ()
868+
check_cxx_source_compiles("#include <arm_neon.h>\nint main() { float16_t _a; float16x8_t _s = vdupq_n_f16(_a); return 0; }" GGML_COMPILER_SUPPORT_FP16_VECTOR_ARITHMETIC)
869+
if (GGML_COMPILER_SUPPORT_FP16_VECTOR_ARITHMETIC)
870+
add_compile_definitions(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC)
871+
endif ()
872+
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_PREV})
863873
else()
864874
check_cxx_compiler_flag(-mfp16-format=ieee COMPILER_SUPPORTS_FP16_FORMAT_I3E)
865875
if (NOT "${COMPILER_SUPPORTS_FP16_FORMAT_I3E}" STREQUAL "")

0 commit comments

Comments
 (0)