2 // Copyright Oliver Kowalke 2016.
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_FIBERS_DETAIL_CPU_RELAX_H
8 #define BOOST_FIBERS_DETAIL_CPU_RELAX_H
13 #include <boost/config.hpp>
14 #include <boost/predef.h>
16 #include <boost/fiber/detail/config.hpp>
18 #if BOOST_COMP_MSVC || BOOST_COMP_MSVC_EMULATED
22 #ifdef BOOST_HAS_ABI_HEADERS
23 # include BOOST_ABI_PREFIX
32 # define cpu_relax() YieldProcessor();
33 # elif (defined(__ARM_ARCH_6K__) || \
34 defined(__ARM_ARCH_6Z__) || \
35 defined(__ARM_ARCH_6ZK__) || \
36 defined(__ARM_ARCH_6T2__) || \
37 defined(__ARM_ARCH_7__) || \
38 defined(__ARM_ARCH_7A__) || \
39 defined(__ARM_ARCH_7R__) || \
40 defined(__ARM_ARCH_7M__) || \
41 defined(__ARM_ARCH_7S__) || \
42 defined(__ARM_ARCH_8A__) || \
44 // http://groups.google.com/a/chromium.org/forum/#!msg/chromium-dev/YGVrZbxYOlU/Vpgy__zeBQAJ
45 // mnemonic 'yield' is supported from ARMv6k onwards
46 # define cpu_relax() asm volatile ("yield" ::: "memory");
48 # define cpu_relax() asm volatile ("nop" ::: "memory");
50 #elif BOOST_ARCH_MIPS && (((__mips_isa_rev > 1) && defined(__mips32)) || ((__mips_isa_rev > 2) && defined(__mips64)))
51 # define cpu_relax() asm volatile ("pause" ::: "memory");
53 // http://code.metager.de/source/xref/gnu/glibc/sysdeps/powerpc/sys/platform/ppc.h
54 // http://stackoverflow.com/questions/5425506/equivalent-of-x86-pause-instruction-for-ppc
55 // mnemonic 'or' shared resource hints
56 // or 27, 27, 27 This form of 'or' provides a hint that performance
57 // will probably be imrpoved if shared resources dedicated
58 // to the executing processor are released for use by other
60 // extended mnemonics (available with POWER7)
61 // yield == or 27, 27, 27
62 # define cpu_relax() asm volatile ("or 27,27,27" ::: "memory");
64 # if BOOST_COMP_MSVC || BOOST_COMP_MSVC_EMULATED
65 # define cpu_relax() YieldProcessor();
67 # define cpu_relax() asm volatile ("pause" ::: "memory");
70 # define cpu_relax() { \
71 static constexpr std::chrono::microseconds us0{ 0 }; \
72 std::this_thread::sleep_for( us0); \
78 #ifdef BOOST_HAS_ABI_HEADERS
79 # include BOOST_ABI_SUFFIX
82 #endif // BOOST_FIBERS_DETAIL_CPU_RELAX_H