-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2421 from pygame-community/simd-transform-setup
Add SIMD functionality to the transform submodule (Attempt 2)
- Loading branch information
Showing
11 changed files
with
169 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#define NO_PYGAME_C_API | ||
#ifndef SIMD_SHARED_H | ||
#define SIMD_SHARED_H | ||
|
||
#include "_surface.h" | ||
|
||
int | ||
pg_sse2_at_runtime_but_uncompiled(); | ||
int | ||
pg_neon_at_runtime_but_uncompiled(); | ||
int | ||
pg_avx2_at_runtime_but_uncompiled(); | ||
int | ||
pg_has_avx2(); | ||
|
||
#if !defined(PG_ENABLE_ARM_NEON) && defined(__aarch64__) | ||
// arm64 has neon optimisations enabled by default, even when fpu=neon is not | ||
// passed | ||
#define PG_ENABLE_ARM_NEON 1 | ||
#endif | ||
|
||
/* See if we are compiled 64 bit on GCC or MSVC */ | ||
#if _WIN32 || _WIN64 | ||
#if _WIN64 | ||
#define ENV64BIT | ||
#endif | ||
#endif | ||
|
||
// Check GCC | ||
#if __GNUC__ | ||
#if __x86_64__ || __ppc64__ || __aarch64__ | ||
#define ENV64BIT | ||
#endif | ||
#endif | ||
|
||
#if PG_ENABLE_ARM_NEON | ||
// sse2neon.h is from here: https://github.com/DLTcollab/sse2neon | ||
#include "include/sse2neon.h" | ||
#endif /* PG_ENABLE_ARM_NEON */ | ||
|
||
/* This defines PG_ENABLE_SSE_NEON as True if either SSE or NEON is available | ||
* at compile time. Since we do compile time translation of SSE2->NEON, they | ||
* have the same code paths, so this reduces code duplication of those paths. | ||
*/ | ||
#if defined(__SSE2__) | ||
#define PG_ENABLE_SSE_NEON 1 | ||
#elif PG_ENABLE_ARM_NEON | ||
#define PG_ENABLE_SSE_NEON 1 | ||
#else | ||
#define PG_ENABLE_SSE_NEON 0 | ||
#endif | ||
|
||
/* This returns True if either SSE2 or NEON is present at runtime. | ||
* Relevant because they use the same codepaths. Only the relevant runtime | ||
* SDL cpu feature check is compiled in.*/ | ||
int | ||
pg_HasSSE_NEON() | ||
{ | ||
#if defined(__SSE2__) | ||
return SDL_HasSSE2(); | ||
#elif PG_ENABLE_ARM_NEON | ||
return SDL_HasNEON(); | ||
#else | ||
return 0; | ||
#endif | ||
} | ||
|
||
#endif // SIMD_SHARED_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#define NO_PYGAME_C_API | ||
#include "_surface.h" | ||
|
||
#if !defined(PG_ENABLE_ARM_NEON) && defined(__aarch64__) | ||
// arm64 has neon optimisations enabled by default, even when fpu=neon is not | ||
// passed | ||
#define PG_ENABLE_ARM_NEON 1 | ||
#endif | ||
|
||
// SSE2 functions | ||
#if defined(__SSE2__) || defined(PG_ENABLE_ARM_NEON) | ||
#endif /* (defined(__SSE2__) || defined(PG_ENABLE_ARM_NEON)) */ | ||
|
||
// AVX2 functions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "simd_transform.h" | ||
|
||
#if defined(HAVE_IMMINTRIN_H) && !defined(SDL_DISABLE_IMMINTRIN_H) | ||
#include <immintrin.h> | ||
#endif /* defined(HAVE_IMMINTRIN_H) && !defined(SDL_DISABLE_IMMINTRIN_H) */ | ||
|
||
#define BAD_AVX2_FUNCTION_CALL \ | ||
printf( \ | ||
"Fatal Error: Attempted calling an AVX2 function when both compile " \ | ||
"time and runtime support is missing. If you are seeing this " \ | ||
"message, you have stumbled across a pygame bug, please report it " \ | ||
"to the devs!"); \ | ||
PG_EXIT(1) | ||
|
||
/* helper function that does a runtime check for AVX2. It has the added | ||
* functionality of also returning 0 if compile time support is missing */ | ||
int | ||
pg_has_avx2() | ||
{ | ||
#if defined(__AVX2__) && defined(HAVE_IMMINTRIN_H) && \ | ||
!defined(SDL_DISABLE_IMMINTRIN_H) | ||
return SDL_HasAVX2(); | ||
#else | ||
return 0; | ||
#endif /* defined(__AVX2__) && defined(HAVE_IMMINTRIN_H) && \ | ||
!defined(SDL_DISABLE_IMMINTRIN_H) */ | ||
} | ||
|
||
/* This returns 1 when avx2 is available at runtime but support for it isn't | ||
* compiled in, 0 in all other cases */ | ||
int | ||
pg_avx2_at_runtime_but_uncompiled() | ||
{ | ||
if (SDL_HasAVX2()) { | ||
#if defined(__AVX2__) && defined(HAVE_IMMINTRIN_H) && \ | ||
!defined(SDL_DISABLE_IMMINTRIN_H) | ||
return 0; | ||
#else | ||
return 1; | ||
#endif /* defined(__AVX2__) && defined(HAVE_IMMINTRIN_H) && \ | ||
!defined(SDL_DISABLE_IMMINTRIN_H) */ | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "simd_transform.h" | ||
|
||
#if PG_ENABLE_ARM_NEON | ||
// sse2neon.h is from here: https://github.com/DLTcollab/sse2neon | ||
#include "include/sse2neon.h" | ||
#endif /* PG_ENABLE_ARM_NEON */ | ||
|
||
/* This returns 1 when sse2 is available at runtime but support for it isn't | ||
* compiled in, 0 in all other cases */ | ||
int | ||
pg_sse2_at_runtime_but_uncompiled() | ||
{ | ||
if (SDL_HasSSE2()) { | ||
#ifdef __SSE2__ | ||
return 0; | ||
#else | ||
return 1; | ||
#endif /* __SSE2__ */ | ||
} | ||
return 0; | ||
} | ||
|
||
/* This returns 1 when neon is available at runtime but support for it isn't | ||
* compiled in, 0 in all other cases */ | ||
int | ||
pg_neon_at_runtime_but_uncompiled() | ||
{ | ||
if (SDL_HasNEON()) { | ||
#if PG_ENABLE_ARM_NEON | ||
return 0; | ||
#else | ||
return 1; | ||
#endif /* PG_ENABLE_ARM_NEON */ | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters