extract.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_SIMD_EXTRACT_H
  7. #define LIBSIMDPP_SIMD_EXTRACT_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/extract.h>
  13. namespace simdpp {
  14. namespace SIMDPP_ARCH_NAMESPACE {
  15. /** Extracts the @a id-th element from a vector.
  16. @code
  17. r = a[id]
  18. @endcode
  19. This function may have very high latency.
  20. */
  21. template<unsigned id, unsigned N> SIMDPP_INL
  22. uint8_t extract(const uint8<N>& a)
  23. {
  24. static_assert(id < N, "index out of bounds");
  25. return detail::insn::i_extract<id>(a);
  26. }
  27. template<unsigned id, unsigned N> SIMDPP_INL
  28. int8_t extract(const int8<N>& a)
  29. {
  30. static_assert(id < N, "index out of bounds");
  31. return detail::insn::i_extract<id>(a);
  32. }
  33. template<unsigned id, unsigned N> SIMDPP_INL
  34. uint16_t extract(const uint16<N>& a)
  35. {
  36. static_assert(id < N, "index out of bounds");
  37. return detail::insn::i_extract<id>(a);
  38. }
  39. template<unsigned id, unsigned N> SIMDPP_INL
  40. int16_t extract(const int16<N>& a)
  41. {
  42. static_assert(id < N, "index out of bounds");
  43. return detail::insn::i_extract<id>(a);
  44. }
  45. template<unsigned id, unsigned N> SIMDPP_INL
  46. uint32_t extract(const uint32<N>& a)
  47. {
  48. static_assert(id < N, "index out of bounds");
  49. return detail::insn::i_extract<id>(a);
  50. }
  51. template<unsigned id, unsigned N> SIMDPP_INL
  52. int32_t extract(const int32<N>& a)
  53. {
  54. static_assert(id < N, "index out of bounds");
  55. return detail::insn::i_extract<id>(a);
  56. }
  57. template<unsigned id, unsigned N> SIMDPP_INL
  58. uint64_t extract(const uint64<N>& a)
  59. {
  60. static_assert(id < N, "index out of bounds");
  61. return detail::insn::i_extract<id>(a);
  62. }
  63. template<unsigned id, unsigned N> SIMDPP_INL
  64. int64_t extract(const int64<N>& a)
  65. {
  66. static_assert(id < N, "index out of bounds");
  67. return detail::insn::i_extract<id>(a);
  68. }
  69. template<unsigned id, unsigned N> SIMDPP_INL
  70. float extract(const float32<N>& a)
  71. {
  72. static_assert(id < N, "index out of bounds");
  73. return detail::insn::i_extract<id>(a);
  74. }
  75. template<unsigned id, unsigned N> SIMDPP_INL
  76. double extract(const float64<N>& a)
  77. {
  78. static_assert(id < N, "index out of bounds");
  79. return detail::insn::i_extract<id>(a);
  80. }
  81. } // namespace SIMDPP_ARCH_NAMESPACE
  82. } // namespace simdpp
  83. #endif