Chris@102: /* Chris@102: * Distributed under the Boost Software License, Version 1.0. Chris@102: * (See accompanying file LICENSE_1_0.txt or copy at Chris@102: * http://www.boost.org/LICENSE_1_0.txt) Chris@102: * Chris@102: * Copyright (c) 2009 Helge Bahmann Chris@102: * Copyright (c) 2013 Tim Blechmann Chris@102: * Copyright (c) 2014 Andrey Semashev Chris@102: */ Chris@102: /*! Chris@102: * \file atomic/detail/ops_gcc_arm.hpp Chris@102: * Chris@102: * This header contains implementation of the \c operations template. Chris@102: */ Chris@102: Chris@102: #ifndef BOOST_ATOMIC_DETAIL_OPS_GCC_ARM_HPP_INCLUDED_ Chris@102: #define BOOST_ATOMIC_DETAIL_OPS_GCC_ARM_HPP_INCLUDED_ Chris@102: Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: Chris@102: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@102: #pragma once Chris@102: #endif Chris@102: Chris@102: namespace boost { Chris@102: namespace atomics { Chris@102: namespace detail { Chris@102: Chris@102: // From the ARM Architecture Reference Manual for architecture v6: Chris@102: // Chris@102: // LDREX{} , [] Chris@102: // Specifies the destination register for the memory word addressed by Chris@102: // Specifies the register containing the address. Chris@102: // Chris@102: // STREX{} , , [] Chris@102: // Specifies the destination register for the returned status value. Chris@102: // 0 if the operation updates memory Chris@102: // 1 if the operation fails to update memory Chris@102: // Specifies the register containing the word to be stored to memory. Chris@102: // Specifies the register containing the address. Chris@102: // Rd must not be the same register as Rm or Rn. Chris@102: // Chris@102: // ARM v7 is like ARM v6 plus: Chris@102: // There are half-word and byte versions of the LDREX and STREX instructions, Chris@102: // LDREXH, LDREXB, STREXH and STREXB. Chris@102: // There are also double-word versions, LDREXD and STREXD. Chris@102: // (Actually it looks like these are available from version 6k onwards.) Chris@102: // FIXME these are not yet used; should be mostly a matter of copy-and-paste. Chris@102: // I think you can supply an immediate offset to the address. Chris@102: // Chris@102: // A memory barrier is effected using a "co-processor 15" instruction, Chris@102: // though a separate assembler mnemonic is available for it in v7. Chris@102: // Chris@102: // "Thumb 1" is a subset of the ARM instruction set that uses a 16-bit encoding. It Chris@102: // doesn't include all instructions and in particular it doesn't include the co-processor Chris@102: // instruction used for the memory barrier or the load-locked/store-conditional Chris@102: // instructions. So, if we're compiling in "Thumb 1" mode, we need to wrap all of our Chris@102: // asm blocks with code to temporarily change to ARM mode. Chris@102: // Chris@102: // You can only change between ARM and Thumb modes when branching using the bx instruction. Chris@102: // bx takes an address specified in a register. The least significant bit of the address Chris@102: // indicates the mode, so 1 is added to indicate that the destination code is Thumb. Chris@102: // A temporary register is needed for the address and is passed as an argument to these Chris@102: // macros. It must be one of the "low" registers accessible to Thumb code, specified Chris@102: // using the "l" attribute in the asm statement. Chris@102: // Chris@102: // Architecture v7 introduces "Thumb 2", which does include (almost?) all of the ARM Chris@102: // instruction set. (Actually, there was an extension of v6 called v6T2 which supported Chris@102: // "Thumb 2" mode, but its architecture manual is no longer available, referring to v7.) Chris@102: // So in v7 we don't need to change to ARM mode; we can write "universal Chris@102: // assembler" which will assemble to Thumb 2 or ARM code as appropriate. The only thing Chris@102: // we need to do to make this "universal" assembler mode work is to insert "IT" instructions Chris@102: // to annotate the conditional instructions. These are ignored in other modes (e.g. v6), Chris@102: // so they can always be present. Chris@102: Chris@102: // A note about memory_order_consume. Technically, this architecture allows to avoid Chris@102: // unnecessary memory barrier after consume load since it supports data dependency ordering. Chris@102: // However, some compiler optimizations may break a seemingly valid code relying on data Chris@102: // dependency tracking by injecting bogus branches to aid out of order execution. Chris@102: // This may happen not only in Boost.Atomic code but also in user's code, which we have no Chris@102: // control of. See this thread: http://lists.boost.org/Archives/boost/2014/06/213890.php. Chris@102: // For this reason we promote memory_order_consume to memory_order_acquire. Chris@102: Chris@102: #if defined(__thumb__) && !defined(__thumb2__) Chris@102: #define BOOST_ATOMIC_DETAIL_ARM_ASM_START(TMPREG) "adr " #TMPREG ", 8f\n" "bx " #TMPREG "\n" ".arm\n" ".align 4\n" "8:\n" Chris@102: #define BOOST_ATOMIC_DETAIL_ARM_ASM_END(TMPREG) "adr " #TMPREG ", 9f + 1\n" "bx " #TMPREG "\n" ".thumb\n" ".align 2\n" "9:\n" Chris@102: #define BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(var) "=&l" (var) Chris@102: #else Chris@102: // The tmpreg may be wasted in this case, which is non-optimal. Chris@102: #define BOOST_ATOMIC_DETAIL_ARM_ASM_START(TMPREG) Chris@102: #define BOOST_ATOMIC_DETAIL_ARM_ASM_END(TMPREG) Chris@102: #define BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(var) "=&r" (var) Chris@102: #endif Chris@102: Chris@102: struct gcc_arm_operations_base Chris@102: { Chris@102: static BOOST_FORCEINLINE void fence_before(memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: if ((order & memory_order_release) != 0) Chris@102: hardware_full_fence(); Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE void fence_after(memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: if ((order & (memory_order_consume | memory_order_acquire)) != 0) Chris@102: hardware_full_fence(); Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE void fence_after_store(memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: if (order == memory_order_seq_cst) Chris@102: hardware_full_fence(); Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE void hardware_full_fence() BOOST_NOEXCEPT Chris@102: { Chris@102: #if defined(BOOST_ATOMIC_DETAIL_ARM_HAS_DMB) Chris@102: // Older binutils (supposedly, older than 2.21.1) didn't support symbolic or numeric arguments of the "dmb" instruction such as "ish" or "#11". Chris@102: // As a workaround we have to inject encoded bytes of the instruction. There are two encodings for the instruction: ARM and Thumb. See ARM Architecture Reference Manual, A8.8.43. Chris@102: // Since we cannot detect binutils version at compile time, we'll have to always use this hack. Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: #if defined(__thumb2__) Chris@102: ".short 0xF3BF, 0x8F5B\n" // dmb ish Chris@102: #else Chris@102: ".word 0xF57FF05B\n" // dmb ish Chris@102: #endif Chris@102: : Chris@102: : Chris@102: : "memory" Chris@102: ); Chris@102: #else Chris@102: int tmp; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%0) Chris@102: "mcr\tp15, 0, r0, c7, c10, 5\n" Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%0) Chris@102: : "=&l" (tmp) Chris@102: : Chris@102: : "memory" Chris@102: ); Chris@102: #endif Chris@102: } Chris@102: }; Chris@102: Chris@102: Chris@102: template< bool Signed > Chris@102: struct operations< 4u, Signed > : Chris@102: public gcc_arm_operations_base Chris@102: { Chris@102: typedef typename make_storage_type< 4u, Signed >::type storage_type; Chris@102: Chris@102: static BOOST_FORCEINLINE void store(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: storage = v; Chris@102: fence_after_store(order); Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type load(storage_type const volatile& storage, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: storage_type v = storage; Chris@102: fence_after(order); Chris@102: return v; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type exchange(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: storage_type original; Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // load the original value Chris@102: "strex %[tmp], %[value], %[storage]\n" // store the replacement, tmp = store failed Chris@102: "teq %[tmp], #0\n" // check if store succeeded Chris@102: "bne 1b\n" Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [tmp] "=&l" (tmp), [original] "=&r" (original), [storage] "+Q" (storage) Chris@102: : [value] "r" (v) Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE bool compare_exchange_weak( Chris@102: storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(success_order); Chris@102: uint32_t success; Chris@102: uint32_t tmp; Chris@102: storage_type original; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "mov %[success], #0\n" // success = 0 Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "cmp %[original], %[expected]\n" // flags = original==expected Chris@102: "itt eq\n" // [hint that the following 2 instructions are conditional on flags.equal] Chris@102: "strexeq %[success], %[desired], %[storage]\n" // if (flags.equal) *(&storage) = desired, success = store failed Chris@102: "eoreq %[success], %[success], #1\n" // if (flags.equal) success ^= 1 (i.e. make it 1 if store succeeded) Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [success] "=&r" (success), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [expected] "r" (expected), // %4 Chris@102: [desired] "r" (desired) // %5 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: if (success) Chris@102: fence_after(success_order); Chris@102: else Chris@102: fence_after(failure_order); Chris@102: expected = original; Chris@102: return !!success; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE bool compare_exchange_strong( Chris@102: storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(success_order); Chris@102: uint32_t success; Chris@102: uint32_t tmp; Chris@102: storage_type original; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "mov %[success], #0\n" // success = 0 Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "cmp %[original], %[expected]\n" // flags = original==expected Chris@102: "bne 2f\n" // if (!flags.equal) goto end Chris@102: "strex %[success], %[desired], %[storage]\n" // *(&storage) = desired, success = store failed Chris@102: "eors %[success], %[success], #1\n" // success ^= 1 (i.e. make it 1 if store succeeded); flags.equal = success == 0 Chris@102: "beq 1b\n" // if (flags.equal) goto retry Chris@102: "2:\n" Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [success] "=&r" (success), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [expected] "r" (expected), // %4 Chris@102: [desired] "r" (desired) // %5 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: if (success) Chris@102: fence_after(success_order); Chris@102: else Chris@102: fence_after(failure_order); Chris@102: expected = original; Chris@102: return !!success; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "add %[result], %[original], %[value]\n" // result = original + value Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "sub %[result], %[original], %[value]\n" // result = original - value Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_and(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "and %[result], %[original], %[value]\n" // result = original & value Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_or(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "orr %[result], %[original], %[value]\n" // result = original | value Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_xor(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "eor %[result], %[original], %[value]\n" // result = original ^ value Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE bool test_and_set(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: return !!exchange(storage, (storage_type)1, order); Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE void clear(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: store(storage, 0, order); Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE bool is_lock_free(storage_type const volatile&) BOOST_NOEXCEPT Chris@102: { Chris@102: return true; Chris@102: } Chris@102: }; Chris@102: Chris@102: Chris@102: template< > Chris@102: struct operations< 1u, false > : Chris@102: public operations< 4u, false > Chris@102: { Chris@102: typedef operations< 4u, false > base_type; Chris@102: typedef base_type::storage_type storage_type; Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "add %[result], %[original], %[value]\n" // result = original + value Chris@102: "uxtb %[result], %[result]\n" // zero extend result from 8 to 32 bits Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "sub %[result], %[original], %[value]\n" // result = original - value Chris@102: "uxtb %[result], %[result]\n" // zero extend result from 8 to 32 bits Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: }; Chris@102: Chris@102: template< > Chris@102: struct operations< 1u, true > : Chris@102: public operations< 4u, true > Chris@102: { Chris@102: typedef operations< 4u, true > base_type; Chris@102: typedef base_type::storage_type storage_type; Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "add %[result], %[original], %[value]\n" // result = original + value Chris@102: "sxtb %[result], %[result]\n" // sign extend result from 8 to 32 bits Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "sub %[result], %[original], %[value]\n" // result = original - value Chris@102: "sxtb %[result], %[result]\n" // sign extend result from 8 to 32 bits Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: }; Chris@102: Chris@102: Chris@102: template< > Chris@102: struct operations< 2u, false > : Chris@102: public operations< 4u, false > Chris@102: { Chris@102: typedef operations< 4u, false > base_type; Chris@102: typedef base_type::storage_type storage_type; Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "add %[result], %[original], %[value]\n" // result = original + value Chris@102: "uxth %[result], %[result]\n" // zero extend result from 16 to 32 bits Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "sub %[result], %[original], %[value]\n" // result = original - value Chris@102: "uxth %[result], %[result]\n" // zero extend result from 16 to 32 bits Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: }; Chris@102: Chris@102: template< > Chris@102: struct operations< 2u, true > : Chris@102: public operations< 4u, true > Chris@102: { Chris@102: typedef operations< 4u, true > base_type; Chris@102: typedef base_type::storage_type storage_type; Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "add %[result], %[original], %[value]\n" // result = original + value Chris@102: "sxth %[result], %[result]\n" // sign extend result from 16 to 32 bits Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: storage_type original, result; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%[tmp]) Chris@102: "1:\n" Chris@102: "ldrex %[original], %[storage]\n" // original = *(&storage) Chris@102: "sub %[result], %[original], %[value]\n" // result = original - value Chris@102: "sxth %[result], %[result]\n" // sign extend result from 16 to 32 bits Chris@102: "strex %[tmp], %[result], %[storage]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %[tmp], #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%[tmp]) Chris@102: : [original] "=&r" (original), // %0 Chris@102: [result] "=&r" (result), // %1 Chris@102: [tmp] "=&l" (tmp), // %2 Chris@102: [storage] "+Q" (storage) // %3 Chris@102: : [value] "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: }; Chris@102: Chris@102: Chris@102: #if defined(BOOST_ATOMIC_DETAIL_ARM_HAS_LDREXD_STREXD) Chris@102: Chris@102: // Unlike 32-bit operations, for 64-bit loads and stores we must use ldrexd/strexd. Chris@102: // Any other instructions result in a non-atomic sequence of 32-bit accesses. Chris@102: // See "ARM Architecture Reference Manual ARMv7-A and ARMv7-R edition", Chris@102: // Section A3.5.3 "Atomicity in the ARM architecture". Chris@102: Chris@102: // In the asm blocks below we have to use 32-bit register pairs to compose 64-bit values. Chris@102: // In order to pass the 64-bit operands to/from asm blocks, we use undocumented gcc feature: Chris@102: // the lower half (Rt) of the operand is accessible normally, via the numbered placeholder (e.g. %0), Chris@102: // and the upper half (Rt2) - via the same placeholder with an 'H' after the '%' sign (e.g. %H0). Chris@102: // See: http://hardwarebug.org/2010/07/06/arm-inline-asm-secrets/ Chris@102: Chris@102: template< bool Signed > Chris@102: struct operations< 8u, Signed > : Chris@102: public gcc_arm_operations_base Chris@102: { Chris@102: typedef typename make_storage_type< 8u, Signed >::type storage_type; Chris@102: Chris@102: static BOOST_FORCEINLINE void store(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: exchange(storage, v, order); Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type load(storage_type const volatile& storage, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: storage_type original; Chris@102: uint32_t tmp; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%0) Chris@102: "ldrexd %1, %H1, [%2]\n" Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%0) Chris@102: : BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(tmp), // %0 Chris@102: "=&r" (original) // %1 Chris@102: : "r" (&storage) // %2 Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type exchange(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: storage_type original; Chris@102: fence_before(order); Chris@102: uint32_t tmp; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%0) Chris@102: "1:\n" Chris@102: "ldrexd %1, %H1, [%3]\n" // load the original value Chris@102: "strexd %0, %2, %H2, [%3]\n" // store the replacement, tmp = store failed Chris@102: "teq %0, #0\n" // check if store succeeded Chris@102: "bne 1b\n" Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%0) Chris@102: : BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(tmp), // %0 Chris@102: "=&r" (original) // %1 Chris@102: : "r" (v), // %2 Chris@102: "r" (&storage) // %3 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory" Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE bool compare_exchange_weak( Chris@102: storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(success_order); Chris@102: uint32_t tmp; Chris@102: storage_type original, old_val = expected; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%0) Chris@102: "ldrexd %1, %H1, [%3]\n" // original = *(&storage) Chris@102: "cmp %1, %2\n" // flags = original.lo==old_val.lo Chris@102: "ittt eq\n" // [hint that the following 3 instructions are conditional on flags.equal] Chris@102: "cmpeq %H1, %H2\n" // if (flags.equal) flags = original.hi==old_val.hi Chris@102: "strexdeq %0, %4, %H4, [%3]\n" // if (flags.equal) *(&storage) = desired, tmp = store failed Chris@102: "teqeq %0, #0\n" // if (flags.equal) flags = tmp==0 Chris@102: "ite eq\n" // [hint that the following 2 instructions are conditional on flags.equal] Chris@102: "moveq %2, #1\n" // if (flags.equal) old_val.lo = 1 Chris@102: "movne %2, #0\n" // if (!flags.equal) old_val.lo = 0 Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%0) Chris@102: : BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(tmp), // %0 Chris@102: "=&r" (original), // %1 Chris@102: "+r" (old_val) // %2 Chris@102: : "r" (&storage), // %3 Chris@102: "r" (desired) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory" Chris@102: ); Chris@102: const uint32_t success = (uint32_t)old_val; Chris@102: if (success) Chris@102: fence_after(success_order); Chris@102: else Chris@102: fence_after(failure_order); Chris@102: expected = original; Chris@102: return !!success; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE bool compare_exchange_strong( Chris@102: storage_type volatile& storage, storage_type& expected, storage_type desired, memory_order success_order, memory_order failure_order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(success_order); Chris@102: uint32_t tmp; Chris@102: storage_type original, old_val = expected; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%0) Chris@102: "1:\n" Chris@102: "ldrexd %1, %H1, [%3]\n" // original = *(&storage) Chris@102: "cmp %1, %2\n" // flags = original.lo==old_val.lo Chris@102: "it eq\n" // [hint that the following instruction is conditional on flags.equal] Chris@102: "cmpeq %H1, %H2\n" // if (flags.equal) flags = original.hi==old_val.hi Chris@102: "bne 2f\n" // if (!flags.equal) goto end Chris@102: "strexd %0, %4, %H4, [%3]\n" // *(&storage) = desired, tmp = store failed Chris@102: "teq %0, #0\n" // flags.equal = tmp == 0 Chris@102: "bne 1b\n" // if (flags.equal) goto retry Chris@102: "2:\n" Chris@102: "ite eq\n" // [hint that the following 2 instructions are conditional on flags.equal] Chris@102: "moveq %2, #1\n" // if (flags.equal) old_val.lo = 1 Chris@102: "movne %2, #0\n" // if (!flags.equal) old_val.lo = 0 Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%0) Chris@102: : BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(tmp), // %0 Chris@102: "=&r" (original), // %1 Chris@102: "+r" (old_val) // %2 Chris@102: : "r" (&storage), // %3 Chris@102: "r" (desired) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory" Chris@102: ); Chris@102: const uint32_t success = (uint32_t)old_val; Chris@102: if (success) Chris@102: fence_after(success_order); Chris@102: else Chris@102: fence_after(failure_order); Chris@102: expected = original; Chris@102: return !!success; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_add(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: storage_type original, result; Chris@102: uint32_t tmp; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%0) Chris@102: "1:\n" Chris@102: "ldrexd %1, %H1, [%3]\n" // original = *(&storage) Chris@102: "adds %2, %1, %4\n" // result = original + value Chris@102: "adc %H2, %H1, %H4\n" Chris@102: "strexd %0, %2, %H2, [%3]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %0, #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%0) Chris@102: : BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(tmp), // %0 Chris@102: "=&r" (original), // %1 Chris@102: "=&r" (result) // %2 Chris@102: : "r" (&storage), // %3 Chris@102: "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory" Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_sub(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: storage_type original, result; Chris@102: uint32_t tmp; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%0) Chris@102: "1:\n" Chris@102: "ldrexd %1, %H1, [%3]\n" // original = *(&storage) Chris@102: "subs %2, %1, %4\n" // result = original - value Chris@102: "sbc %H2, %H1, %H4\n" Chris@102: "strexd %0, %2, %H2, [%3]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %0, #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%0) Chris@102: : BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(tmp), // %0 Chris@102: "=&r" (original), // %1 Chris@102: "=&r" (result) // %2 Chris@102: : "r" (&storage), // %3 Chris@102: "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory" Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_and(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: storage_type original, result; Chris@102: uint32_t tmp; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%0) Chris@102: "1:\n" Chris@102: "ldrexd %1, %H1, [%3]\n" // original = *(&storage) Chris@102: "and %2, %1, %4\n" // result = original & value Chris@102: "and %H2, %H1, %H4\n" Chris@102: "strexd %0, %2, %H2, [%3]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %0, #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%0) Chris@102: : BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(tmp), // %0 Chris@102: "=&r" (original), // %1 Chris@102: "=&r" (result) // %2 Chris@102: : "r" (&storage), // %3 Chris@102: "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory" Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_or(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: storage_type original, result; Chris@102: uint32_t tmp; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%0) Chris@102: "1:\n" Chris@102: "ldrexd %1, %H1, [%3]\n" // original = *(&storage) Chris@102: "orr %2, %1, %4\n" // result = original | value Chris@102: "orr %H2, %H1, %H4\n" Chris@102: "strexd %0, %2, %H2, [%3]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %0, #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%0) Chris@102: : BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(tmp), // %0 Chris@102: "=&r" (original), // %1 Chris@102: "=&r" (result) // %2 Chris@102: : "r" (&storage), // %3 Chris@102: "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory" Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE storage_type fetch_xor(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: fence_before(order); Chris@102: storage_type original, result; Chris@102: uint32_t tmp; Chris@102: __asm__ __volatile__ Chris@102: ( Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_START(%0) Chris@102: "1:\n" Chris@102: "ldrexd %1, %H1, [%3]\n" // original = *(&storage) Chris@102: "eor %2, %1, %4\n" // result = original ^ value Chris@102: "eor %H2, %H1, %H4\n" Chris@102: "strexd %0, %2, %H2, [%3]\n" // *(&storage) = result, tmp = store failed Chris@102: "teq %0, #0\n" // flags = tmp==0 Chris@102: "bne 1b\n" // if (!flags.equal) goto retry Chris@102: BOOST_ATOMIC_DETAIL_ARM_ASM_END(%0) Chris@102: : BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(tmp), // %0 Chris@102: "=&r" (original), // %1 Chris@102: "=&r" (result) // %2 Chris@102: : "r" (&storage), // %3 Chris@102: "r" (v) // %4 Chris@102: : BOOST_ATOMIC_DETAIL_ASM_CLOBBER_CC_COMMA "memory" Chris@102: ); Chris@102: fence_after(order); Chris@102: return original; Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE bool test_and_set(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: return !!exchange(storage, (storage_type)1, order); Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE void clear(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: store(storage, 0, order); Chris@102: } Chris@102: Chris@102: static BOOST_FORCEINLINE bool is_lock_free(storage_type const volatile&) BOOST_NOEXCEPT Chris@102: { Chris@102: return true; Chris@102: } Chris@102: }; Chris@102: Chris@102: #endif // defined(BOOST_ATOMIC_DETAIL_ARM_HAS_LDREXD_STREXD) Chris@102: Chris@102: Chris@102: BOOST_FORCEINLINE void thread_fence(memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: if (order != memory_order_relaxed) Chris@102: gcc_arm_operations_base::hardware_full_fence(); Chris@102: } Chris@102: Chris@102: BOOST_FORCEINLINE void signal_fence(memory_order order) BOOST_NOEXCEPT Chris@102: { Chris@102: if (order != memory_order_relaxed) Chris@102: __asm__ __volatile__ ("" ::: "memory"); Chris@102: } Chris@102: Chris@102: } // namespace detail Chris@102: } // namespace atomics Chris@102: } // namespace boost Chris@102: Chris@102: #endif // BOOST_ATOMIC_DETAIL_OPS_GCC_ARM_HPP_INCLUDED_