cache.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Copyright (C) 2011-2014 Povilas Kanapickas <[email protected]>
  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)
  5. */
  6. #ifndef LIBSIMDPP_SIMDPP_CACHE_H
  7. #define LIBSIMDPP_SIMDPP_CACHE_H
  8. #ifndef LIBSIMDPP_SIMD_H
  9. #error "This file must be included through simd.h"
  10. #endif
  11. #include <simdpp/setup_arch.h>
  12. namespace simdpp {
  13. namespace SIMDPP_ARCH_NAMESPACE {
  14. /** Prefetches data to the lowest level cache for reading.
  15. @param ptr pointer to the data to prefetch
  16. */
  17. template<class T>
  18. SIMDPP_INL void prefetch_read(const T* ptr)
  19. {
  20. #if SIMDPP_USE_SSE2
  21. _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0);
  22. #elif SIMDPP_USE_NEON || SIMDPP_USE_ALTIVEC || SIMDPP_USE_MSA
  23. #if __GNUC__
  24. // on NEON results in PLD
  25. // on Altivec results in DST
  26. // on MSA results in PREF
  27. __builtin_prefetch(ptr, 0);
  28. #endif
  29. #endif
  30. (void) ptr;
  31. }
  32. /** Prefetches data to the lowest level cache for writing.
  33. @param ptr pointer to the data to prefetch
  34. */
  35. template<class T>
  36. SIMDPP_INL void prefetch_write(const T* ptr)
  37. {
  38. #if SIMDPP_USE_SSE2
  39. _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0);
  40. #elif SIMDPP_USE_NEON || SIMDPP_USE_ALTIVEC || SIMDPP_USE_MSA
  41. #if __GNUC__
  42. // on NEON results in PLDW
  43. // on Altivec results in DSTST
  44. // on MSA results in PREF
  45. __builtin_prefetch(ptr, 1);
  46. #endif
  47. #endif
  48. (void) ptr;
  49. }
  50. } // namespace SIMDPP_ARCH_NAMESPACE
  51. } // namespace simdpp
  52. #endif