splat.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Copyright (C) 2013-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_CORE_SPLAT_H
  7. #define LIBSIMDPP_SIMDPP_CORE_SPLAT_H
  8. #ifndef LIBSIMDPP_SIMD_H
  9. #error "This file must be included through simd.h"
  10. #endif
  11. #include <simdpp/types.h>
  12. #include <simdpp/detail/insn/splat.h>
  13. #include <simdpp/detail/get_expr.h>
  14. namespace simdpp {
  15. namespace SIMDPP_ARCH_NAMESPACE {
  16. /** Broadcasts the specified element to all elements.
  17. @code
  18. r0 = a[s]
  19. r1 = a[s]
  20. ...
  21. rN = a[s]
  22. @endcode
  23. @par int8
  24. @par 128-bit version:
  25. @icost{SSE2-AVX, 5}
  26. @icost{AVX2, 2}
  27. @par 256-bit version:
  28. @icost{SSE2-AVX, 6}
  29. @icost{NEON, ALTIVEC, 2}
  30. @par int16
  31. @par 128-bit version:
  32. @icost{SSE2-AVX, 5}
  33. @icost{AVX2, 2}
  34. @par 256-bit version:
  35. @icost{SSE2-AVX, 6}
  36. @icost{NEON, ALTIVEC, 2}
  37. @par int32
  38. @par 256-bit version:
  39. @icost{NEON, ALTIVEC, 2}
  40. @par int64
  41. @par 128-bit version:
  42. @icost{ALTIVEC, 1-2}
  43. @par 256-bit version:
  44. @icost{SSE2-AVX, NEON, 2}
  45. @icost{ALTIVEC, 1-2}
  46. @par float32
  47. @par 256-bit version:
  48. @icost{SSE2-AVX, NEON, ALTIVEC, 2}
  49. @par float64
  50. @par 128-bit version:
  51. @novec{NEON, ALTIVEC}
  52. @par 256-bit version:
  53. @icost{SSE2-AVX, 2}
  54. @novec{NEON, ALTIVEC}
  55. */
  56. template<unsigned s, unsigned N, class V> SIMDPP_INL
  57. typename detail::get_expr_nomask<V>::empty
  58. splat(const any_vec<N,V>& a)
  59. {
  60. static_assert(s < V::length, "Access out of bounds");
  61. typename detail::get_expr_nomask<V>::type ra = a.wrapped().eval();
  62. return detail::insn::i_splat<s>(ra);
  63. }
  64. } // namespace SIMDPP_ARCH_NAMESPACE
  65. } // namespace simdpp
  66. #endif