1 | /* Copyright (C) 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_SIMDPP_CORE_DETAIL_VEC_INSERT_H |
9 | #define LIBSIMDPP_SIMDPP_CORE_DETAIL_VEC_INSERT_H |
10 | |
11 | #ifndef LIBSIMDPP_SIMD_H |
12 | #error "This file must be included through simd.h" |
13 | #endif |
14 | |
15 | #include <simdpp/setup_arch.h> |
16 | #include <simdpp/types.h> |
17 | |
18 | #include <cstring> |
19 | |
20 | namespace simdpp { |
21 | namespace SIMDPP_ARCH_NAMESPACE { |
22 | namespace detail { |
23 | |
24 | template<class R, class V> SIMDPP_INL |
25 | void subvec_insert_impl(R& r, const V& v, unsigned n) |
26 | { |
27 | static_assert(V::length >= R::base_length, "Too small vector to insert" ); |
28 | |
29 | for (unsigned i = 0; i < V::vec_length; ++i) { |
30 | r.vec(n*v.vec_length + i) = v.vec(i); //TODO combine or split as needed |
31 | } |
32 | } |
33 | |
34 | // Sets the elements [M*n .. M*(n+1)) of @a a to the contents of @a x |
35 | template<unsigned N, unsigned M> SIMDPP_INL |
36 | void subvec_insert(uint8<N>& a, const uint8<M>& x, unsigned n) { subvec_insert_impl(a, x, n); } |
37 | template<unsigned N, unsigned M> SIMDPP_INL |
38 | void subvec_insert(uint16<N>& a, const uint16<M>& x, unsigned n) { subvec_insert_impl(a, x, n); } |
39 | template<unsigned N, unsigned M> SIMDPP_INL |
40 | void subvec_insert(uint32<N>& a, const uint32<M>& x, unsigned n) { subvec_insert_impl(a, x, n); } |
41 | template<unsigned N, unsigned M> SIMDPP_INL |
42 | void subvec_insert(uint64<N>& a, const uint64<M>& x, unsigned n) { subvec_insert_impl(a, x, n); } |
43 | |
44 | template<unsigned N, unsigned M> SIMDPP_INL |
45 | void subvec_insert(int8<N>& a, const int8<M>& x, unsigned n) { subvec_insert_impl(a, x, n); } |
46 | template<unsigned N, unsigned M> SIMDPP_INL |
47 | void subvec_insert(int16<N>& a, const int16<M>& x, unsigned n) { subvec_insert_impl(a, x, n); } |
48 | template<unsigned N, unsigned M> SIMDPP_INL |
49 | void subvec_insert(int32<N>& a, const int32<M>& x, unsigned n) { subvec_insert_impl(a, x, n); } |
50 | template<unsigned N, unsigned M> SIMDPP_INL |
51 | void subvec_insert(int64<N>& a, const int64<M>& x, unsigned n) { subvec_insert_impl(a, x, n); } |
52 | |
53 | template<unsigned N, unsigned M> SIMDPP_INL |
54 | void subvec_insert(float32<N>& a, const float32<M>& x, unsigned n) { subvec_insert_impl(a, x, n); } |
55 | template<unsigned N, unsigned M> SIMDPP_INL |
56 | void subvec_insert(float64<N>& a, const float64<M>& x, unsigned n) { subvec_insert_impl(a, x, n); } |
57 | |
58 | } // namespace detail |
59 | } // namespace SIMDPP_ARCH_NAMESPACE |
60 | } // namespace simdpp |
61 | |
62 | #endif |
63 | |