| 1 | /* Copyright (C) 2013-2017 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_DETAIL_INSN_I_NEG_H |
| 9 | #define LIBSIMDPP_SIMDPP_DETAIL_INSN_I_NEG_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/core/i_sub.h> |
| 17 | #include <simdpp/detail/null/math.h> |
| 18 | #include <simdpp/detail/vector_array_macros.h> |
| 19 | |
| 20 | namespace simdpp { |
| 21 | namespace SIMDPP_ARCH_NAMESPACE { |
| 22 | namespace detail { |
| 23 | namespace insn { |
| 24 | |
| 25 | static SIMDPP_INL |
| 26 | int8<16> i_ineg(const int8<16>& a) |
| 27 | { |
| 28 | #if SIMDPP_USE_NULL |
| 29 | return detail::null::neg(a); |
| 30 | #elif SIMDPP_USE_SSE2 || SIMDPP_USE_ALTIVEC || SIMDPP_USE_MSA |
| 31 | return sub(0, a); |
| 32 | #elif SIMDPP_USE_NEON |
| 33 | return vnegq_s8(a.native()); |
| 34 | #endif |
| 35 | } |
| 36 | |
| 37 | #if SIMDPP_USE_AVX2 |
| 38 | static SIMDPP_INL |
| 39 | int8<32> i_ineg(const int8<32>& a) |
| 40 | { |
| 41 | return sub(0, a); |
| 42 | } |
| 43 | #endif |
| 44 | |
| 45 | #if SIMDPP_USE_AVX512BW |
| 46 | static SIMDPP_INL |
| 47 | int8<64> i_ineg(const int8<64>& a) |
| 48 | { |
| 49 | return sub(0, a); |
| 50 | } |
| 51 | #endif |
| 52 | |
| 53 | // ----------------------------------------------------------------------------- |
| 54 | |
| 55 | static SIMDPP_INL |
| 56 | int16<8> i_ineg(const int16<8>& a) |
| 57 | { |
| 58 | #if SIMDPP_USE_NULL |
| 59 | return detail::null::neg(a); |
| 60 | #elif SIMDPP_USE_SSE2 || SIMDPP_USE_ALTIVEC || SIMDPP_USE_MSA |
| 61 | return sub(0, a); |
| 62 | #elif SIMDPP_USE_NEON |
| 63 | return vnegq_s16(a.native()); |
| 64 | #endif |
| 65 | } |
| 66 | |
| 67 | #if SIMDPP_USE_AVX2 |
| 68 | static SIMDPP_INL |
| 69 | int16<16> i_ineg(const int16<16>& a) |
| 70 | { |
| 71 | return sub(0, a); |
| 72 | } |
| 73 | #endif |
| 74 | |
| 75 | #if SIMDPP_USE_AVX512BW |
| 76 | static SIMDPP_INL |
| 77 | int16<32> i_ineg(const int16<32>& a) |
| 78 | { |
| 79 | return sub(0, a); |
| 80 | } |
| 81 | #endif |
| 82 | |
| 83 | // ----------------------------------------------------------------------------- |
| 84 | |
| 85 | static SIMDPP_INL |
| 86 | int32<4> i_ineg(const int32<4>& a) |
| 87 | { |
| 88 | #if SIMDPP_USE_NULL |
| 89 | return detail::null::neg(a); |
| 90 | #elif SIMDPP_USE_SSE2 || SIMDPP_USE_ALTIVEC || SIMDPP_USE_MSA |
| 91 | return sub(0, a); |
| 92 | #elif SIMDPP_USE_NEON |
| 93 | return vnegq_s32(a.native()); |
| 94 | #endif |
| 95 | } |
| 96 | |
| 97 | #if SIMDPP_USE_AVX2 |
| 98 | static SIMDPP_INL |
| 99 | int32<8> i_ineg(const int32<8>& a) |
| 100 | { |
| 101 | return sub(0, a); |
| 102 | } |
| 103 | #endif |
| 104 | |
| 105 | #if SIMDPP_USE_AVX512F |
| 106 | static SIMDPP_INL |
| 107 | int32<16> i_ineg(const int32<16>& a) |
| 108 | { |
| 109 | return sub(0, a); |
| 110 | } |
| 111 | #endif |
| 112 | |
| 113 | // ----------------------------------------------------------------------------- |
| 114 | |
| 115 | static SIMDPP_INL |
| 116 | int64<2> i_ineg(const int64<2>& a) |
| 117 | { |
| 118 | #if SIMDPP_USE_SSE2 || SIMDPP_USE_NEON || SIMDPP_USE_VSX_207 || SIMDPP_USE_MSA |
| 119 | return sub(0, a); |
| 120 | #elif SIMDPP_USE_NULL || SIMDPP_USE_ALTIVEC |
| 121 | return detail::null::neg(a); |
| 122 | #endif |
| 123 | } |
| 124 | |
| 125 | #if SIMDPP_USE_AVX2 |
| 126 | static SIMDPP_INL |
| 127 | uint64<4> i_ineg(const int64<4>& a) |
| 128 | { |
| 129 | return sub(0, a); |
| 130 | } |
| 131 | #endif |
| 132 | |
| 133 | #if SIMDPP_USE_AVX512F |
| 134 | static SIMDPP_INL |
| 135 | uint64<8> i_ineg(const int64<8>& a) |
| 136 | { |
| 137 | return sub(0, a); |
| 138 | } |
| 139 | #endif |
| 140 | |
| 141 | // ----------------------------------------------------------------------------- |
| 142 | |
| 143 | template<class V> SIMDPP_INL |
| 144 | V i_ineg(const V& a) |
| 145 | { |
| 146 | SIMDPP_VEC_ARRAY_IMPL1(V, i_ineg, a) |
| 147 | } |
| 148 | |
| 149 | } // namespace insn |
| 150 | } // namespace detail |
| 151 | } // namespace SIMDPP_ARCH_NAMESPACE |
| 152 | } // namespace simdpp |
| 153 | |
| 154 | #endif |
| 155 | |
| 156 | |