28 #ifndef VC_COMMON_X86_PREFETCHES_H_
29 #define VC_COMMON_X86_PREFETCHES_H_
31 #include <xmmintrin.h>
34 namespace Vc_VERSIONED_NAMESPACE
39 #if defined(Vc_IMPL_MIC)
40 static constexpr
int exclusive_hint = 0x4;
42 static constexpr
int exclusive_hint = 0;
47 template <
typename ExclusiveOrShared = Vc::Shared>
50 if (std::is_same<ExclusiveOrShared, Vc::Shared>::value) {
51 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_NTA);
53 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)),
54 static_cast<decltype(_MM_HINT_NTA)
>(_MM_HINT_NTA | exclusive_hint));
57 template <
typename ExclusiveOrShared = Vc::Shared>
60 if (std::is_same<ExclusiveOrShared, Vc::Shared>::value) {
61 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T0);
63 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)),
64 static_cast<decltype(_MM_HINT_T0)
>(_MM_HINT_T0 | exclusive_hint));
67 template <
typename ExclusiveOrShared = Vc::Shared>
70 if (std::is_same<ExclusiveOrShared, Vc::Shared>::value) {
71 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T1);
73 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)),
74 static_cast<decltype(_MM_HINT_T1)
>(_MM_HINT_T1 | exclusive_hint));
77 template <
typename ExclusiveOrShared = Vc::Shared>
80 if (std::is_same<ExclusiveOrShared, Vc::Shared>::value) {
81 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T2);
83 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)),
84 static_cast<decltype(_MM_HINT_T2)
>(_MM_HINT_T2 | exclusive_hint));
91 template<
size_t L1,
size_t L2,
bool UseExclusivePrefetch> Vc_INTRINSIC
void handlePrefetch(
const void *addr_,
typename std::enable_if<L1 != 0 && L2 != 0, void *>::type =
nullptr)
93 const char *addr =
static_cast<const char *
>(addr_);
94 prefetchClose<typename std::conditional<UseExclusivePrefetch, Vc::Exclusive, Vc::Shared>::type>(addr + L1);
95 prefetchMid <typename std::conditional<UseExclusivePrefetch, Vc::Exclusive, Vc::Shared>::type>(addr + L2);
97 template<
size_t L1,
size_t L2,
bool UseExclusivePrefetch> Vc_INTRINSIC
void handlePrefetch(
const void *addr_,
typename std::enable_if<L1 == 0 && L2 != 0, void *>::type =
nullptr)
99 const char *addr =
static_cast<const char *
>(addr_);
100 prefetchMid <typename std::conditional<UseExclusivePrefetch, Vc::Exclusive, Vc::Shared>::type>(addr + L2);
102 template<
size_t L1,
size_t L2,
bool UseExclusivePrefetch> Vc_INTRINSIC
void handlePrefetch(
const void *addr_,
typename std::enable_if<L1 != 0 && L2 == 0, void *>::type =
nullptr)
104 const char *addr =
static_cast<const char *
>(addr_);
105 prefetchClose<typename std::conditional<UseExclusivePrefetch, Vc::Exclusive, Vc::Shared>::type>(addr + L1);
107 template<
size_t L1,
size_t L2,
bool UseExclusivePrefetch> Vc_INTRINSIC
void handlePrefetch(
const void *,
typename std::enable_if<L1 == 0 && L2 == 0, void *>::type =
nullptr)
111 template<
typename Flags> Vc_INTRINSIC
void handleLoadPrefetches(
const void * , Flags,
typename Flags::EnableIfNotPrefetch =
nullptr) {}
112 template<
typename Flags> Vc_INTRINSIC
void handleLoadPrefetches(
const void *addr, Flags,
typename Flags::EnableIfPrefetch =
nullptr)
115 handlePrefetch<Flags::L1Stride, Flags::L2Stride, Flags::IsExclusivePrefetch>(addr);
118 template<
typename Flags> Vc_INTRINSIC
void handleStorePrefetches(
const void * , Flags,
typename Flags::EnableIfNotPrefetch =
nullptr) {}
119 template<
typename Flags> Vc_INTRINSIC
void handleStorePrefetches(
const void *addr, Flags,
typename Flags::EnableIfPrefetch =
nullptr)
122 handlePrefetch<Flags::L1Stride, Flags::L2Stride, !Flags::IsSharedPrefetch>(addr);
136 #endif // VC_COMMON_X86_PREFETCHES_H_
void prefetchClose(const void *addr)
Prefetch the cacheline containing addr to L1 cache.
void prefetchMid(const void *addr)
Prefetch the cacheline containing addr to L2 cache.
void prefetchForOneRead(const void *addr)
Prefetch the cacheline containing addr for a single read access.
void prefetchFar(const void *addr)
Prefetch the cacheline containing addr to L3 cache.