permute_bytes16.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_PERMUTE_BYTES16_H
  7. #define LIBSIMDPP_SIMDPP_CORE_PERMUTE_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/permute_bytes16.h>
  14. namespace simdpp {
  15. namespace SIMDPP_ARCH_NAMESPACE {
  16. /** Selects bytes from a vector according to a mask. Each byte within the
  17. mask defines which element to select:
  18. * Bits 7-4 must be zero or the behavior is undefined
  19. * Bits 3-0 define the element within the given vector.
  20. */
  21. template<unsigned N, class V1, class E2> SIMDPP_INL
  22. typename detail::get_expr_nomask<V1>::empty
  23. permute_bytes16(const any_vec8<N,V1>& a, const uint8<N,E2>& mask)
  24. {
  25. typename detail::get_expr_nomask<V1>::type ra = a.wrapped().eval();
  26. return detail::insn::i_permute_bytes16(ra, mask.eval());
  27. }
  28. template<unsigned N, class V1, class E2> SIMDPP_INL
  29. typename detail::get_expr_nomask<V1>::empty
  30. permute_bytes16(const any_vec16<N,V1>& a, const uint16<N,E2>& mask)
  31. {
  32. typename detail::get_expr_nomask<V1>::type ra = a.wrapped().eval();
  33. return detail::insn::i_permute_bytes16(ra, mask.eval());
  34. }
  35. template<unsigned N, class V1, class E2> SIMDPP_INL
  36. typename detail::get_expr_nomask<V1>::empty
  37. permute_bytes16(const any_vec32<N,V1>& a, const uint32<N,E2>& mask)
  38. {
  39. typename detail::get_expr_nomask<V1>::type ra = a.wrapped().eval();
  40. return detail::insn::i_permute_bytes16(ra, mask.eval());
  41. }
  42. template<unsigned N, class V1, class E2> SIMDPP_INL
  43. typename detail::get_expr_nomask<V1>::empty
  44. permute_bytes16(const any_vec64<N,V1>& a, const uint64<N,E2>& mask)
  45. {
  46. typename detail::get_expr_nomask<V1>::type ra = a.wrapped().eval();
  47. return detail::insn::i_permute_bytes16(ra, mask.eval());
  48. }
  49. } // namespace SIMDPP_ARCH_NAMESPACE
  50. } // namespace simdpp
  51. #endif