Skip to content

Commit 8bb39c6

Browse files
committed
cmake: enable x86 and neon simd for Apple multi-arch configurations
Reference issue libsdl-org#12731
1 parent 8756536 commit 8bb39c6

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,10 @@ if(SDL_ASSEMBLY)
679679
set(HAVE_ASSEMBLY TRUE)
680680

681681
if(SDL_MMX)
682+
if(APPLE_MULTIARCH AND SDL_CPU_X64)
683+
set(HAVE_MMX TRUE)
684+
message(STATUS "SIMD: MMX enabled for Apple multi-arch config")
685+
else()
682686
cmake_push_check_state()
683687
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
684688
string(APPEND CMAKE_REQUIRED_FLAGS " -mmmx")
@@ -698,8 +702,13 @@ if(SDL_ASSEMBLY)
698702
if(COMPILER_SUPPORTS_MMX)
699703
set(HAVE_MMX TRUE)
700704
endif()
705+
endif()
701706
endif()
702707
if(SDL_SSE)
708+
if(APPLE_MULTIARCH AND SDL_CPU_X64)
709+
set(HAVE_SSE TRUE)
710+
message(STATUS "SIMD: SSE enabled for Apple multi-arch config")
711+
else()
703712
cmake_push_check_state()
704713
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
705714
string(APPEND CMAKE_REQUIRED_FLAGS " -msse")
@@ -719,8 +728,13 @@ if(SDL_ASSEMBLY)
719728
if(COMPILER_SUPPORTS_SSE)
720729
set(HAVE_SSE TRUE)
721730
endif()
731+
endif()
722732
endif()
723733
if(SDL_SSE2)
734+
if(APPLE_MULTIARCH AND SDL_CPU_X64)
735+
set(HAVE_SSE2 TRUE)
736+
message(STATUS "SIMD: SSE2 enabled for Apple multi-arch config")
737+
else()
724738
cmake_push_check_state()
725739
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
726740
string(APPEND CMAKE_REQUIRED_FLAGS " -msse2")
@@ -740,8 +754,13 @@ if(SDL_ASSEMBLY)
740754
if(COMPILER_SUPPORTS_SSE2)
741755
set(HAVE_SSE2 TRUE)
742756
endif()
757+
endif()
743758
endif()
744759
if(SDL_SSE3)
760+
if(APPLE_MULTIARCH AND SDL_CPU_X64)
761+
set(HAVE_SSE3 TRUE)
762+
message(STATUS "SIMD: SSE3 enabled for Apple multi-arch config")
763+
else()
745764
cmake_push_check_state()
746765
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
747766
string(APPEND CMAKE_REQUIRED_FLAGS " -msse3")
@@ -762,7 +781,12 @@ if(SDL_ASSEMBLY)
762781
set(HAVE_SSE3 TRUE)
763782
endif()
764783
endif()
784+
endif()
765785
if(SDL_SSE4_1)
786+
if(APPLE_MULTIARCH AND SDL_CPU_X64)
787+
set(HAVE_SSE4_1 TRUE)
788+
message(STATUS "SIMD: SSE4.1 enabled for Apple multi-arch config")
789+
else()
766790
cmake_push_check_state()
767791
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
768792
string(APPEND CMAKE_REQUIRED_FLAGS " -msse4.1")
@@ -782,8 +806,13 @@ if(SDL_ASSEMBLY)
782806
if(COMPILER_SUPPORTS_SSE4_1)
783807
set(HAVE_SSE4_1 TRUE)
784808
endif()
809+
endif()
785810
endif()
786811
if(SDL_SSE4_2)
812+
if(APPLE_MULTIARCH AND SDL_CPU_X64)
813+
set(HAVE_SSE4_2 TRUE)
814+
message(STATUS "SIMD: SSE4.2 enabled for Apple multi-arch config")
815+
else()
787816
cmake_push_check_state()
788817
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
789818
string(APPEND CMAKE_REQUIRED_FLAGS " -msse4.2")
@@ -800,8 +829,13 @@ if(SDL_ASSEMBLY)
800829
if(COMPILER_SUPPORTS_SSE4_2)
801830
set(HAVE_SSE4_2 TRUE)
802831
endif()
832+
endif()
803833
endif()
804834
if(SDL_AVX)
835+
if(APPLE_MULTIARCH AND SDL_CPU_X64)
836+
set(HAVE_AVX TRUE)
837+
message(STATUS "SIMD: AVX enabled for Apple multi-arch config")
838+
else()
805839
cmake_push_check_state()
806840
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
807841
string(APPEND CMAKE_REQUIRED_FLAGS " -mavx")
@@ -821,8 +855,13 @@ if(SDL_ASSEMBLY)
821855
if(COMPILER_SUPPORTS_AVX)
822856
set(HAVE_AVX TRUE)
823857
endif()
858+
endif()
824859
endif()
825860
if(SDL_AVX2)
861+
if(APPLE_MULTIARCH AND SDL_CPU_X64)
862+
set(HAVE_AVX2 TRUE)
863+
message(STATUS "SIMD: AVX2 enabled for Apple multi-arch config")
864+
else()
826865
cmake_push_check_state()
827866
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
828867
string(APPEND CMAKE_REQUIRED_FLAGS " -mavx2")
@@ -842,8 +881,13 @@ if(SDL_ASSEMBLY)
842881
if(COMPILER_SUPPORTS_AVX2)
843882
set(HAVE_AVX2 TRUE)
844883
endif()
884+
endif()
845885
endif()
846886
if(SDL_AVX512F)
887+
if(APPLE_MULTIARCH AND SDL_CPU_X64)
888+
set(HAVE_AVX512F TRUE)
889+
message(STATUS "SIMD: AVX512F enabled for Apple multi-arch config")
890+
else()
847891
cmake_push_check_state()
848892
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
849893
string(APPEND CMAKE_REQUIRED_FLAGS " -mavx512f")
@@ -863,9 +907,14 @@ if(SDL_ASSEMBLY)
863907
if(COMPILER_SUPPORTS_AVX512F)
864908
set(HAVE_AVX512F TRUE)
865909
endif()
910+
endif()
866911
endif()
867912

868913
if(SDL_ARMNEON)
914+
if(APPLE_MULTIARCH AND SDL_CPU_ARM64)
915+
set(HAVE_ARMNEON TRUE)
916+
message(STATUS "SIMD: NEON enabled for Apple multi-arch config")
917+
else()
869918
check_c_source_compiles("
870919
#include <arm_neon.h>
871920
void floats_add(float *dest, float *a, float *b, unsigned size) {
@@ -881,6 +930,7 @@ if(SDL_ASSEMBLY)
881930
if(COMPILER_SUPPORTS_ARMNEON)
882931
set(HAVE_ARMNEON TRUE)
883932
endif()
933+
endif()
884934
endif()
885935

886936
if(USE_GCC OR USE_CLANG)

cmake/sdlcpu.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ function(SDL_DetectTargetCPUArchitectures DETECTED_ARCHS)
33
set(known_archs EMSCRIPTEN ARM32 ARM64 ARM64EC LOONGARCH64 POWERPC32 POWERPC64 X86 X64)
44

55
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
6+
list(LENGTH CMAKE_OSX_ARCHITECTURES _num_arches)
7+
if(_num_arches GREATER 1)
8+
set(APPLE_MULTIARCH 1 PARENT_SCOPE)
9+
endif()
610
foreach(known_arch IN LISTS known_archs)
711
set(SDL_CPU_${known_arch} "0" PARENT_SCOPE)
812
endforeach()

0 commit comments

Comments
 (0)