From 2276eece0ea2eb430118f9eb87e88e80c1c84aa3 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 20 Nov 2009 15:14:27 -0700 Subject: [PATCH] support atomicCompareAndSwap on powerpc for GCC versions prior to 4.1 --- src/powerpc.h | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/powerpc.h b/src/powerpc.h index 20b512c16e..1b906537cc 100644 --- a/src/powerpc.h +++ b/src/powerpc.h @@ -91,16 +91,33 @@ syncInstructionCache(const void* start, unsigned size) } #ifdef USE_ATOMIC_OPERATIONS -# if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 1) inline bool atomicCompareAndSwap(uintptr_t* p, uintptr_t old, uintptr_t new_) { +#if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 1) return __sync_bool_compare_and_swap(p, old, new_); +#else // not GCC >= 4.1 + bool result; + + __asm__ __volatile__(" sync\n" + "1:\n" + " lwarx %0,0,%2\n" + " cmpw %0,%3\n" + " bne- 2f\n" + " stwcx. %4,0,%2\n" + " bne- 1b\n" + " isync \n" + "2:\n" + " xor %0,%0,%3\n" + " cntlzw %0,%0\n" + " srwi %0,%0,5\n" + : "=&r"(result), "+m"(*p) + : "r"(p), "r"(old), "r"(new_) + : "cc", "memory"); + + return result; +#endif // not GCC >= 4.1 } -# else // not GCC >= 4.1 -// todo: implement using inline assembly -# undef USE_ATOMIC_OPERATIONS -# endif // not GCC >= 4.1 #endif // USE_ATOMIC_OPERATIONS inline uint64_t