Debian Codegraph @

gcc/testsuite/gcc.target/aarch64/sve/saturating_arithmetic.inc

raw
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 uint32_t
16 #define UMAX UINT_MAX
17 #define UMIN 0
18 #endif
19
20 void uaddq (UT *out, UT *a, UT *b, int n)
21 {
22 for (int i = 0; i < n; i++)
23 {
24 UT sum = a[i] + b[i];
25 out[i] = sum < a[i] ? UMAX : sum;
26 }
27 }
28
29 void uaddq2 (UT *out, UT *a, UT *b, int n)
30 {
31 for (int i = 0; i < n; i++)
32 {
33 UT sum;
34 if (!__builtin_add_overflow(a[i], b[i], &sum))
35 out[i] = sum;
36 else
37 out[i] = UMAX;
38 }
39 }
40
41 void uaddq_imm (UT *out, UT *a, int n)
42 {
43 for (int i = 0; i < n; i++)
44 {
45 UT sum = a[i] + 50;
46 out[i] = sum < a[i] ? UMAX : sum;
47 }
48 }
49
50 void usubq (UT *out, UT *a, UT *b, int n)
51 {
52 for (int i = 0; i < n; i++)
53 {
54 UT sum = a[i] - b[i];
55 out[i] = sum > a[i] ? UMIN : sum;
56 }
57 }
58
59 void usubq_imm (UT *out, UT *a, int n)
60 {
61 for (int i = 0; i < n; i++)
62 {
63 UT sum = a[i] - 50;
64 out[i] = sum > a[i] ? UMIN : sum;
65 }
66 }
67
68 #endif