| 1 |
/* Template file for vector saturating arithmetic validation. |
| 2 |
|
| 3 |
This file defines saturating addition and subtraction functions for a given |
| 4 |
scalar type, testing the auto-vectorization of these two operators. This |
| 5 |
type, along with the corresponding minimum and maximum values for that type, |
| 6 |
must be defined by any test file which includes this template file. */ |
| 7 |
|
| 8 |
#ifndef SAT_ARIT_AUTOVEC_INC |
| 9 |
#define SAT_ARIT_AUTOVEC_INC |
| 10 |
|
| 11 |
#include <limits.h> |
| 12 |
#include <arm_neon.h> |
| 13 |
|
| 14 |
#ifndef UT |
| 15 |
#define UT unsigned int |
| 16 |
#define VT uint32x4_t |
| 17 |
#define UMAX UINT_MAX |
| 18 |
#define UMIN 0 |
| 19 |
#endif |
| 20 |
|
| 21 |
|
| 22 |
UT uadd_lane (UT a, VT b) |
| 23 |
{ |
| 24 |
UT sum = a + b[0]; |
| 25 |
return sum < a ? UMAX : sum; |
| 26 |
} |
| 27 |
|
| 28 |
void uaddq (UT *out, UT *a, UT *b, int n) |
| 29 |
{ |
| 30 |
for (int i = 0; i < n; i++) |
| 31 |
{ |
| 32 |
UT sum = a[i] + b[i]; |
| 33 |
out[i] = sum < a[i] ? UMAX : sum; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
void uaddq2 (UT *out, UT *a, UT *b, int n) |
| 38 |
{ |
| 39 |
for (int i = 0; i < n; i++) |
| 40 |
{ |
| 41 |
UT sum; |
| 42 |
if (!__builtin_add_overflow(a[i], b[i], &sum)) |
| 43 |
out[i] = sum; |
| 44 |
else |
| 45 |
out[i] = UMAX; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
void usubq (UT *out, UT *a, UT *b, int n) |
| 50 |
{ |
| 51 |
for (int i = 0; i < n; i++) |
| 52 |
{ |
| 53 |
UT sum = a[i] - b[i]; |
| 54 |
out[i] = sum > a[i] ? UMIN : sum; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
#endif |