29 #ifndef VC_COMMON_X86_PREFETCHES_H_
30 #define VC_COMMON_X86_PREFETCHES_H_
32 #include <xmmintrin.h>
35 namespace Vc_VERSIONED_NAMESPACE
40 #if defined(Vc_IMPL_MIC)
41 static constexpr
int exclusive_hint = 0x4;
43 static constexpr
int exclusive_hint = 0;
48 template <
typename ExclusiveOrShared = Vc::Shared>
51 if (std::is_same<ExclusiveOrShared, Vc::Shared>::value) {
52 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_NTA);
54 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)),
55 static_cast<decltype(_MM_HINT_NTA)
>(_MM_HINT_NTA | exclusive_hint));
58 template <
typename ExclusiveOrShared = Vc::Shared>
61 if (std::is_same<ExclusiveOrShared, Vc::Shared>::value) {
62 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T0);
64 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)),
65 static_cast<decltype(_MM_HINT_T0)
>(_MM_HINT_T0 | exclusive_hint));
68 template <
typename ExclusiveOrShared = Vc::Shared>
71 if (std::is_same<ExclusiveOrShared, Vc::Shared>::value) {
72 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T1);
74 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)),
75 static_cast<decltype(_MM_HINT_T1)
>(_MM_HINT_T1 | exclusive_hint));
78 template <
typename ExclusiveOrShared = Vc::Shared>
81 if (std::is_same<ExclusiveOrShared, Vc::Shared>::value) {
82 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)), _MM_HINT_T2);
84 _mm_prefetch(static_cast<char *>(const_cast<void *>(addr)),
85 static_cast<decltype(_MM_HINT_T2)
>(_MM_HINT_T2 | exclusive_hint));
92 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)
94 const char *addr =
static_cast<const char *
>(addr_);
95 prefetchClose<typename std::conditional<UseExclusivePrefetch, Vc::Exclusive, Vc::Shared>::type>(addr + L1);
96 prefetchMid <typename std::conditional<UseExclusivePrefetch, Vc::Exclusive, Vc::Shared>::type>(addr + L2);
98 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)
100 const char *addr =
static_cast<const char *
>(addr_);
101 prefetchMid <typename std::conditional<UseExclusivePrefetch, Vc::Exclusive, Vc::Shared>::type>(addr + L2);
103 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)
105 const char *addr =
static_cast<const char *
>(addr_);
106 prefetchClose<typename std::conditional<UseExclusivePrefetch, Vc::Exclusive, Vc::Shared>::type>(addr + L1);
108 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)
112 template<
typename Flags> Vc_INTRINSIC
void handleLoadPrefetches(
const void * , Flags,
typename Flags::EnableIfNotPrefetch =
nullptr) {}
113 template<
typename Flags> Vc_INTRINSIC
void handleLoadPrefetches(
const void *addr, Flags,
typename Flags::EnableIfPrefetch =
nullptr)
116 handlePrefetch<Flags::L1Stride, Flags::L2Stride, Flags::IsExclusivePrefetch>(addr);
119 template<
typename Flags> Vc_INTRINSIC
void handleStorePrefetches(
const void * , Flags,
typename Flags::EnableIfNotPrefetch =
nullptr) {}
120 template<
typename Flags> Vc_INTRINSIC
void handleStorePrefetches(
const void *addr, Flags,
typename Flags::EnableIfPrefetch =
nullptr)
123 handlePrefetch<Flags::L1Stride, Flags::L2Stride, !Flags::IsSharedPrefetch>(addr);
137 #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.