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 LIBSIMDPP_SIMD_EXTRACT_H
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
18namespace simdpp {
19namespace 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*/
29template<unsigned id, unsigned N> SIMDPP_INL
30uint8_t extract(const uint8<N>& a)
31{
32 static_assert(id < N, "index out of bounds");
33 return detail::insn::i_extract<id>(a);
34}
35
36template<unsigned id, unsigned N> SIMDPP_INL
37int8_t extract(const int8<N>& a)
38{
39 static_assert(id < N, "index out of bounds");
40 return detail::insn::i_extract<id>(a);
41}
42
43template<unsigned id, unsigned N> SIMDPP_INL
44uint16_t extract(const uint16<N>& a)
45{
46 static_assert(id < N, "index out of bounds");
47 return detail::insn::i_extract<id>(a);
48}
49
50template<unsigned id, unsigned N> SIMDPP_INL
51int16_t extract(const int16<N>& a)
52{
53 static_assert(id < N, "index out of bounds");
54 return detail::insn::i_extract<id>(a);
55}
56
57template<unsigned id, unsigned N> SIMDPP_INL
58uint32_t extract(const uint32<N>& a)
59{
60 static_assert(id < N, "index out of bounds");
61 return detail::insn::i_extract<id>(a);
62}
63
64template<unsigned id, unsigned N> SIMDPP_INL
65int32_t extract(const int32<N>& a)
66{
67 static_assert(id < N, "index out of bounds");
68 return detail::insn::i_extract<id>(a);
69}
70
71template<unsigned id, unsigned N> SIMDPP_INL
72uint64_t extract(const uint64<N>& a)
73{
74 static_assert(id < N, "index out of bounds");
75 return detail::insn::i_extract<id>(a);
76}
77
78template<unsigned id, unsigned N> SIMDPP_INL
79int64_t extract(const int64<N>& a)
80{
81 static_assert(id < N, "index out of bounds");
82 return detail::insn::i_extract<id>(a);
83}
84
85template<unsigned id, unsigned N> SIMDPP_INL
86float extract(const float32<N>& a)
87{
88 static_assert(id < N, "index out of bounds");
89 return detail::insn::i_extract<id>(a);
90}
91
92template<unsigned id, unsigned N> SIMDPP_INL
93double extract(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