Merge pull request #1110 from patrickbabb/master

Updates to target arm64-v8a Android devices
This commit is contained in:
Eduardo MG
2025-03-21 22:08:19 -06:00
committed by GitHub
3 changed files with 50 additions and 15 deletions

View File

@@ -29,11 +29,30 @@ public:
{
int r;
#if defined(__ARM_FEATURE_LSE)
// Use LSE atomic instructions if supported
#pragma message("LSE feature detected") // This will print a message in your build logs
__asm__ __volatile__(
"swp %0, %1, [%2]":
"=&r"( r ): // outputs
"r"( 1 ), "r"( &v_ ): // inputs
"memory", "cc" );
"ldaxr %0, [%1];" // Load-Exclusive instruction
"cbnz %0, 1f;" // If the value is non-zero, the lock is already acquired
"stlxr %w0, %2, [%1];" // Store-Exclusive instruction
"cbnz %w0, 1f;" // If the store failed, retry
"mov %0, #0;" // Success, zero indicates lock acquired
"1:"
: "=&r"(r)
: "r"(&v_), "r"(1)
: "memory", "cc"
);
#else
// Fallback for systems that don't support LSE
#pragma message("LSE feature not detected") // This will print a message in your build logs if LSE is not detected
__asm__ __volatile__(
"swp %0, %1, [%2];" // Swap instruction (used as a fallback)
: "=&r"(r) // output constraint
: "r"(1), "r"(&v_) // input constraints
: "memory", "cc" // clobbered registers
);
#endif
return r == 0;
}

View File

@@ -14,10 +14,11 @@
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
2. Altered source versions must be plainly marked as such, and must not
be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_stdinc.h"
#include "SDL_atomic.h"
@@ -30,8 +31,7 @@
#endif
/* This function is where all the magic happens... */
SDL_bool
SDL_AtomicTryLock(SDL_SpinLock *lock)
SDL_bool SDL_AtomicTryLock(SDL_SpinLock *lock)
{
#if SDL_ATOMIC_DISABLED
/* Terrible terrible damage */
@@ -85,13 +85,27 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
return (result == 0);
#else
/* Need CPU instructions for spinlock here! */
__need_spinlock_implementation__
/* Fallback implementation using a standard mutex */
/* You can use SDL_mutex as a fallback if no atomic instructions are available */
static SDL_mutex *mutex;
if (!mutex) {
mutex = SDL_CreateMutex();
}
SDL_mutexP(mutex);
if (*lock == 0) {
*lock = 1;
SDL_mutexV(mutex);
return SDL_TRUE;
} else {
SDL_mutexV(mutex);
return SDL_FALSE;
}
#endif
}
void
SDL_AtomicLock(SDL_SpinLock *lock)
void SDL_AtomicLock(SDL_SpinLock *lock)
{
/* FIXME: Should we have an eventual timeout? */
while (!SDL_AtomicTryLock(lock)) {
@@ -99,8 +113,7 @@ SDL_AtomicLock(SDL_SpinLock *lock)
}
}
void
SDL_AtomicUnlock(SDL_SpinLock *lock)
void SDL_AtomicUnlock(SDL_SpinLock *lock)
{
#if defined(_MSC_VER)
_ReadWriteBarrier();

View File

@@ -1,6 +1,9 @@
APP_PROJECT_PATH := $(call my-dir)/..
APP_CPPFLAGS += -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_ABI := arm64-v8a
APP_PLATFORM := android-21
APP_CFLAGS += -march=armv8.1-a
APP_CPPFLAGS += -D__ARM_FEATURE_LSE=1
#APP_ABI := x86 # mainly for emulators
APP_STL := c++_static
APP_MODULES := libpng libjpeg main SDL