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_INSERT_H
9#define LIBSIMDPP_SIMD_INSERT_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/insert.h>
17
18namespace simdpp {
19namespace SIMDPP_ARCH_NAMESPACE {
20
21
22/** Inserts an element into a vector at the position identified by @a id.
23
24 @code
25 r0 = (id == 0) ? x : a0
26 ...
27 rN = (id == N) ? x : aN
28 @endcode
29
30 This function may have very high latency.
31 It is expected that the argument comes from a general-purpose register.
32*/
33template<unsigned id, unsigned N> SIMDPP_INL
34uint8<N> insert(const uint8<N>& a, uint8_t x)
35{
36 static_assert(id < N, "index out of bounds");
37 return detail::insn::i_insert<id>(a, x);
38}
39
40template<unsigned id, unsigned N> SIMDPP_INL
41int8<N> insert(const int8<N>& a, int8_t x)
42{
43 static_assert(id < N, "index out of bounds");
44 return (int8<N>) detail::insn::i_insert<id>((uint8<N>) a, (uint8_t)x);
45}
46
47template<unsigned id, unsigned N> SIMDPP_INL
48uint16<N> insert(const uint16<N>& a, uint16_t x)
49{
50 static_assert(id < N, "index out of bounds");
51 return detail::insn::i_insert<id>(a, x);
52}
53
54template<unsigned id, unsigned N> SIMDPP_INL
55int16<N> insert(const int16<N>& a, int16_t x)
56{
57 static_assert(id < N, "index out of bounds");
58 return (int16<N>) detail::insn::i_insert<id>((uint16<N>) a, (uint16_t)x);
59}
60
61template<unsigned id, unsigned N> SIMDPP_INL
62uint32<N> insert(const uint32<N>& a, uint32_t x)
63{
64 static_assert(id < N, "index out of bounds");
65 return detail::insn::i_insert<id>(a, x);
66}
67
68template<unsigned id, unsigned N> SIMDPP_INL
69int32<N> insert(const int32<N>& a, int32_t x)
70{
71 static_assert(id < N, "index out of bounds");
72 return (int32<N>) detail::insn::i_insert<id>((uint32<N>)a, (uint32_t)x);
73}
74
75template<unsigned id, unsigned N> SIMDPP_INL
76uint64<N> insert(const uint64<N>& a, uint64_t x)
77{
78 static_assert(id < N, "index out of bounds");
79 return detail::insn::i_insert<id>(a, x);
80}
81
82template<unsigned id, unsigned N> SIMDPP_INL
83int64<N> insert(const int64<N>& a, int64_t x)
84{
85 static_assert(id < N, "index out of bounds");
86 return (int64<N>) detail::insn::i_insert<id>((uint64<N>)a, (uint64_t)x);
87}
88
89template<unsigned id, unsigned N> SIMDPP_INL
90float32<N> insert(const float32<N>& a, float x)
91{
92 static_assert(id < N, "index out of bounds");
93 return detail::insn::i_insert<id>(a, x);
94}
95
96template<unsigned id, unsigned N> SIMDPP_INL
97float64<N> insert(const float64<N>& a, double x)
98{
99 static_assert(id < N, "index out of bounds");
100 return detail::insn::i_insert<id>(a, x);
101}
102
103
104} // namespace SIMDPP_ARCH_NAMESPACE
105} // namespace simdpp
106
107#endif
108