New Advanced SIMD intrinsics tests.
[platform/upstream/gcc49.git] / gcc / testsuite / gcc.target / aarch64 / advsimd-intrinsics / cmp_op.inc
1 #include <arm_neon.h>
2 #include "arm-neon-ref.h"
3 #include "compute-ref-data.h"
4 #include <math.h>
5
6 /* Additional expected results declaration, they are initialized in
7    each test file.  */
8 extern ARRAY(expected_uint, uint, 8, 8);
9 extern ARRAY(expected_uint, uint, 16, 4);
10 extern ARRAY(expected_uint, uint, 32, 2);
11 extern ARRAY(expected_q_uint, uint, 8, 16);
12 extern ARRAY(expected_q_uint, uint, 16, 8);
13 extern ARRAY(expected_q_uint, uint, 32, 4);
14 extern ARRAY(expected_float, uint, 32, 2);
15 extern ARRAY(expected_q_float, uint, 32, 4);
16 extern ARRAY(expected_uint2, uint, 32, 2);
17 extern ARRAY(expected_uint3, uint, 32, 2);
18 extern ARRAY(expected_uint4, uint, 32, 2);
19 extern ARRAY(expected_nan, uint, 32, 2);
20 extern ARRAY(expected_mnan, uint, 32, 2);
21 extern ARRAY(expected_nan2, uint, 32, 2);
22 extern ARRAY(expected_inf, uint, 32, 2);
23 extern ARRAY(expected_minf, uint, 32, 2);
24 extern ARRAY(expected_inf2, uint, 32, 2);
25 extern ARRAY(expected_mzero, uint, 32, 2);
26 extern ARRAY(expected_p8, uint, 8, 8);
27 extern ARRAY(expected_q_p8, uint, 8, 16);
28
29 #define FNNAME1(NAME) exec_ ## NAME
30 #define FNNAME(NAME) FNNAME1(NAME)
31
32 void FNNAME (INSN_NAME) (void)
33 {
34   /* Basic test: y=vcomp(x1,x2), then store the result.  */
35 #define TEST_VCOMP1(INSN, Q, T1, T2, T3, W, N)                          \
36   VECT_VAR(vector_res, T3, W, N) =                                      \
37     INSN##Q##_##T2##W(VECT_VAR(vector, T1, W, N),                       \
38                       VECT_VAR(vector2, T1, W, N));                     \
39   vst1##Q##_u##W(VECT_VAR(result, T3, W, N), VECT_VAR(vector_res, T3, W, N))
40
41 #define TEST_VCOMP(INSN, Q, T1, T2, T3, W, N)                           \
42   TEST_VCOMP1(INSN, Q, T1, T2, T3, W, N)
43
44   /* No need for 64 bits elements.  */
45   DECL_VARIABLE(vector, int, 8, 8);
46   DECL_VARIABLE(vector, int, 16, 4);
47   DECL_VARIABLE(vector, int, 32, 2);
48   DECL_VARIABLE(vector, uint, 8, 8);
49   DECL_VARIABLE(vector, uint, 16, 4);
50   DECL_VARIABLE(vector, uint, 32, 2);
51   DECL_VARIABLE(vector, float, 32, 2);
52   DECL_VARIABLE(vector, int, 8, 16);
53   DECL_VARIABLE(vector, int, 16, 8);
54   DECL_VARIABLE(vector, int, 32, 4);
55   DECL_VARIABLE(vector, uint, 8, 16);
56   DECL_VARIABLE(vector, uint, 16, 8);
57   DECL_VARIABLE(vector, uint, 32, 4);
58   DECL_VARIABLE(vector, float, 32, 4);
59
60   DECL_VARIABLE(vector2, int, 8, 8);
61   DECL_VARIABLE(vector2, int, 16, 4);
62   DECL_VARIABLE(vector2, int, 32, 2);
63   DECL_VARIABLE(vector2, uint, 8, 8);
64   DECL_VARIABLE(vector2, uint, 16, 4);
65   DECL_VARIABLE(vector2, uint, 32, 2);
66   DECL_VARIABLE(vector2, float, 32, 2);
67   DECL_VARIABLE(vector2, int, 8, 16);
68   DECL_VARIABLE(vector2, int, 16, 8);
69   DECL_VARIABLE(vector2, int, 32, 4);
70   DECL_VARIABLE(vector2, uint, 8, 16);
71   DECL_VARIABLE(vector2, uint, 16, 8);
72   DECL_VARIABLE(vector2, uint, 32, 4);
73   DECL_VARIABLE(vector2, float, 32, 4);
74
75   DECL_VARIABLE(vector_res, uint, 8, 8);
76   DECL_VARIABLE(vector_res, uint, 16, 4);
77   DECL_VARIABLE(vector_res, uint, 32, 2);
78   DECL_VARIABLE(vector_res, uint, 8, 16);
79   DECL_VARIABLE(vector_res, uint, 16, 8);
80   DECL_VARIABLE(vector_res, uint, 32, 4);
81
82   clean_results ();
83
84   /* There is no 64 bits variant, don't use the generic initializer.  */
85   VLOAD(vector, buffer, , int, s, 8, 8);
86   VLOAD(vector, buffer, , int, s, 16, 4);
87   VLOAD(vector, buffer, , int, s, 32, 2);
88   VLOAD(vector, buffer, , uint, u, 8, 8);
89   VLOAD(vector, buffer, , uint, u, 16, 4);
90   VLOAD(vector, buffer, , uint, u, 32, 2);
91   VLOAD(vector, buffer, , float, f, 32, 2);
92
93   VLOAD(vector, buffer, q, int, s, 8, 16);
94   VLOAD(vector, buffer, q, int, s, 16, 8);
95   VLOAD(vector, buffer, q, int, s, 32, 4);
96   VLOAD(vector, buffer, q, uint, u, 8, 16);
97   VLOAD(vector, buffer, q, uint, u, 16, 8);
98   VLOAD(vector, buffer, q, uint, u, 32, 4);
99   VLOAD(vector, buffer, q, float, f, 32, 4);
100
101   /* Choose init value arbitrarily, will be used for vector
102      comparison.  */
103   VDUP(vector2, , int, s, 8, 8, -10);
104   VDUP(vector2, , int, s, 16, 4, -14);
105   VDUP(vector2, , int, s, 32, 2, -16);
106   VDUP(vector2, , uint, u, 8, 8, 0xF3);
107   VDUP(vector2, , uint, u, 16, 4, 0xFFF2);
108   VDUP(vector2, , uint, u, 32, 2, 0xFFFFFFF1);
109   VDUP(vector2, , float, f, 32, 2, -15.0f);
110
111   VDUP(vector2, q, int, s, 8, 16, -4);
112   VDUP(vector2, q, int, s, 16, 8, -10);
113   VDUP(vector2, q, int, s, 32, 4, -14);
114   VDUP(vector2, q, uint, u, 8, 16, 0xF4);
115   VDUP(vector2, q, uint, u, 16, 8, 0xFFF6);
116   VDUP(vector2, q, uint, u, 32, 4, 0xFFFFFFF2);
117   VDUP(vector2, q, float, f, 32, 4, -14.0f);
118
119   /* The comparison operators produce only unsigned results, which
120      means that our tests with uint* inputs write their results in the
121      same vectors as the int* variants. As a consequence, we have to
122      execute and test the int* first, then the uint* ones.
123      Same thing for float and poly8.
124   */
125
126   /* Apply operator named INSN_NAME.  */
127   TEST_VCOMP(INSN_NAME, , int, s, uint, 8, 8);
128   TEST_VCOMP(INSN_NAME, , int, s, uint, 16, 4);
129   TEST_VCOMP(INSN_NAME, , int, s, uint, 32, 2);
130   TEST_VCOMP(INSN_NAME, q, int, s, uint, 8, 16);
131   TEST_VCOMP(INSN_NAME, q, int, s, uint, 16, 8);
132   TEST_VCOMP(INSN_NAME, q, int, s, uint, 32, 4);
133
134   CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected, "");
135   CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected, "");
136   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected, "");
137   CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected, "");
138   CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected, "");
139   CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected, "");
140
141   /* Now the uint* variants.  */
142   TEST_VCOMP(INSN_NAME, , uint, u, uint, 8, 8);
143   TEST_VCOMP(INSN_NAME, , uint, u, uint, 16, 4);
144   TEST_VCOMP(INSN_NAME, , uint, u, uint, 32, 2);
145   TEST_VCOMP(INSN_NAME, q, uint, u, uint, 8, 16);
146   TEST_VCOMP(INSN_NAME, q, uint, u, uint, 16, 8);
147   TEST_VCOMP(INSN_NAME, q, uint, u, uint, 32, 4);
148
149   CHECK(TEST_MSG, uint, 8, 8, PRIx8, expected_uint, "");
150   CHECK(TEST_MSG, uint, 16, 4, PRIx16, expected_uint, "");
151   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_uint, "");
152   CHECK(TEST_MSG, uint, 8, 16, PRIx8, expected_q_uint, "");
153   CHECK(TEST_MSG, uint, 16, 8, PRIx16, expected_q_uint, "");
154   CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_q_uint, "");
155
156   /* The float variants.  */
157   TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
158   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_float, "");
159
160   TEST_VCOMP(INSN_NAME, q, float, f, uint, 32, 4);
161   CHECK(TEST_MSG, uint, 32, 4, PRIx32, expected_q_float, "");
162
163   /* Some "special" input values to test some corner cases.  */
164   /* Extra tests to have 100% coverage on all the variants.  */
165   VDUP(vector2, , uint, u, 32, 2, 0xFFFFFFF0);
166   TEST_VCOMP(INSN_NAME, , uint, u, uint, 32, 2);
167   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_uint2, "uint 0xfffffff0");
168
169   VDUP(vector2, , int, s, 32, 2, -15);
170   TEST_VCOMP(INSN_NAME, , int, s, uint, 32, 2);
171   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_uint3, "int -15");
172
173   VDUP(vector2, , float, f, 32, 2, -16.0f);
174   TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
175   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_uint4, "float -16.0f");
176
177
178   /* Extra FP tests with special values (NaN, ....).  */
179   VDUP(vector, , float, f, 32, 2, 1.0);
180   VDUP(vector2, , float, f, 32, 2, NAN);
181   TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
182   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_nan, "FP special (NaN)");
183
184   VDUP(vector, , float, f, 32, 2, 1.0);
185   VDUP(vector2, , float, f, 32, 2, -NAN);
186   TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
187   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_mnan, " FP special (-NaN)");
188
189   VDUP(vector, , float, f, 32, 2, NAN);
190   VDUP(vector2, , float, f, 32, 2, 1.0);
191   TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
192   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_nan2, " FP special (NaN)");
193
194   VDUP(vector, , float, f, 32, 2, 1.0);
195   VDUP(vector2, , float, f, 32, 2, HUGE_VALF);
196   TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
197   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_inf, " FP special (inf)");
198
199   VDUP(vector, , float, f, 32, 2, 1.0);
200   VDUP(vector2, , float, f, 32, 2, -HUGE_VALF);
201   TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
202   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_minf, " FP special (-inf)");
203
204   VDUP(vector, , float, f, 32, 2, HUGE_VALF);
205   VDUP(vector2, , float, f, 32, 2, 1.0);
206   TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
207   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_inf2, " FP special (inf)");
208
209   VDUP(vector, , float, f, 32, 2, -0.0);
210   VDUP(vector2, , float, f, 32, 2, 0.0);
211   TEST_VCOMP(INSN_NAME, , float, f, uint, 32, 2);
212   CHECK(TEST_MSG, uint, 32, 2, PRIx32, expected_mzero, " FP special (-0.0)");
213
214 #ifdef EXTRA_TESTS
215   EXTRA_TESTS();
216 #endif
217 }
218
219 int main (void)
220 {
221   FNNAME (INSN_NAME) ();
222
223   return 0;
224 }