From 0b3b33f727a61a08788a10b0a85d54a50e448408 Mon Sep 17 00:00:00 2001 From: Patrick Babb <72764527+patrickbabb@users.noreply.github.com> Date: Tue, 18 Mar 2025 21:55:59 -0500 Subject: [PATCH 1/3] Update SDL_spinlock.c --- .../SDL/src/atomic/SDL_spinlock.c | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/JGE/Dependencies/SDL/src/atomic/SDL_spinlock.c b/JGE/Dependencies/SDL/src/atomic/SDL_spinlock.c index 07c26308a..b3ff36cee 100644 --- a/JGE/Dependencies/SDL/src/atomic/SDL_spinlock.c +++ b/JGE/Dependencies/SDL/src/atomic/SDL_spinlock.c @@ -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(); From 4df4422d938d5aa069e073c3b9491f97c5f52ec8 Mon Sep 17 00:00:00 2001 From: Patrick Babb <72764527+patrickbabb@users.noreply.github.com> Date: Tue, 18 Mar 2025 21:58:59 -0500 Subject: [PATCH 2/3] Update Application.mk Updated ABI target to arm64-v8a. Added CFLAG for arm8.1-a. Added CPPFLAG for LSE --- projects/mtg/Android/jni/Application.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/projects/mtg/Android/jni/Application.mk b/projects/mtg/Android/jni/Application.mk index 3aebe4ea6..2f2fa4698 100644 --- a/projects/mtg/Android/jni/Application.mk +++ b/projects/mtg/Android/jni/Application.mk @@ -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 From 91d588c670e54b79eb0263def5b2cb545d4d3338 Mon Sep 17 00:00:00 2001 From: Patrick Babb <72764527+patrickbabb@users.noreply.github.com> Date: Tue, 18 Mar 2025 22:01:55 -0500 Subject: [PATCH 3/3] Update spinlock_gcc_arm.hpp Added logic to use LSE as a primary instead of Swap. --- .../smart_ptr/detail/spinlock_gcc_arm.hpp | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Boost/boost/smart_ptr/detail/spinlock_gcc_arm.hpp b/Boost/boost/smart_ptr/detail/spinlock_gcc_arm.hpp index 7d7c78698..95a27a587 100644 --- a/Boost/boost/smart_ptr/detail/spinlock_gcc_arm.hpp +++ b/Boost/boost/smart_ptr/detail/spinlock_gcc_arm.hpp @@ -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; }