]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/atomic/detail/gcc_arm_asm_common.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / atomic / detail / gcc_arm_asm_common.hpp
CommitLineData
20effc67
TL
1/*
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
5 *
6 * Copyright (c) 2009 Helge Bahmann
7 * Copyright (c) 2013 Tim Blechmann
8 * Copyright (c) 2014, 2020 Andrey Semashev
9 */
10/*!
11 * \file atomic/detail/gcc_arm_asm_common.hpp
12 *
13 * This header contains basic utilities for gcc asm-based ARM backend.
14 */
15
16#ifndef BOOST_ATOMIC_DETAIL_GCC_ARM_ASM_COMMON_HPP_INCLUDED_
17#define BOOST_ATOMIC_DETAIL_GCC_ARM_ASM_COMMON_HPP_INCLUDED_
18
19#include <boost/atomic/detail/config.hpp>
20#include <boost/atomic/detail/capabilities.hpp>
21
1e59de90
TL
22#ifdef BOOST_HAS_PRAGMA_ONCE
23#pragma once
24#endif
25
20effc67
TL
26// A memory barrier is effected using a "co-processor 15" instruction,
27// though a separate assembler mnemonic is available for it in v7.
28//
29// "Thumb 1" is a subset of the ARM instruction set that uses a 16-bit encoding. It
30// doesn't include all instructions and in particular it doesn't include the co-processor
31// instruction used for the memory barrier or the load-locked/store-conditional
32// instructions. So, if we're compiling in "Thumb 1" mode, we need to wrap all of our
33// asm blocks with code to temporarily change to ARM mode.
34//
35// You can only change between ARM and Thumb modes when branching using the bx instruction.
36// bx takes an address specified in a register. The least significant bit of the address
37// indicates the mode, so 1 is added to indicate that the destination code is Thumb.
38// A temporary register is needed for the address and is passed as an argument to these
39// macros. It must be one of the "low" registers accessible to Thumb code, specified
40// using the "l" attribute in the asm statement.
41//
42// Architecture v7 introduces "Thumb 2", which does include (almost?) all of the ARM
43// instruction set. (Actually, there was an extension of v6 called v6T2 which supported
44// "Thumb 2" mode, but its architecture manual is no longer available, referring to v7.)
45// So in v7 we don't need to change to ARM mode; we can write "universal
46// assembler" which will assemble to Thumb 2 or ARM code as appropriate. The only thing
47// we need to do to make this "universal" assembler mode work is to insert "IT" instructions
48// to annotate the conditional instructions. These are ignored in other modes (e.g. v6),
49// so they can always be present.
50
51// A note about memory_order_consume. Technically, this architecture allows to avoid
52// unnecessary memory barrier after consume load since it supports data dependency ordering.
53// However, some compiler optimizations may break a seemingly valid code relying on data
54// dependency tracking by injecting bogus branches to aid out of order execution.
55// This may happen not only in Boost.Atomic code but also in user's code, which we have no
56// control of. See this thread: http://lists.boost.org/Archives/boost/2014/06/213890.php.
57// For this reason we promote memory_order_consume to memory_order_acquire.
58
59#if defined(__thumb__) && !defined(__thumb2__)
60#define BOOST_ATOMIC_DETAIL_ARM_ASM_START(TMPREG) "adr " #TMPREG ", 8f\n\t" "bx " #TMPREG "\n\t" ".arm\n\t" ".align 4\n\t" "8:\n\t"
61#define BOOST_ATOMIC_DETAIL_ARM_ASM_END(TMPREG) "adr " #TMPREG ", 9f + 1\n\t" "bx " #TMPREG "\n\t" ".thumb\n\t" ".align 2\n\t" "9:\n\t"
62#define BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(var) "=&l" (var)
63#else
64// Indicate that start/end macros are empty and the tmpreg is not needed
65#define BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_UNUSED
66#define BOOST_ATOMIC_DETAIL_ARM_ASM_START(TMPREG)
67#define BOOST_ATOMIC_DETAIL_ARM_ASM_END(TMPREG)
68#define BOOST_ATOMIC_DETAIL_ARM_ASM_TMPREG_CONSTRAINT(var) "=&l" (var)
69#endif
70
71#if defined(BOOST_ATOMIC_DETAIL_ARM_LITTLE_ENDIAN)
72#define BOOST_ATOMIC_DETAIL_ARM_ASM_ARG_LO(arg) "%" BOOST_STRINGIZE(arg)
73#define BOOST_ATOMIC_DETAIL_ARM_ASM_ARG_HI(arg) "%H" BOOST_STRINGIZE(arg)
74#else
75#define BOOST_ATOMIC_DETAIL_ARM_ASM_ARG_LO(arg) "%H" BOOST_STRINGIZE(arg)
76#define BOOST_ATOMIC_DETAIL_ARM_ASM_ARG_HI(arg) "%" BOOST_STRINGIZE(arg)
77#endif
78
79#endif // BOOST_ATOMIC_DETAIL_GCC_ARM_ASM_COMMON_HPP_INCLUDED_