diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-09-13 11:24:46 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2017-09-13 11:25:39 +0900 |
commit | 4fadd968fa12130524c8380f33fcfe25d4de79e5 (patch) | |
tree | fd26a490cd15388d42fc6652b3c5c13012e7f93e /boost/context/detail/prefetch.hpp | |
parent | b5c87084afaef42b2d058f68091be31988a6a874 (diff) | |
download | boost-upstream/1.65.0.tar.gz boost-upstream/1.65.0.tar.bz2 boost-upstream/1.65.0.zip |
Imported Upstream version 1.65.0upstream/1.65.0
Change-Id: Icf8400b375482cb11bcf77440a6934ba360d6ba4
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/context/detail/prefetch.hpp')
-rw-r--r-- | boost/context/detail/prefetch.hpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/boost/context/detail/prefetch.hpp b/boost/context/detail/prefetch.hpp new file mode 100644 index 0000000000..a479450c74 --- /dev/null +++ b/boost/context/detail/prefetch.hpp @@ -0,0 +1,78 @@ +// Copyright Oliver Kowalke 2017. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_CONTEXT_DETAIL_PREFETCH_H +#define BOOST_CONTEXT_DETAIL_PREFETCH_H + +#include <cstddef> +#include <cstdint> + +#include <boost/config.hpp> +#include <boost/predef.h> + +#include <boost/context/detail/config.hpp> + +#if BOOST_COMP_INTEL || BOOST_COMP_INTEL_EMULATED +#include <immintrin.h> +#endif + +#if BOOST_COMP_MSVC +#include <mmintrin.h> +#endif + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_PREFIX +#endif + +namespace boost { +namespace context { +namespace detail { + +#if BOOST_COMP_GNUC || BOOST_COMP_CLANG +#define BOOST_HAS_PREFETCH 1 +BOOST_FORCEINLINE +void prefetch( void * addr) { + // L1 cache : hint == 1 + __builtin_prefetch( addr, 1, 1); +} +#elif BOOST_COMP_INTEL || BOOST_COMP_INTEL_EMULATED +#define BOOST_HAS_PREFETCH 1 +BOOST_FORCEINLINE +void prefetch( void * addr) { + // L1 cache : hint == _MM_HINT_T0 + _mm_prefetch( (const char *)addr, _MM_HINT_T0); +} +#elif BOOST_COMP_MSVC +#define BOOST_HAS_PREFETCH 1 +BOOST_FORCEINLINE +void prefetch( void * addr) { + // L1 cache : hint == _MM_HINT_T0 + _mm_prefetch( (const char *)addr, _MM_HINT_T0); +} +#endif + +inline +void prefetch_range( void * addr, std::size_t len) { +#if defined(BOOST_HAS_PREFETCH) + void * vp = addr; + void * end = reinterpret_cast< void * >( + reinterpret_cast< uintptr_t >( addr) + static_cast< uintptr_t >( len) ); + while ( vp < end) { + prefetch( vp); + vp = reinterpret_cast< void * >( + reinterpret_cast< uintptr_t >( vp) + static_cast< uintptr_t >( prefetch_stride) ); + } +#endif +} + +#undef BOOST_HAS_PREFETCH + +}}} + +#ifdef BOOST_HAS_ABI_HEADERS +# include BOOST_ABI_SUFFIX +#endif + +#endif // BOOST_CONTEXT_DETAIL_PREFETCH_H |