1 /* SPDX-License-Identifier: MIT
2  *
3  * Permission is hereby granted, free of charge, to any person
4  * obtaining a copy of this software and associated documentation
5  * files (the "Software"), to deal in the Software without
6  * restriction, including without limitation the rights to use, copy,
7  * modify, merge, publish, distribute, sublicense, and/or sell copies
8  * of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be
12  * included in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Copyright:
24  *   2020      Evan Nemerson <evan@nemerson.com>
25  *   2020      Sean Maher <seanptmaher@gmail.com> (Copyright owned by Google, LLC)
26  */
27 
28 #if !defined(SIMDE_ARM_NEON_ADDW_H)
29 #define SIMDE_ARM_NEON_ADDW_H
30 
31 #include "types.h"
32 #include "add.h"
33 #include "movl.h"
34 
35 HEDLEY_DIAGNOSTIC_PUSH
36 SIMDE_DISABLE_UNWANTED_DIAGNOSTICS
37 SIMDE_BEGIN_DECLS_
38 
39 SIMDE_FUNCTION_ATTRIBUTES
40 simde_int16x8_t
simde_vaddw_s8(simde_int16x8_t a,simde_int8x8_t b)41 simde_vaddw_s8(simde_int16x8_t a, simde_int8x8_t b) {
42   #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
43     return vaddw_s8(a, b);
44   #elif SIMDE_NATURAL_VECTOR_SIZE_GE(128)
45     return simde_vaddq_s16(a, simde_vmovl_s8(b));
46   #else
47     simde_int16x8_private r_;
48     simde_int16x8_private a_ = simde_int16x8_to_private(a);
49     simde_int8x8_private b_ = simde_int8x8_to_private(b);
50 
51     #if (SIMDE_NATURAL_VECTOR_SIZE > 0) && defined(SIMDE_VECTOR_SUBSCRIPT_OPS) && defined(SIMDE_CONVERT_VECTOR_)
52       SIMDE_CONVERT_VECTOR_(r_.values, b_.values);
53       r_.values += a_.values;
54     #else
55       SIMDE_VECTORIZE
56       for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
57         r_.values[i] = a_.values[i] + b_.values[i];
58       }
59     #endif
60 
61     return simde_int16x8_from_private(r_);
62   #endif
63 }
64 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
65   #undef vaddw_s8
66   #define vaddw_s8(a, b) simde_vaddw_s8((a), (b))
67 #endif
68 
69 SIMDE_FUNCTION_ATTRIBUTES
70 simde_int32x4_t
simde_vaddw_s16(simde_int32x4_t a,simde_int16x4_t b)71 simde_vaddw_s16(simde_int32x4_t a, simde_int16x4_t b) {
72   #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
73     return vaddw_s16(a, b);
74   #elif SIMDE_NATURAL_VECTOR_SIZE_GE(128)
75     return simde_vaddq_s32(a, simde_vmovl_s16(b));
76   #else
77     simde_int32x4_private r_;
78     simde_int32x4_private a_ = simde_int32x4_to_private(a);
79     simde_int16x4_private b_ = simde_int16x4_to_private(b);
80 
81     #if (SIMDE_NATURAL_VECTOR_SIZE > 0) && defined(SIMDE_VECTOR_SUBSCRIPT_OPS) && defined(SIMDE_CONVERT_VECTOR_)
82       SIMDE_CONVERT_VECTOR_(r_.values, b_.values);
83       r_.values += a_.values;
84     #else
85       SIMDE_VECTORIZE
86       for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
87         r_.values[i] = a_.values[i] + b_.values[i];
88       }
89     #endif
90 
91     return simde_int32x4_from_private(r_);
92   #endif
93 }
94 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
95   #undef vaddw_s16
96   #define vaddw_s16(a, b) simde_vaddw_s16((a), (b))
97 #endif
98 
99 SIMDE_FUNCTION_ATTRIBUTES
100 simde_int64x2_t
simde_vaddw_s32(simde_int64x2_t a,simde_int32x2_t b)101 simde_vaddw_s32(simde_int64x2_t a, simde_int32x2_t b) {
102   #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
103     return vaddw_s32(a, b);
104   #elif SIMDE_NATURAL_VECTOR_SIZE_GE(128)
105     return simde_vaddq_s64(a, simde_vmovl_s32(b));
106   #else
107     simde_int64x2_private r_;
108     simde_int64x2_private a_ = simde_int64x2_to_private(a);
109     simde_int32x2_private b_ = simde_int32x2_to_private(b);
110 
111     #if (SIMDE_NATURAL_VECTOR_SIZE > 0) && defined(SIMDE_VECTOR_SUBSCRIPT_OPS) && defined(SIMDE_CONVERT_VECTOR_)
112       SIMDE_CONVERT_VECTOR_(r_.values, b_.values);
113       r_.values += a_.values;
114     #else
115       SIMDE_VECTORIZE
116       for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
117         r_.values[i] = a_.values[i] + b_.values[i];
118       }
119     #endif
120 
121     return simde_int64x2_from_private(r_);
122   #endif
123 }
124 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
125   #undef vaddw_s32
126   #define vaddw_s32(a, b) simde_vaddw_s32((a), (b))
127 #endif
128 
129 SIMDE_FUNCTION_ATTRIBUTES
130 simde_uint16x8_t
simde_vaddw_u8(simde_uint16x8_t a,simde_uint8x8_t b)131 simde_vaddw_u8(simde_uint16x8_t a, simde_uint8x8_t b) {
132   #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
133     return vaddw_u8(a, b);
134   #elif SIMDE_NATURAL_VECTOR_SIZE_GE(128)
135     return simde_vaddq_u16(a, simde_vmovl_u8(b));
136   #else
137     simde_uint16x8_private r_;
138     simde_uint16x8_private a_ = simde_uint16x8_to_private(a);
139     simde_uint8x8_private b_ = simde_uint8x8_to_private(b);
140 
141     #if (SIMDE_NATURAL_VECTOR_SIZE > 0) && defined(SIMDE_VECTOR_SUBSCRIPT_OPS) && defined(SIMDE_CONVERT_VECTOR_)
142       SIMDE_CONVERT_VECTOR_(r_.values, b_.values);
143       r_.values += a_.values;
144     #else
145       SIMDE_VECTORIZE
146       for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
147         r_.values[i] = a_.values[i] + b_.values[i];
148       }
149     #endif
150 
151     return simde_uint16x8_from_private(r_);
152   #endif
153 }
154 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
155   #undef vaddw_u8
156   #define vaddw_u8(a, b) simde_vaddw_u8((a), (b))
157 #endif
158 
159 SIMDE_FUNCTION_ATTRIBUTES
160 simde_uint32x4_t
simde_vaddw_u16(simde_uint32x4_t a,simde_uint16x4_t b)161 simde_vaddw_u16(simde_uint32x4_t a, simde_uint16x4_t b) {
162   #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
163     return vaddw_u16(a, b);
164   #elif SIMDE_NATURAL_VECTOR_SIZE_GE(128)
165     return simde_vaddq_u32(a, simde_vmovl_u16(b));
166   #else
167     simde_uint32x4_private r_;
168     simde_uint32x4_private a_ = simde_uint32x4_to_private(a);
169     simde_uint16x4_private b_ = simde_uint16x4_to_private(b);
170 
171     #if (SIMDE_NATURAL_VECTOR_SIZE > 0) && defined(SIMDE_VECTOR_SUBSCRIPT_OPS) && defined(SIMDE_CONVERT_VECTOR_)
172       SIMDE_CONVERT_VECTOR_(r_.values, b_.values);
173       r_.values += a_.values;
174     #else
175       SIMDE_VECTORIZE
176       for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
177         r_.values[i] = a_.values[i] + b_.values[i];
178       }
179     #endif
180 
181     return simde_uint32x4_from_private(r_);
182   #endif
183 }
184 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
185   #undef vaddw_u16
186   #define vaddw_u16(a, b) simde_vaddw_u16((a), (b))
187 #endif
188 
189 SIMDE_FUNCTION_ATTRIBUTES
190 simde_uint64x2_t
simde_vaddw_u32(simde_uint64x2_t a,simde_uint32x2_t b)191 simde_vaddw_u32(simde_uint64x2_t a, simde_uint32x2_t b) {
192   #if defined(SIMDE_ARM_NEON_A32V7_NATIVE)
193     return vaddw_u32(a, b);
194   #elif SIMDE_NATURAL_VECTOR_SIZE_GE(128)
195     return simde_vaddq_u64(a, simde_vmovl_u32(b));
196   #else
197     simde_uint64x2_private r_;
198     simde_uint64x2_private a_ = simde_uint64x2_to_private(a);
199     simde_uint32x2_private b_ = simde_uint32x2_to_private(b);
200 
201     #if (SIMDE_NATURAL_VECTOR_SIZE > 0) && defined(SIMDE_VECTOR_SUBSCRIPT_OPS) && defined(SIMDE_CONVERT_VECTOR_)
202       SIMDE_CONVERT_VECTOR_(r_.values, b_.values);
203       r_.values += a_.values;
204     #else
205       SIMDE_VECTORIZE
206       for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
207         r_.values[i] = a_.values[i] + b_.values[i];
208       }
209     #endif
210 
211     return simde_uint64x2_from_private(r_);
212   #endif
213 }
214 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
215   #undef vaddw_u32
216   #define vaddw_u32(a, b) simde_vaddw_u32((a), (b))
217 #endif
218 
219 SIMDE_END_DECLS_
220 HEDLEY_DIAGNOSTIC_POP
221 
222 #endif /* !defined(SIMDE_ARM_NEON_ADDW_H) */
223