Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / gcc / testsuite / gcc.target / aarch64 / vect-abs.c
1
2 /* { dg-do run } */
3 /* { dg-options "-O3" } */
4
5 #include "limits.h"
6
7 extern void abort (void);
8
9 #define N 16
10
11 #include "vect-abs.x"
12
13 #define SET_VEC(size, type) void set_vector_##size (pRINT##size a) \
14                             {                                   \
15                               int i;                            \
16                               for (i=0; i<N; i++)               \
17                                 a[i] = (type##_MIN) + (i + 1);  \
18                             }
19
20 #define SET_RVEC(size, type) void set_rvector_##size (pRINT##size a) \
21                              {                                \
22                                int i;                         \
23                                for (i=0; i<N; i++)            \
24                                  a[i] = type##_MAX - i;       \
25                              }
26
27 #define CHECK_VEC(size) void check_vector_##size (pRINT##size a, \
28                                                   pRINT##size b) \
29                         {                                      \
30                           int i;                               \
31                           for (i=0; i<N; i++)                  \
32                             if (a[i] != b[i])                  \
33                               abort ();                        \
34                         }
35
36
37 SET_RVEC (8, SCHAR)
38 SET_RVEC (16, SHRT)
39 SET_RVEC (32, INT)
40 SET_RVEC (64, LONG_LONG)
41
42 set_rvector_long (pRLONG a)
43 {
44   int i;
45   for (i=0; i<N; i++)
46     a[i] = (LONG_MAX) - i;
47 }
48
49 SET_VEC (8, SCHAR)
50 SET_VEC (16, SHRT)
51 SET_VEC (32, INT)
52 SET_VEC (64, LONG_LONG)
53
54 set_vector_long (long *__restrict__ a)
55 {
56   long i;
57   for (i=0; i<N; i++)
58     a[i] = (LONG_MIN) + i + 1;
59 }
60
61 CHECK_VEC (8)
62 CHECK_VEC (16)
63 CHECK_VEC (32)
64 CHECK_VEC (64)
65
66 check_vector_long (long *__restrict__ a, long *__restrict__ b)
67 {
68   long i;
69   for (i=0; i<N; i++)
70     if (a[i] != b[i])
71       abort ();
72 }
73
74 int main (void)
75 {
76
77   signed char a8[N];
78   short a16[N];
79   int a32[N];
80   long long a64[N];
81   /* abs () from stdlib.  */
82   int alib32[N];
83   long alibl[N];
84
85
86   signed char b8[N];
87   short b16[N];
88   int b32[N];
89   long long b64[N];
90   /* abs () from stdlib.  */
91   long blibl[N];
92
93   signed char abs_vector_8[N];
94   short abs_vector_16[N];
95   int abs_vector_32[N];
96   long long abs_vector_64[N];
97   long abs_vector_long[N];
98
99   /* Set up result vectors.  */
100   set_rvector_8 (abs_vector_8);
101   set_rvector_16 (abs_vector_16);
102   set_rvector_32 (abs_vector_32);
103   set_rvector_long (abs_vector_long);
104   set_rvector_64 (abs_vector_64);
105
106   /* Set up inputs.  */
107   set_vector_8 (b8);
108   set_vector_16 (b16);
109   set_vector_32 (b32);
110   set_vector_64 (b64);
111   set_vector_long (blibl);
112
113   /* Calculate their absolute values.  */
114   absolute_s8 (a8, b8);
115   absolute_s16 (a16, b16);
116   absolute_s32 (a32, b32);
117   absolute_s64 (a64, b64);
118   /* abs () from stdlib.  */
119   absolute_s32_lib (alib32, b32);
120   absolute_l32_lib (alibl, blibl);
121
122   /* Check.  */
123   check_vector_8 (a8, abs_vector_8);
124   check_vector_16 (a16, abs_vector_16);
125   check_vector_32 (a32, abs_vector_32);
126   check_vector_64 (a64, abs_vector_64);
127   check_vector_32 (alib32, abs_vector_32);
128   check_vector_long (alibl, abs_vector_long);
129
130   return 0;
131 }