Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

madebr
Copy link
Contributor

@madebr madebr commented Apr 3, 2025

I think include/SDL3/SDL_intrin.h should get a similar makeover.

 expands to <nothing> on e.g. Windows, which will be interpreted as true by cmake_dependent_option.
Copy link
Contributor

@sezero sezero left a 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.

@madebr
Copy link
Contributor Author

madebr commented Apr 3, 2025

This actions run behaves as expected now: https://github.com/libsdl-org/SDL/actions/runs/14251280259/job/39944568381?pr=12731

  • it uses -DCMAKE_OSX_ARCHITECTURES=x86_64;arm64
  • all simd extensions (mmx, sse, avx, neon) are supported, so no #define SDL_DISABLE_xxx's in the generated SDL_build_config.h

@madebr
Copy link
Contributor Author

madebr commented Apr 3, 2025

An Apple person should check whether the SDL_intrin.h behaves as expected.
The header would need this, and perhaps additional changes.

--- 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>

@slouken slouken added this to the 3.4.0 milestone Apr 3, 2025
@madebr madebr marked this pull request as draft April 3, 2025 19:54
@sezero
Copy link
Contributor

sezero commented Apr 3, 2025

An Apple person should check whether the SDL_intrin.h behaves as expected. The header would need this, and perhaps additional changes.

--- 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 __i386__ is defined (otherwise to 0). Similarly, TARGET_CPU_X86_64 is defined to 1 if __x86_64__ is defined (otherwise to 0). In short, we are already covering those cases here. Am I missing something?

@madebr madebr force-pushed the cmake-apple-fat-simd branch from be99236 to 7c9a6c9 Compare April 3, 2025 20:01
@madebr
Copy link
Contributor Author

madebr commented Apr 3, 2025

I don't think this is necessary: TARGET_CPU_X86, for, e.g., is defined to 1 if __i386__ is defined (otherwise to 0). Similarly, TARGET_CPU_X86_64 is defined to 1 if __x86_64__ is defined (otherwise to 0). In short, we are already covering those cases here. Am I missing something?

I think we're fine. After thinking about it, CMake was failing because we were including <xmmintrin.h> when targeting arm64.

@madebr madebr marked this pull request as ready for review April 3, 2025 20:15
# if test_enabled
${MAIN_BODY}
# endif
return 0;
Copy link
Contributor

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?

Copy link
Contributor Author

@madebr madebr Apr 4, 2025

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)

@sezero sezero self-requested a review April 4, 2025 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants