1/* Copyright (C) 2011-2014 Povilas Kanapickas <povilas@radix.lt>
2
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt)
6*/
7
8#ifndef LIBSIMDPP_SIMDPP_CACHE_H
9#define LIBSIMDPP_SIMDPP_CACHE_H
10
11#ifndef LIBSIMDPP_SIMD_H
12 #error "This file must be included through simd.h"
13#endif
14#include <simdpp/setup_arch.h>
15
16namespace simdpp {
17namespace SIMDPP_ARCH_NAMESPACE {
18
19/** Prefetches data to the lowest level cache for reading.
20
21 @param ptr pointer to the data to prefetch
22*/
23template<class T>
24SIMDPP_INL void prefetch_read(const T* ptr)
25{
26#if SIMDPP_USE_SSE2
27 _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0);
28#elif SIMDPP_USE_NEON || SIMDPP_USE_ALTIVEC || SIMDPP_USE_MSA
29#if __GNUC__
30 // on NEON results in PLD
31 // on Altivec results in DST
32 // on MSA results in PREF
33 __builtin_prefetch(ptr, 0);
34#endif
35#endif
36 (void) ptr;
37}
38
39/** Prefetches data to the lowest level cache for writing.
40
41 @param ptr pointer to the data to prefetch
42*/
43template<class T>
44SIMDPP_INL void prefetch_write(const T* ptr)
45{
46#if SIMDPP_USE_SSE2
47 _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0);
48#elif SIMDPP_USE_NEON || SIMDPP_USE_ALTIVEC || SIMDPP_USE_MSA
49#if __GNUC__
50 // on NEON results in PLDW
51 // on Altivec results in DSTST
52 // on MSA results in PREF
53 __builtin_prefetch(ptr, 1);
54#endif
55#endif
56 (void) ptr;
57}
58
59} // namespace SIMDPP_ARCH_NAMESPACE
60} // namespace simdpp
61
62#endif
63
64