shuffle_bytes16.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright (C) 2013-2017 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_SHUFFLE_BYTES16_H
  7. #define LIBSIMDPP_SIMDPP_CORE_SHUFFLE_BYTES16_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/get_expr.h>
  13. #include <simdpp/detail/insn/shuffle_bytes16.h>
  14. namespace simdpp {
  15. namespace SIMDPP_ARCH_NAMESPACE {
  16. /** Selects bytes from two vectors according to a mask. Each byte within the
  17. mask defines which element to select:
  18. * Bits 7-5 must be zero or the behavior is undefined
  19. * Bit 4 defines which vector to select. 0 corresponds to @a a, 1 to @a b.
  20. * Bits 3-0 define the element within the selected vector.
  21. */
  22. template<unsigned N, class V1, class V2, class E3> SIMDPP_INL
  23. typename detail::get_expr_nomask<V1>::empty
  24. shuffle_bytes16(const any_vec8<N,V1>& a, const any_vec8<N,V2>& b,
  25. const uint8<N,E3>& mask)
  26. {
  27. typename detail::get_expr_nomask<V1>::type ra = a.wrapped().eval(),
  28. rb = b.wrapped().eval();
  29. return detail::insn::i_shuffle_bytes16(ra, rb, mask.eval());
  30. }
  31. template<unsigned N, class V1, class V2, class E3> SIMDPP_INL
  32. typename detail::get_expr_nomask<V1>::empty
  33. shuffle_bytes16(const any_vec16<N,V1>& a, const any_vec16<N,V2>& b,
  34. const uint16<N,E3>& mask)
  35. {
  36. typename detail::get_expr_nomask<V1>::type ra = a.wrapped().eval(),
  37. rb = b.wrapped().eval();
  38. return detail::insn::i_shuffle_bytes16(ra, rb, mask.eval());
  39. }
  40. template<unsigned N, class V1, class V2, class E3> SIMDPP_INL
  41. typename detail::get_expr_nomask<V1>::empty
  42. shuffle_bytes16(const any_vec32<N,V1>& a, const any_vec32<N,V2>& b,
  43. const uint32<N,E3>& mask)
  44. {
  45. typename detail::get_expr_nomask<V1>::type ra = a.wrapped().eval(),
  46. rb = b.wrapped().eval();
  47. return detail::insn::i_shuffle_bytes16(ra, rb, mask.eval());
  48. }
  49. template<unsigned N, class V1, class V2, class E3> SIMDPP_INL
  50. typename detail::get_expr_nomask<V1>::empty
  51. shuffle_bytes16(const any_vec64<N,V1>& a, const any_vec64<N,V2>& b,
  52. const uint64<N,E3>& mask)
  53. {
  54. typename detail::get_expr_nomask<V1>::type ra = a.wrapped().eval(),
  55. rb = b.wrapped().eval();
  56. return detail::insn::i_shuffle_bytes16(ra, rb, mask.eval());
  57. }
  58. } // namespace SIMDPP_ARCH_NAMESPACE
  59. } // namespace simdpp
  60. #endif