File indexing completed on 2025-01-30 09:35:07
0001
0002
0003
0004
0005
0006 #ifndef BOOST_CONTEXT_DETAIL_PREFETCH_H
0007 #define BOOST_CONTEXT_DETAIL_PREFETCH_H
0008
0009 #include <cstddef>
0010 #include <cstdint>
0011
0012 #include <boost/config.hpp>
0013 #include <boost/predef.h>
0014
0015 #include <boost/context/detail/config.hpp>
0016
0017 #if BOOST_COMP_INTEL || BOOST_COMP_INTEL_EMULATED
0018 #include <immintrin.h>
0019 #endif
0020
0021 #if BOOST_COMP_MSVC && !defined(_M_ARM) && !defined(_M_ARM64)
0022 #include <mmintrin.h>
0023 #endif
0024
0025 #ifdef BOOST_HAS_ABI_HEADERS
0026 # include BOOST_ABI_PREFIX
0027 #endif
0028
0029 namespace boost {
0030 namespace context {
0031 namespace detail {
0032
0033 #if BOOST_COMP_GNUC || BOOST_COMP_CLANG
0034 #define BOOST_HAS_PREFETCH 1
0035 BOOST_FORCEINLINE
0036 void prefetch( void * addr) {
0037
0038 __builtin_prefetch( addr, 1, 1);
0039 }
0040 #elif BOOST_COMP_INTEL || BOOST_COMP_INTEL_EMULATED
0041 #define BOOST_HAS_PREFETCH 1
0042 BOOST_FORCEINLINE
0043 void prefetch( void * addr) {
0044
0045 _mm_prefetch( (const char *)addr, _MM_HINT_T0);
0046 }
0047 #elif BOOST_COMP_MSVC && !defined(_M_ARM) && !defined(_M_ARM64)
0048 #define BOOST_HAS_PREFETCH 1
0049 BOOST_FORCEINLINE
0050 void prefetch( void * addr) {
0051
0052 _mm_prefetch( (const char *)addr, _MM_HINT_T0);
0053 }
0054 #endif
0055
0056 inline
0057 void prefetch_range( void * addr, std::size_t len) {
0058 #if defined(BOOST_HAS_PREFETCH)
0059 void * vp = addr;
0060 void * end = reinterpret_cast< void * >(
0061 reinterpret_cast< uintptr_t >( addr) + static_cast< uintptr_t >( len) );
0062 while ( vp < end) {
0063 prefetch( vp);
0064 vp = reinterpret_cast< void * >(
0065 reinterpret_cast< uintptr_t >( vp) + static_cast< uintptr_t >( prefetch_stride) );
0066 }
0067 #endif
0068 }
0069
0070 #undef BOOST_HAS_PREFETCH
0071
0072 }}}
0073
0074 #ifdef BOOST_HAS_ABI_HEADERS
0075 # include BOOST_ABI_SUFFIX
0076 #endif
0077
0078 #endif