From f416fd7a9e90d00090c7fa99a9a585b5a5c575aa Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 5 Feb 2024 14:08:21 +1000 Subject: [PATCH] UnitTests: Only build SSE4 on Apple Silicon host --- tests/ctest/core/CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/ctest/core/CMakeLists.txt b/tests/ctest/core/CMakeLists.txt index 7558cc98ba..1f4d523cdf 100644 --- a/tests/ctest/core/CMakeLists.txt +++ b/tests/ctest/core/CMakeLists.txt @@ -26,13 +26,23 @@ if(DISABLE_ADVANCE_SIMD) set(compile_options_avx -march=sandybridge -mtune=sandybridge) set(compile_options_sse4 -msse4.1 -mtune=nehalem) endif() + + # This breaks when running on Apple Silicon, because even though we skip the test itself, the + # gtest constructor still generates AVX code, and that's a global object which gets constructed + # at binary load time. So, for now, only compile SSE4 if running on ARM64. + if (NOT APPLE OR "${CMAKE_HOST_SYSTEM_PROCESSOR}" STREQUAL "x86_64") + set(isa_list "sse4" "avx" "avx2") + else() + set(isa_list "sse4") + endif() + # ODR violation time! # Everything would be fine if we only defined things in cpp files, but C++ tends to like inline functions (STL anyone?) # Each ISA will bring with it its own copies of these inline header functions, and the linker gets to choose whichever one it wants! Not fun if the linker chooses the avx2 version and uses it with everything # Thankfully, most linkers don't choose at random. When presented with a bunch of .o files, most linkers seem to choose the first implementation they see, so make sure you order these from oldest to newest # Note: ld64 (macOS's linker) does not act the same way when presented with .a files, unless linked with `-force_load` (cmake WHOLE_ARCHIVE). set(is_first_isa "1") - foreach(isa "sse4" "avx" "avx2") + foreach(isa IN LISTS isa_list) add_library(core_test_${isa} STATIC ${multi_isa_sources}) target_link_libraries(core_test_${isa} PRIVATE PCSX2_FLAGS gtest) target_compile_definitions(core_test_${isa} PRIVATE MULTI_ISA_UNSHARED_COMPILATION=isa_${isa} MULTI_ISA_IS_FIRST=${is_first_isa} ${pcsx2_defs_${isa}})