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
20namespace simdpp {
21namespace SIMDPP_ARCH_NAMESPACE {
22namespace detail {
23
24template<class R, class V> SIMDPP_INL
25void 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
35template<unsigned N, unsigned M> SIMDPP_INL
36void subvec_insert(uint8<N>& a, const uint8<M>& x, unsigned n) { subvec_insert_impl(a, x, n); }
37template<unsigned N, unsigned M> SIMDPP_INL
38void subvec_insert(uint16<N>& a, const uint16<M>& x, unsigned n) { subvec_insert_impl(a, x, n); }
39template<unsigned N, unsigned M> SIMDPP_INL
40void subvec_insert(uint32<N>& a, const uint32<M>& x, unsigned n) { subvec_insert_impl(a, x, n); }
41template<unsigned N, unsigned M> SIMDPP_INL
42void subvec_insert(uint64<N>& a, const uint64<M>& x, unsigned n) { subvec_insert_impl(a, x, n); }
43
44template<unsigned N, unsigned M> SIMDPP_INL
45void subvec_insert(int8<N>& a, const int8<M>& x, unsigned n) { subvec_insert_impl(a, x, n); }
46template<unsigned N, unsigned M> SIMDPP_INL
47void subvec_insert(int16<N>& a, const int16<M>& x, unsigned n) { subvec_insert_impl(a, x, n); }
48template<unsigned N, unsigned M> SIMDPP_INL
49void subvec_insert(int32<N>& a, const int32<M>& x, unsigned n) { subvec_insert_impl(a, x, n); }
50template<unsigned N, unsigned M> SIMDPP_INL
51void subvec_insert(int64<N>& a, const int64<M>& x, unsigned n) { subvec_insert_impl(a, x, n); }
52
53template<unsigned N, unsigned M> SIMDPP_INL
54void subvec_insert(float32<N>& a, const float32<M>& x, unsigned n) { subvec_insert_impl(a, x, n); }
55template<unsigned N, unsigned M> SIMDPP_INL
56void 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