| 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 <[email protected]> |
| 25 |
*/ |
| 26 |
|
| 27 |
#if !defined(SIMDE_ARM_NEON_UQADD_H) |
| 28 |
#define SIMDE_ARM_NEON_UQADD_H |
| 29 |
|
| 30 |
#include "types.h" |
| 31 |
|
| 32 |
HEDLEY_DIAGNOSTIC_PUSH |
| 33 |
SIMDE_DISABLE_UNWANTED_DIAGNOSTICS |
| 34 |
SIMDE_BEGIN_DECLS_ |
| 35 |
|
| 36 |
SIMDE_FUNCTION_ATTRIBUTES |
| 37 |
int8_t |
| 38 |
simde_vuqaddb_s8(int8_t a, uint8_t b) { |
| 39 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 40 |
#if defined(SIMDE_BUG_CLANG_GIT_4EC445B8) |
| 41 |
return vuqaddb_s8(a, HEDLEY_STATIC_CAST(int8_t, b)); |
| 42 |
#else |
| 43 |
return vuqaddb_s8(a, b); |
| 44 |
#endif |
| 45 |
#else |
| 46 |
int16_t r_ = HEDLEY_STATIC_CAST(int16_t, a) + HEDLEY_STATIC_CAST(int16_t, b); |
| 47 |
return (r_ < INT8_MIN) ? INT8_MIN : ((r_ > INT8_MAX) ? INT8_MAX : HEDLEY_STATIC_CAST(int8_t, r_)); |
| 48 |
#endif |
| 49 |
} |
| 50 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 51 |
#undef vuqaddb_s8 |
| 52 |
#define vuqaddb_s8(a, b) simde_vuqaddb_s8((a), (b)) |
| 53 |
#endif |
| 54 |
|
| 55 |
SIMDE_FUNCTION_ATTRIBUTES |
| 56 |
int16_t |
| 57 |
simde_vuqaddh_s16(int16_t a, uint16_t b) { |
| 58 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 59 |
#if defined(SIMDE_BUG_CLANG_GIT_4EC445B8) |
| 60 |
return vuqaddh_s16(a, HEDLEY_STATIC_CAST(int16_t, b)); |
| 61 |
#else |
| 62 |
return vuqaddh_s16(a, b); |
| 63 |
#endif |
| 64 |
#else |
| 65 |
int32_t r_ = HEDLEY_STATIC_CAST(int32_t, a) + HEDLEY_STATIC_CAST(int32_t, b); |
| 66 |
return (r_ < INT16_MIN) ? INT16_MIN : ((r_ > INT16_MAX) ? INT16_MAX : HEDLEY_STATIC_CAST(int16_t, r_)); |
| 67 |
#endif |
| 68 |
} |
| 69 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 70 |
#undef vuqaddh_s16 |
| 71 |
#define vuqaddh_s16(a, b) simde_vuqaddh_s16((a), (b)) |
| 72 |
#endif |
| 73 |
|
| 74 |
SIMDE_FUNCTION_ATTRIBUTES |
| 75 |
int32_t |
| 76 |
simde_vuqadds_s32(int32_t a, uint32_t b) { |
| 77 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 78 |
#if defined(SIMDE_BUG_CLANG_GIT_4EC445B8) |
| 79 |
return vuqadds_s32(a, HEDLEY_STATIC_CAST(int32_t, b)); |
| 80 |
#else |
| 81 |
return vuqadds_s32(a, b); |
| 82 |
#endif |
| 83 |
#else |
| 84 |
int64_t r_ = HEDLEY_STATIC_CAST(int64_t, a) + HEDLEY_STATIC_CAST(int64_t, b); |
| 85 |
return (r_ < INT32_MIN) ? INT32_MIN : ((r_ > INT32_MAX) ? INT32_MAX : HEDLEY_STATIC_CAST(int32_t, r_)); |
| 86 |
#endif |
| 87 |
} |
| 88 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 89 |
#undef vuqadds_s32 |
| 90 |
#define vuqadds_s32(a, b) simde_vuqadds_s32((a), (b)) |
| 91 |
#endif |
| 92 |
|
| 93 |
SIMDE_FUNCTION_ATTRIBUTES |
| 94 |
int64_t |
| 95 |
simde_vuqaddd_s64(int64_t a, uint64_t b) { |
| 96 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 97 |
#if defined(SIMDE_BUG_CLANG_GIT_4EC445B8) |
| 98 |
return vuqaddd_s64(a, HEDLEY_STATIC_CAST(int64_t, b)); |
| 99 |
#else |
| 100 |
return vuqaddd_s64(a, b); |
| 101 |
#endif |
| 102 |
#else |
| 103 |
/* TODO: I suspect there is room for improvement here. This is |
| 104 |
* just the first thing that worked, and I don't feel like messing |
| 105 |
* with it now. */ |
| 106 |
int64_t r; |
| 107 |
|
| 108 |
if (a < 0) { |
| 109 |
uint64_t na = HEDLEY_STATIC_CAST(uint64_t, -a); |
| 110 |
if (na > b) { |
| 111 |
uint64_t t = na - b; |
| 112 |
r = (t > (HEDLEY_STATIC_CAST(uint64_t, INT64_MAX) + 1)) ? INT64_MIN : -HEDLEY_STATIC_CAST(int64_t, t); |
| 113 |
} else { |
| 114 |
uint64_t t = b - na; |
| 115 |
r = (t > (HEDLEY_STATIC_CAST(uint64_t, INT64_MAX) )) ? INT64_MAX : HEDLEY_STATIC_CAST(int64_t, t); |
| 116 |
} |
| 117 |
} else { |
| 118 |
uint64_t ua = HEDLEY_STATIC_CAST(uint64_t, a); |
| 119 |
r = ((INT64_MAX - ua) < b) ? INT64_MAX : HEDLEY_STATIC_CAST(int64_t, ua + b); |
| 120 |
} |
| 121 |
|
| 122 |
return r; |
| 123 |
#endif |
| 124 |
} |
| 125 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 126 |
#undef vuqaddd_s64 |
| 127 |
#define vuqaddd_s64(a, b) simde_vuqaddd_s64((a), (b)) |
| 128 |
#endif |
| 129 |
|
| 130 |
SIMDE_FUNCTION_ATTRIBUTES |
| 131 |
simde_int8x8_t |
| 132 |
simde_vuqadd_s8(simde_int8x8_t a, simde_uint8x8_t b) { |
| 133 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 134 |
return vuqadd_s8(a, b); |
| 135 |
#else |
| 136 |
simde_int8x8_private |
| 137 |
r_, |
| 138 |
a_ = simde_int8x8_to_private(a); |
| 139 |
simde_uint8x8_private b_ = simde_uint8x8_to_private(b); |
| 140 |
|
| 141 |
SIMDE_VECTORIZE |
| 142 |
for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) { |
| 143 |
r_.values[i] = simde_vuqaddb_s8(a_.values[i], b_.values[i]); |
| 144 |
} |
| 145 |
|
| 146 |
return simde_int8x8_from_private(r_); |
| 147 |
#endif |
| 148 |
} |
| 149 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 150 |
#undef vuqadd_s8 |
| 151 |
#define vuqadd_s8(a, b) simde_vuqadd_s8((a), (b)) |
| 152 |
#endif |
| 153 |
|
| 154 |
SIMDE_FUNCTION_ATTRIBUTES |
| 155 |
simde_int16x4_t |
| 156 |
simde_vuqadd_s16(simde_int16x4_t a, simde_uint16x4_t b) { |
| 157 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 158 |
return vuqadd_s16(a, b); |
| 159 |
#else |
| 160 |
simde_int16x4_private |
| 161 |
r_, |
| 162 |
a_ = simde_int16x4_to_private(a); |
| 163 |
simde_uint16x4_private b_ = simde_uint16x4_to_private(b); |
| 164 |
|
| 165 |
SIMDE_VECTORIZE |
| 166 |
for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) { |
| 167 |
r_.values[i] = simde_vuqaddh_s16(a_.values[i], b_.values[i]); |
| 168 |
} |
| 169 |
|
| 170 |
return simde_int16x4_from_private(r_); |
| 171 |
#endif |
| 172 |
} |
| 173 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 174 |
#undef vuqadd_s16 |
| 175 |
#define vuqadd_s16(a, b) simde_vuqadd_s16((a), (b)) |
| 176 |
#endif |
| 177 |
|
| 178 |
SIMDE_FUNCTION_ATTRIBUTES |
| 179 |
simde_int32x2_t |
| 180 |
simde_vuqadd_s32(simde_int32x2_t a, simde_uint32x2_t b) { |
| 181 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 182 |
return vuqadd_s32(a, b); |
| 183 |
#else |
| 184 |
simde_int32x2_private |
| 185 |
r_, |
| 186 |
a_ = simde_int32x2_to_private(a); |
| 187 |
simde_uint32x2_private b_ = simde_uint32x2_to_private(b); |
| 188 |
|
| 189 |
SIMDE_VECTORIZE |
| 190 |
for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) { |
| 191 |
r_.values[i] = simde_vuqadds_s32(a_.values[i], b_.values[i]); |
| 192 |
} |
| 193 |
|
| 194 |
return simde_int32x2_from_private(r_); |
| 195 |
#endif |
| 196 |
} |
| 197 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 198 |
#undef vuqadd_s32 |
| 199 |
#define vuqadd_s32(a, b) simde_vuqadd_s32((a), (b)) |
| 200 |
#endif |
| 201 |
|
| 202 |
SIMDE_FUNCTION_ATTRIBUTES |
| 203 |
simde_int64x1_t |
| 204 |
simde_vuqadd_s64(simde_int64x1_t a, simde_uint64x1_t b) { |
| 205 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 206 |
return vuqadd_s64(a, b); |
| 207 |
#else |
| 208 |
simde_int64x1_private |
| 209 |
r_, |
| 210 |
a_ = simde_int64x1_to_private(a); |
| 211 |
simde_uint64x1_private b_ = simde_uint64x1_to_private(b); |
| 212 |
|
| 213 |
SIMDE_VECTORIZE |
| 214 |
for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) { |
| 215 |
r_.values[i] = simde_vuqaddd_s64(a_.values[i], b_.values[i]); |
| 216 |
} |
| 217 |
|
| 218 |
return simde_int64x1_from_private(r_); |
| 219 |
#endif |
| 220 |
} |
| 221 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 222 |
#undef vuqadd_s64 |
| 223 |
#define vuqadd_s64(a, b) simde_vuqadd_s64((a), (b)) |
| 224 |
#endif |
| 225 |
|
| 226 |
SIMDE_FUNCTION_ATTRIBUTES |
| 227 |
simde_int8x16_t |
| 228 |
simde_vuqaddq_s8(simde_int8x16_t a, simde_uint8x16_t b) { |
| 229 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 230 |
return vuqaddq_s8(a, b); |
| 231 |
#else |
| 232 |
simde_int8x16_private |
| 233 |
r_, |
| 234 |
a_ = simde_int8x16_to_private(a); |
| 235 |
simde_uint8x16_private b_ = simde_uint8x16_to_private(b); |
| 236 |
|
| 237 |
SIMDE_VECTORIZE |
| 238 |
for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) { |
| 239 |
r_.values[i] = simde_vuqaddb_s8(a_.values[i], b_.values[i]); |
| 240 |
} |
| 241 |
|
| 242 |
return simde_int8x16_from_private(r_); |
| 243 |
#endif |
| 244 |
} |
| 245 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 246 |
#undef vuqaddq_s8 |
| 247 |
#define vuqaddq_s8(a, b) simde_vuqaddq_s8((a), (b)) |
| 248 |
#endif |
| 249 |
|
| 250 |
SIMDE_FUNCTION_ATTRIBUTES |
| 251 |
simde_int16x8_t |
| 252 |
simde_vuqaddq_s16(simde_int16x8_t a, simde_uint16x8_t b) { |
| 253 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 254 |
return vuqaddq_s16(a, b); |
| 255 |
#else |
| 256 |
simde_int16x8_private |
| 257 |
r_, |
| 258 |
a_ = simde_int16x8_to_private(a); |
| 259 |
simde_uint16x8_private b_ = simde_uint16x8_to_private(b); |
| 260 |
|
| 261 |
SIMDE_VECTORIZE |
| 262 |
for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) { |
| 263 |
r_.values[i] = simde_vuqaddh_s16(a_.values[i], b_.values[i]); |
| 264 |
} |
| 265 |
|
| 266 |
return simde_int16x8_from_private(r_); |
| 267 |
#endif |
| 268 |
} |
| 269 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 270 |
#undef vuqaddq_s16 |
| 271 |
#define vuqaddq_s16(a, b) simde_vuqaddq_s16((a), (b)) |
| 272 |
#endif |
| 273 |
|
| 274 |
SIMDE_FUNCTION_ATTRIBUTES |
| 275 |
simde_int32x4_t |
| 276 |
simde_vuqaddq_s32(simde_int32x4_t a, simde_uint32x4_t b) { |
| 277 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 278 |
return vuqaddq_s32(a, b); |
| 279 |
#else |
| 280 |
simde_int32x4_private |
| 281 |
r_, |
| 282 |
a_ = simde_int32x4_to_private(a); |
| 283 |
simde_uint32x4_private b_ = simde_uint32x4_to_private(b); |
| 284 |
|
| 285 |
SIMDE_VECTORIZE |
| 286 |
for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) { |
| 287 |
r_.values[i] = simde_vuqadds_s32(a_.values[i], b_.values[i]); |
| 288 |
} |
| 289 |
|
| 290 |
return simde_int32x4_from_private(r_); |
| 291 |
#endif |
| 292 |
} |
| 293 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 294 |
#undef vuqaddq_s32 |
| 295 |
#define vuqaddq_s32(a, b) simde_vuqaddq_s32((a), (b)) |
| 296 |
#endif |
| 297 |
|
| 298 |
SIMDE_FUNCTION_ATTRIBUTES |
| 299 |
simde_int64x2_t |
| 300 |
simde_vuqaddq_s64(simde_int64x2_t a, simde_uint64x2_t b) { |
| 301 |
#if defined(SIMDE_ARM_NEON_A64V8_NATIVE) |
| 302 |
return vuqaddq_s64(a, b); |
| 303 |
#else |
| 304 |
simde_int64x2_private |
| 305 |
r_, |
| 306 |
a_ = simde_int64x2_to_private(a); |
| 307 |
simde_uint64x2_private b_ = simde_uint64x2_to_private(b); |
| 308 |
|
| 309 |
SIMDE_VECTORIZE |
| 310 |
for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) { |
| 311 |
r_.values[i] = simde_vuqaddd_s64(a_.values[i], b_.values[i]); |
| 312 |
} |
| 313 |
|
| 314 |
return simde_int64x2_from_private(r_); |
| 315 |
#endif |
| 316 |
} |
| 317 |
#if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES) |
| 318 |
#undef vuqaddq_s64 |
| 319 |
#define vuqaddq_s64(a, b) simde_vuqaddq_s64((a), (b)) |
| 320 |
#endif |
| 321 |
|
| 322 |
SIMDE_END_DECLS_ |
| 323 |
HEDLEY_DIAGNOSTIC_POP |
| 324 |
|
| 325 |
#endif /* !defined(SIMDE_ARM_NEON_UQADD_H) */ |