
Phil Endecott wrote:
It's in Helge's repository - http://git.chaoticmind.net/cgi-bin/cgit.cgi/boost.atomic/tree/boost/atomic/d...
Thanks. Your barriers look fine. I see that you also switch to ARM mode automatically if in __thumb__. I wonder whether there's some easier way to do that, for example by tagging the appropriate functions as ARM by some magic GCC __attribute__.
How do you detect the ARMv7 architecture to enable ldrex/strex use?
The compiler defines a macro. Unfortunately it appears not to have a simple "v6" or "v7" but instead something more detailed, and I'm not at all convinced that this detects all of the variants:
// This list of ARM architecture versions comes from Apple's arm/arch.h header. // I don't know how complete it is. #elif defined(__GNUC__) && (defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \ || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) \ || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_7A__))
Thanks for that, too. It helps to have a starting point for googling. It looks like v6 is: __ARM_ARCH_6__ __ARM_ARCH_6J__ __ARM_ARCH_6K__ __ARM_ARCH_6Z__ __ARM_ARCH_6ZK__ __ARM_ARCH_6T2__ and v7 is: __ARM_ARCH_7__ __ARM_ARCH_7A__ __ARM_ARCH_7R__ __ARM_ARCH_7M__ and maybe __ARM_ARCH_7EM__ but it looks like the only one seen in practice is indeed __ARM_ARCH_7A__. They don't make that easy.
There should be __GCC_HAVE_COMPARE_AND_SWAP_4, but I'm not sure if it's actually defined by the whatever compiler people use for iOS development.
I'm using Apple's version of gcc 4.2, and it is NOT defined there - but the intrinsic DOES exist:
#ifdef __GCC_HAVE_COMPARE_AND_SWAP_4 #warning "__GCC_HAVE_COMPARE_AND_SWAP_4 defined" #else #warning "__GCC_HAVE_COMPARE_AND_SWAP_4 NOT defined" int a, b, c; __sync_bool_compare_and_swap(&a,b,c); #endif
That outputs the "NOT defined" warning, but compiles and links OK.
Yeah, thought so. The instrinsics _probably_ work in ARMv6 and ARMv7 mode, but we can't be sure. I assume you tried that in ARMv6 mode?
I'm not quite sure what exactly DSB and ISB can be used for - maybe one of those could be enough.
I think they are used when you've changed the page tables, and similar things, and aren't appropriate here. What might be appropriate are some of the options to the DMB instruction e.g. "DMB #ST"; I think they might be new though.
I think that it's better to stay away from these.