| 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 | |
| 18 | namespace simdpp { |
| 19 | namespace 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 | */ |
| 33 | template<unsigned id, unsigned N> SIMDPP_INL |
| 34 | uint8<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 | |
| 40 | template<unsigned id, unsigned N> SIMDPP_INL |
| 41 | int8<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 | |
| 47 | template<unsigned id, unsigned N> SIMDPP_INL |
| 48 | uint16<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 | |
| 54 | template<unsigned id, unsigned N> SIMDPP_INL |
| 55 | int16<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 | |
| 61 | template<unsigned id, unsigned N> SIMDPP_INL |
| 62 | uint32<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 | |
| 68 | template<unsigned id, unsigned N> SIMDPP_INL |
| 69 | int32<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 | |
| 75 | template<unsigned id, unsigned N> SIMDPP_INL |
| 76 | uint64<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 | |
| 82 | template<unsigned id, unsigned N> SIMDPP_INL |
| 83 | int64<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 | |
| 89 | template<unsigned id, unsigned N> SIMDPP_INL |
| 90 | float32<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 | |
| 96 | template<unsigned id, unsigned N> SIMDPP_INL |
| 97 | float64<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 | |