-
Notifications
You must be signed in to change notification settings - Fork 2.6k
cmake: use TargetConditionals.h for SIMD testing on Apple #12731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
sezero
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked OK to be after brief eyeballing.
|
This actions run behaves as expected now: https://github.com/libsdl-org/SDL/actions/runs/14251280259/job/39944568381?pr=12731
|
|
An Apple person should check whether the --- a/include/SDL3/SDL_intrin.h
+++ b/include/SDL3/SDL_intrin.h
@@ -356,7 +356,11 @@ _m_prefetch(void *__P)
# endif
#endif
-#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
+#ifdef __APPLE__
+#include "TargetConditionals.h"
+#endif
+
+#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) || (defined(TARGET_CPU_X86) && TARGET_CPU_X86) || (defined(TARGET_CPU_X86_64) && TARGET_CPU_X86_64)
# if ((defined(_MSC_VER) && !defined(_M_X64)) || defined(__MMX__) || defined(SDL_HAS_TARGET_ATTRIBS)) && !defined(SDL_DISABLE_MMX)
# define SDL_MMX_INTRINSICS 1
# include <mmintrin.h> |
I don't think this is necessary: TARGET_CPU_X86, for, e.g., is defined to 1 if |
be99236 to
7c9a6c9
Compare
I think we're fine. After thinking about it, CMake was failing because we were including |
| # if test_enabled | ||
| ${MAIN_BODY} | ||
| # endif | ||
| return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm reading this correctly, this x86 test will succeed for aarch64-apple (non-x86.) Similarly, the arm test below will succeed for x86_64-apple (non-arm.) Is this what you really intend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These functions will only get called if cmake is targeting x64/x86.
I'll add a fail-safe that returns false when the cpu is not x86 (and vice verse for the arm function)
|
This was forgotten?? Patches 1 and 3 are irrelevant here: They should be applied (and cherry-picked to 3.2.x) As for patch/2 which matters: It needs rebasing. But is the following simpler / more straight-forward for it? diff --git a/CMakeLists.txt b/CMakeLists.txt
index e7ae6f2..3ce5df9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -679,6 +679,9 @@ if(SDL_ASSEMBLY)
set(HAVE_ASSEMBLY TRUE)
if(SDL_MMX)
+ if(APPLE AND SDL_CPU_X64 AND SDL_CPU_ARM64)
+ set(HAVE_MMX TRUE)
+ else()
cmake_push_check_state()
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -mmmx")
@@ -698,8 +701,13 @@ if(SDL_ASSEMBLY)
if(COMPILER_SUPPORTS_MMX)
set(HAVE_MMX TRUE)
endif()
+ endif()
endif()
if(SDL_SSE)
+ if(APPLE AND SDL_CPU_X64 AND SDL_CPU_ARM64)
+ set(HAVE_SSE TRUE)
+ message("MMX enabled for Apple multi-arch config")
+ else()
cmake_push_check_state()
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -msse")
@@ -719,8 +727,13 @@ if(SDL_ASSEMBLY)
if(COMPILER_SUPPORTS_SSE)
set(HAVE_SSE TRUE)
endif()
+ endif()
endif()
if(SDL_SSE2)
+ if(APPLE AND SDL_CPU_X64 AND SDL_CPU_ARM64)
+ set(HAVE_SSE2 TRUE)
+ message("SSE2 enabled for Apple multi-arch config")
+ else()
cmake_push_check_state()
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -msse2")
@@ -740,8 +753,13 @@ if(SDL_ASSEMBLY)
if(COMPILER_SUPPORTS_SSE2)
set(HAVE_SSE2 TRUE)
endif()
+ endif()
endif()
if(SDL_SSE3)
+ if(APPLE AND SDL_CPU_X64 AND SDL_CPU_ARM64)
+ set(HAVE_SSE3 TRUE)
+ message("SSE3 enabled for Apple multi-arch config")
+ else()
cmake_push_check_state()
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -msse3")
@@ -762,7 +780,12 @@ if(SDL_ASSEMBLY)
set(HAVE_SSE3 TRUE)
endif()
endif()
+ endif()
if(SDL_SSE4_1)
+ if(APPLE AND SDL_CPU_X64 AND SDL_CPU_ARM64)
+ set(HAVE_SSE4_1 TRUE)
+ message("SSE4.1 enabled for Apple multi-arch config")
+ else()
cmake_push_check_state()
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -msse4.1")
@@ -782,8 +805,13 @@ if(SDL_ASSEMBLY)
if(COMPILER_SUPPORTS_SSE4_1)
set(HAVE_SSE4_1 TRUE)
endif()
+ endif()
endif()
if(SDL_SSE4_2)
+ if(APPLE AND SDL_CPU_X64 AND SDL_CPU_ARM64)
+ set(HAVE_SSE4_2 TRUE)
+ message("SSE4.2 enabled for Apple multi-arch config")
+ else()
cmake_push_check_state()
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -msse4.2")
@@ -800,8 +828,13 @@ if(SDL_ASSEMBLY)
if(COMPILER_SUPPORTS_SSE4_2)
set(HAVE_SSE4_2 TRUE)
endif()
+ endif()
endif()
if(SDL_AVX)
+ if(APPLE AND SDL_CPU_X64 AND SDL_CPU_ARM64)
+ set(HAVE_AVX TRUE)
+ message("AVX enabled for Apple multi-arch config")
+ else()
cmake_push_check_state()
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -mavx")
@@ -821,8 +854,13 @@ if(SDL_ASSEMBLY)
if(COMPILER_SUPPORTS_AVX)
set(HAVE_AVX TRUE)
endif()
+ endif()
endif()
if(SDL_AVX2)
+ if(APPLE AND SDL_CPU_X64 AND SDL_CPU_ARM64)
+ set(HAVE_AVX2 TRUE)
+ message("AVX2 enabled for Apple multi-arch config")
+ else()
cmake_push_check_state()
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -mavx2")
@@ -842,8 +880,13 @@ if(SDL_ASSEMBLY)
if(COMPILER_SUPPORTS_AVX2)
set(HAVE_AVX2 TRUE)
endif()
+ endif()
endif()
if(SDL_AVX512F)
+ if(APPLE AND SDL_CPU_X64 AND SDL_CPU_ARM64)
+ set(HAVE_AVX512F TRUE)
+ message("AVX512F enabled for Apple multi-arch config")
+ else()
cmake_push_check_state()
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -mavx512f")
@@ -863,9 +906,13 @@ if(SDL_ASSEMBLY)
if(COMPILER_SUPPORTS_AVX512F)
set(HAVE_AVX512F TRUE)
endif()
+ endif()
endif()
if(SDL_ARMNEON)
+ if(APPLE AND SDL_CPU_X64 AND SDL_CPU_ARM64)
+ set(HAVE_ARMNEON TRUE)
+ else()
check_c_source_compiles("
#include <arm_neon.h>
void floats_add(float *dest, float *a, float *b, unsigned size) {
@@ -881,6 +928,7 @@ if(SDL_ASSEMBLY)
if(COMPILER_SUPPORTS_ARMNEON)
set(HAVE_ARMNEON TRUE)
endif()
+ endif()
endif()
if(USE_GCC OR USE_CLANG) |
|
See #13839 for an alternative to patch/2 |
7c9a6c9 to
f9b8955
Compare
sezero
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checks in Apple multi-arch configs are pointless IMO.
Besides the NEON check seems to always fail...
expands to <nothing> on e.g. Windows, which will be interpreted as true by cmake_dependent_option.
f9b8955 to
731311f
Compare
The errors were because of a copy/paste error (using
I'd prefer to keep the tests, and let the "fast" things move to |
731311f to
bdf2486
Compare
OK, we won't agree :) I'll defer to Sam's judgement. |
|
Now that Sam approved this one, I'd like to close #13839. diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9591315..f8bb29d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -80,6 +80,12 @@ include("${SDL3_SOURCE_DIR}/cmake/PreseedNokiaNGageCache.cmake")
SDL_DetectCompiler()
SDL_DetectTargetCPUArchitectures(SDL_CPUS)
+if(APPLE AND CMAKE_OSX_ARCHITECTURES)
+ list(LENGTH CMAKE_OSX_ARCHITECTURES _num_arches)
+ if(_num_arches GREATER 1)
+ set(APPLE_MULTIARCH TRUE)
+ endif()
+endif()
# Increment this if there is an incompatible change - but if that happens,
# we should rename the library from SDL3 to SDL4, at which point this would
diff --git a/cmake/sdlcompilers.cmake b/cmake/sdlcompilers.cmake
index f4e43b7..af80a8e 100644
--- a/cmake/sdlcompilers.cmake
+++ b/cmake/sdlcompilers.cmake
@@ -165,20 +165,19 @@ function(check_x86_source_compiles BODY VAR)
if(ARGN)
message(FATAL_ERROR "Unknown arguments: ${ARGN}")
endif()
- if(APPLE AND DEFINED CMAKE_OSX_ARCHITECTURES)
+ if(APPLE_MULTIARCH AND (SDL_CPU_X86 OR SDL_CPU_X64))
set(test_conditional 1)
else()
set(test_conditional 0)
endif()
check_c_source_compiles("
#if ${test_conditional}
- # include \"TargetConditionals.h\"
- # if TARGET_CPU_X86 || TARGET_CPU_X86_64
+ # if defined(__i386__) || defined(__x86_64__)
# define test_enabled 1
# else
- # define test_enabled 0
+ # define test_enabled 0 /* feign success in Apple multi-arch configs */
# endif
- #else
+ #else /* test normally */
# define test_enabled 1
#endif
#if test_enabled
@@ -196,20 +195,19 @@ function(check_arm_source_compiles BODY VAR)
if(ARGN)
message(FATAL_ERROR "Unknown arguments: ${ARGN}")
endif()
- if(APPLE AND DEFINED CMAKE_OSX_ARCHITECTURES)
+ if(APPLE_MULTIARCH AND (SDL_CPU_ARM32 OR SDL_CPU_ARM64))
set(test_conditional 1)
else()
set(test_conditional 0)
endif()
check_c_source_compiles("
#if ${test_conditional}
- # include \"TargetConditionals.h\"
- # if TARGET_CPU_ARM || TARGET_CPU_ARM64
+ # if defined(__arm__) || defined(__aarch64__)
# define test_enabled 1
# else
- # define test_enabled 0
+ # define test_enabled 0 /* feign success in Apple multi-arch configs */
# endif
- #else
+ #else /* test normally */
# define test_enabled 1
#endif
#if test_enabled |
Makes total sense to me. Feel free to apply (and while you're at it, also cherry-pick this one to the 3.2.x branch). |
Applied as 83bb0f9
Done |
I think
include/SDL3/SDL_intrin.hshould get a similar makeover.