1 // Copyright Oliver Kowalke 2017.
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)
6 #ifndef BOOST_CONTEXT_DETAIL_PREFETCH_H
7 #define BOOST_CONTEXT_DETAIL_PREFETCH_H
12 #include <boost/config.hpp>
13 #include <boost/predef.h>
15 #include <boost/context/detail/config.hpp>
17 #if BOOST_COMP_INTEL || BOOST_COMP_INTEL_EMULATED
18 #include <immintrin.h>
25 #ifdef BOOST_HAS_ABI_HEADERS
26 # include BOOST_ABI_PREFIX
33 #if BOOST_COMP_GNUC || BOOST_COMP_CLANG
34 #define BOOST_HAS_PREFETCH 1
36 void prefetch( void * addr) {
37 // L1 cache : hint == 1
38 __builtin_prefetch( addr, 1, 1);
40 #elif BOOST_COMP_INTEL || BOOST_COMP_INTEL_EMULATED
41 #define BOOST_HAS_PREFETCH 1
43 void prefetch( void * addr) {
44 // L1 cache : hint == _MM_HINT_T0
45 _mm_prefetch( (const char *)addr, _MM_HINT_T0);
48 #define BOOST_HAS_PREFETCH 1
50 void prefetch( void * addr) {
51 // L1 cache : hint == _MM_HINT_T0
52 _mm_prefetch( (const char *)addr, _MM_HINT_T0);
57 void prefetch_range( void * addr, std::size_t len) {
58 #if defined(BOOST_HAS_PREFETCH)
60 void * end = reinterpret_cast< void * >(
61 reinterpret_cast< uintptr_t >( addr) + static_cast< uintptr_t >( len) );
64 vp = reinterpret_cast< void * >(
65 reinterpret_cast< uintptr_t >( vp) + static_cast< uintptr_t >( prefetch_stride) );
70 #undef BOOST_HAS_PREFETCH
74 #ifdef BOOST_HAS_ABI_HEADERS
75 # include BOOST_ABI_SUFFIX
78 #endif // BOOST_CONTEXT_DETAIL_PREFETCH_H