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
20namespace simdpp {
21namespace SIMDPP_ARCH_NAMESPACE {
22namespace detail {
23namespace insn {
24
25static SIMDPP_INL
26int8<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
38static SIMDPP_INL
39int8<32> i_ineg(const int8<32>& a)
40{
41 return sub(0, a);
42}
43#endif
44
45#if SIMDPP_USE_AVX512BW
46static SIMDPP_INL
47int8<64> i_ineg(const int8<64>& a)
48{
49 return sub(0, a);
50}
51#endif
52
53// -----------------------------------------------------------------------------
54
55static SIMDPP_INL
56int16<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
68static SIMDPP_INL
69int16<16> i_ineg(const int16<16>& a)
70{
71 return sub(0, a);
72}
73#endif
74
75#if SIMDPP_USE_AVX512BW
76static SIMDPP_INL
77int16<32> i_ineg(const int16<32>& a)
78{
79 return sub(0, a);
80}
81#endif
82
83// -----------------------------------------------------------------------------
84
85static SIMDPP_INL
86int32<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
98static SIMDPP_INL
99int32<8> i_ineg(const int32<8>& a)
100{
101 return sub(0, a);
102}
103#endif
104
105#if SIMDPP_USE_AVX512F
106static SIMDPP_INL
107int32<16> i_ineg(const int32<16>& a)
108{
109 return sub(0, a);
110}
111#endif
112
113// -----------------------------------------------------------------------------
114
115static SIMDPP_INL
116int64<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
126static SIMDPP_INL
127uint64<4> i_ineg(const int64<4>& a)
128{
129 return sub(0, a);
130}
131#endif
132
133#if SIMDPP_USE_AVX512F
134static SIMDPP_INL
135uint64<8> i_ineg(const int64<8>& a)
136{
137 return sub(0, a);
138}
139#endif
140
141// -----------------------------------------------------------------------------
142
143template<class V> SIMDPP_INL
144V 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