1 | /* Copyright (C) 2011-2014 Povilas Kanapickas <povilas@radix.lt> |
2 | |
3 | Distributed under the Boost Software License, Version 1.0. |
4 | (See accompanying file LICENSE_1_0.txt or copy at |
5 | http://www.boost.org/LICENSE_1_0.txt) |
6 | */ |
7 | |
8 | #ifndef LIBSIMDPP_SIMD_EXTRACT_H |
9 | #define |
10 | |
11 | #ifndef LIBSIMDPP_SIMD_H |
12 | #error "This file must be included through simd.h" |
13 | #endif |
14 | |
15 | #include <simdpp/types.h> |
16 | #include <simdpp/detail/insn/extract.h> |
17 | |
18 | namespace simdpp { |
19 | namespace SIMDPP_ARCH_NAMESPACE { |
20 | |
21 | /** Extracts the @a id-th element from a vector. |
22 | |
23 | @code |
24 | r = a[id] |
25 | @endcode |
26 | |
27 | This function may have very high latency. |
28 | */ |
29 | template<unsigned id, unsigned N> SIMDPP_INL |
30 | uint8_t (const uint8<N>& a) |
31 | { |
32 | static_assert(id < N, "index out of bounds" ); |
33 | return detail::insn::i_extract<id>(a); |
34 | } |
35 | |
36 | template<unsigned id, unsigned N> SIMDPP_INL |
37 | int8_t (const int8<N>& a) |
38 | { |
39 | static_assert(id < N, "index out of bounds" ); |
40 | return detail::insn::i_extract<id>(a); |
41 | } |
42 | |
43 | template<unsigned id, unsigned N> SIMDPP_INL |
44 | uint16_t (const uint16<N>& a) |
45 | { |
46 | static_assert(id < N, "index out of bounds" ); |
47 | return detail::insn::i_extract<id>(a); |
48 | } |
49 | |
50 | template<unsigned id, unsigned N> SIMDPP_INL |
51 | int16_t (const int16<N>& a) |
52 | { |
53 | static_assert(id < N, "index out of bounds" ); |
54 | return detail::insn::i_extract<id>(a); |
55 | } |
56 | |
57 | template<unsigned id, unsigned N> SIMDPP_INL |
58 | uint32_t (const uint32<N>& a) |
59 | { |
60 | static_assert(id < N, "index out of bounds" ); |
61 | return detail::insn::i_extract<id>(a); |
62 | } |
63 | |
64 | template<unsigned id, unsigned N> SIMDPP_INL |
65 | int32_t (const int32<N>& a) |
66 | { |
67 | static_assert(id < N, "index out of bounds" ); |
68 | return detail::insn::i_extract<id>(a); |
69 | } |
70 | |
71 | template<unsigned id, unsigned N> SIMDPP_INL |
72 | uint64_t (const uint64<N>& a) |
73 | { |
74 | static_assert(id < N, "index out of bounds" ); |
75 | return detail::insn::i_extract<id>(a); |
76 | } |
77 | |
78 | template<unsigned id, unsigned N> SIMDPP_INL |
79 | int64_t (const int64<N>& a) |
80 | { |
81 | static_assert(id < N, "index out of bounds" ); |
82 | return detail::insn::i_extract<id>(a); |
83 | } |
84 | |
85 | template<unsigned id, unsigned N> SIMDPP_INL |
86 | float (const float32<N>& a) |
87 | { |
88 | static_assert(id < N, "index out of bounds" ); |
89 | return detail::insn::i_extract<id>(a); |
90 | } |
91 | |
92 | template<unsigned id, unsigned N> SIMDPP_INL |
93 | double (const float64<N>& a) |
94 | { |
95 | static_assert(id < N, "index out of bounds" ); |
96 | return detail::insn::i_extract<id>(a); |
97 | } |
98 | |
99 | } // namespace SIMDPP_ARCH_NAMESPACE |
100 | } // namespace simdpp |
101 | |
102 | #endif |
103 | |
104 | |