Rebase.
[official-gcc.git] / gcc / testsuite / gcc.target / aarch64 / vdiv_f.c
blob9e1b768eda3a88ea37a5da8ffa405e29ec2f2d60
1 /* Test vdiv works correctly. */
2 /* { dg-do run } */
3 /* { dg-options "-O3 --save-temps" } */
5 #include <arm_neon.h>
7 #define FLT_INFINITY (__builtin_inff ())
8 #define DBL_INFINITY (__builtin_inf ())
10 #define NAN (0.0 / 0.0)
12 #define PI 3.141592653589793
13 #define PI_4 0.7853981633974483
14 #define SQRT2 1.4142135623730951
15 #define SQRT1_2 0.7071067811865475
17 #define TESTA0 PI
18 #define TESTA1 -PI
19 #define TESTA2 PI
20 #define TESTA3 -PI
21 #define TESTA4 1.0
22 #define TESTA5 -1.0
23 #define TESTA6 1.0
24 #define TESTA7 -1.0
25 /* 2^25+1, float has 24 significand bits
26 according to Single-precision floating-point format. */
27 #define TESTA8_FLT 33554433
28 /* 2^54+1, double has 53 significand bits
29 according to Double-precision floating-point format. */
30 #define TESTA8_DBL 18014398509481985
31 #define TESTA9 -TESTA8
32 #define TESTA10 TESTA8
33 #define TESTA11 -TESTA8
34 #define TESTA12 NAN
35 #define TESTA13 1.0
36 #define TESTA14 INFINITY
37 #define TESTA15 -INFINITY
38 #define TESTA16 INFINITY
39 #define TESTA17 9.0
40 #define TESTA18 11.0
41 #define TESTA19 13.0
43 #define TESTB0 4.0
44 #define TESTB1 4.0
45 #define TESTB2 -4.0
46 #define TESTB3 -4.0
47 #define TESTB4 SQRT2
48 #define TESTB5 SQRT2
49 #define TESTB6 -SQRT2
50 #define TESTB7 -SQRT2
51 #define TESTB8 2.0
52 #define TESTB9 2.0
53 #define TESTB10 -2.0
54 #define TESTB11 -2.0
55 #define TESTB12 3.0
56 #define TESTB13 NAN
57 #define TESTB14 5.0
58 #define TESTB15 7.0
59 #define TESTB16 INFINITY
60 #define TESTB17 INFINITY
61 #define TESTB18 -INFINITY
62 #define TESTB19 0
64 #define ANSW0 PI_4
65 #define ANSW1 -PI_4
66 #define ANSW2 -PI_4
67 #define ANSW3 PI_4
68 #define ANSW4 SQRT1_2
69 #define ANSW5 -SQRT1_2
70 #define ANSW6 -SQRT1_2
71 #define ANSW7 SQRT1_2
72 #define ANSW8_FLT 16777216
73 #define ANSW8_DBL 9007199254740992
74 #define ANSW9 -ANSW8
75 #define ANSW10 -ANSW8
76 #define ANSW11 ANSW8
77 #define ANSW12 NAN
78 #define ANSW13 NAN
79 #define ANSW14 INFINITY
80 #define ANSW15 -INFINITY
81 #define ANSW16 NAN
82 #define ANSW17 0
83 #define ANSW18 0
84 #define ANSW19 INFINITY
86 #define CONCAT(a, b) a##b
87 #define CONCAT1(a, b) CONCAT (a, b)
88 #define REG_INFEX64 _
89 #define REG_INFEX128 q_
90 #define REG_INFEX(reg_len) REG_INFEX##reg_len
91 #define POSTFIX(reg_len, data_len) \
92 CONCAT1 (REG_INFEX (reg_len), f##data_len)
94 #define DATA_TYPE_32 float
95 #define DATA_TYPE_64 double
96 #define DATA_TYPE(data_len) DATA_TYPE_##data_len
98 #define EPSILON_32 __FLT_EPSILON__
99 #define EPSILON_64 __DBL_EPSILON__
100 #define EPSILON(data_len) EPSILON_##data_len
102 #define LOAD_INST(reg_len, data_len) \
103 CONCAT1 (vld1, POSTFIX (reg_len, data_len))
104 #define DIV_INST(reg_len, data_len) \
105 CONCAT1 (vdiv, POSTFIX (reg_len, data_len))
107 #define ABS(a) __builtin_fabs (a)
108 #define ISNAN(a) __builtin_isnan (a)
109 #define FP_equals(a, b, epsilon) \
111 ((a) == (b)) \
112 || (ISNAN (a) && ISNAN (b)) \
113 || (ABS (a - b) < epsilon) \
116 #define INHIB_OPTIMIZATION asm volatile ("" : : : "memory")
118 #define RUN_TEST(a, b, c, testseta, testsetb, answset, count, \
119 reg_len, data_len, n) \
121 int i; \
122 INHIB_OPTIMIZATION; \
123 (a) = LOAD_INST (reg_len, data_len) (testseta[count]); \
124 (b) = LOAD_INST (reg_len, data_len) (testsetb[count]); \
125 (c) = LOAD_INST (reg_len, data_len) (answset[count]); \
126 INHIB_OPTIMIZATION; \
127 (a) = DIV_INST (reg_len, data_len) (a, b); \
128 for (i = 0; i < n; i++) \
130 INHIB_OPTIMIZATION; \
131 if (!FP_equals ((a) [i], (c) [i], EPSILON (data_len))) \
132 return 1; \
136 extern void abort (void);
138 #define TESTA8 TESTA8_FLT
139 #define ANSW8 ANSW8_FLT
140 #define INFINITY FLT_INFINITY
143 test_vdiv_f32 ()
145 int count;
146 float32x2_t a;
147 float32x2_t b;
148 float32x2_t c;
150 float32_t testseta[10][2] = {
151 { TESTA0, TESTA1 }, { TESTA2, TESTA3 },
152 { TESTA4, TESTA5 }, { TESTA6, TESTA7 },
153 { TESTA8, TESTA9 }, { TESTA10, TESTA11 },
154 { TESTA12, TESTA13 }, { TESTA14, TESTA15 },
155 { TESTA16, TESTA17 }, { TESTA18, TESTA19 }
158 float32_t testsetb[10][2] = {
159 { TESTB0, TESTB1 }, { TESTB2, TESTB3 },
160 { TESTB4, TESTB5 }, { TESTB6, TESTB7 },
161 { TESTB8, TESTB9 }, { TESTB10, TESTB11 },
162 { TESTB12, TESTB13 }, { TESTB14, TESTB15 },
163 { TESTB16, TESTB17 }, { TESTB18, TESTB19 }
166 float32_t answset[10][2] = {
167 { ANSW0, ANSW1 }, { ANSW2, ANSW3 },
168 { ANSW4, ANSW5 }, { ANSW6, ANSW7 },
169 { ANSW8, ANSW9 }, { ANSW10, ANSW11 },
170 { ANSW12, ANSW13 }, { ANSW14, ANSW15 },
171 { ANSW16, ANSW17 }, { ANSW18, ANSW19 }
174 for (count = 0; count < 10; count++)
176 RUN_TEST (a, b, c, testseta, testsetb, answset, count, 64, 32, 2);
179 return 0;
182 /* { dg-final { scan-assembler-times "fdiv\\tv\[0-9\]+\.2s, v\[0-9\]+\.2s, v\[0-9\]+\.2s" 1 } } */
184 #undef TESTA8
185 #undef ANSW8
186 #undef INFINITY
188 #define TESTA8 TESTA8_DBL
189 #define ANSW8 ANSW8_DBL
190 #define INFINITY DBL_INFINITY
193 test_vdiv_f64 ()
195 int count;
196 float64x1_t a;
197 float64x1_t b;
198 float64x1_t c;
200 float64_t testseta[20][1] = {
201 { TESTA0 }, { TESTA1 }, { TESTA2 }, { TESTA3 },
202 { TESTA4 }, { TESTA5 }, { TESTA6 }, { TESTA7 },
203 { TESTA8 }, { TESTA9 }, { TESTA10 }, { TESTA11 },
204 { TESTA12 }, { TESTA13 }, { TESTA14 }, { TESTA15 },
205 { TESTA16 }, { TESTA17 }, { TESTA18 }, { TESTA19 }
208 float64_t testsetb[20][1] = {
209 { TESTB0 }, { TESTB1 }, { TESTB2 }, { TESTB3 },
210 { TESTB4 }, { TESTB5 }, { TESTB6 }, { TESTB7 },
211 { TESTB8 }, { TESTB9 }, { TESTB10 }, { TESTB11 },
212 { TESTB12 }, { TESTB13 }, { TESTB14 }, { TESTB15 },
213 { TESTB16 }, { TESTB17 }, { TESTB18 }, { TESTB19 }
216 float64_t answset[20][1] = {
217 { ANSW0 }, { ANSW1 }, { ANSW2 }, { ANSW3 },
218 { ANSW4 }, { ANSW5 }, { ANSW6 }, { ANSW7 },
219 { ANSW8 }, { ANSW9 }, { ANSW10 }, { ANSW11 },
220 { ANSW12 }, { ANSW13 }, { ANSW14 }, { ANSW15 },
221 { ANSW16 }, { ANSW17 }, { ANSW18 }, { ANSW19 }
224 for (count = 0; count < 20; count++)
226 RUN_TEST (a, b, c, testseta, testsetb, answset, count, 64, 64, 1);
228 return 0;
231 /* The following assembly should match 2 more times,
232 in 64bit NAN generation. */
233 /* { dg-final { scan-assembler-times "fdiv\\td\[0-9\]+, d\[0-9\]+, d\[0-9\]+" 3 } } */
235 #undef TESTA8
236 #undef ANSW8
237 #undef INFINITY
239 #define TESTA8 TESTA8_FLT
240 #define ANSW8 ANSW8_FLT
241 #define INFINITY FLT_INFINITY
244 test_vdivq_f32 ()
246 int count;
247 float32x4_t a;
248 float32x4_t b;
249 float32x4_t c;
251 float32_t testseta[5][4] = {
252 { TESTA0, TESTA1, TESTA2, TESTA3 },
253 { TESTA4, TESTA5, TESTA6, TESTA7 },
254 { TESTA8, TESTA9, TESTA10, TESTA11 },
255 { TESTA12, TESTA13, TESTA14, TESTA15 },
256 { TESTA16, TESTA17, TESTA18, TESTA19 }
259 float32_t testsetb[5][4] = {
260 { TESTB0, TESTB1, TESTB2, TESTB3 },
261 { TESTB4, TESTB5, TESTB6, TESTB7 },
262 { TESTB8, TESTB9, TESTB10, TESTB11 },
263 { TESTB12, TESTB13, TESTB14, TESTB15 },
264 { TESTB16, TESTB17, TESTB18, TESTB19 }
267 float32_t answset[5][4] = {
268 { ANSW0, ANSW1, ANSW2, ANSW3 },
269 { ANSW4, ANSW5, ANSW6, ANSW7 },
270 { ANSW8, ANSW9, ANSW10, ANSW11 },
271 { ANSW12, ANSW13, ANSW14, ANSW15 },
272 { ANSW16, ANSW17, ANSW18, ANSW19 }
275 for (count = 0; count < 5; count++)
277 RUN_TEST (a, b, c, testseta, testsetb, answset, count, 128, 32, 4);
279 return 0;
282 /* { dg-final { scan-assembler-times "fdiv\\tv\[0-9\]+\.4s, v\[0-9\]+\.4s, v\[0-9\]+\.4s" 1 } } */
284 #undef TESTA8
285 #undef ANSW8
286 #undef INFINITY
288 #define TESTA8 TESTA8_DBL
289 #define ANSW8 ANSW8_DBL
290 #define INFINITY DBL_INFINITY
293 test_vdivq_f64 ()
295 int count;
296 float64x2_t a;
297 float64x2_t b;
298 float64x2_t c;
300 float64_t testseta[10][2] = {
301 { TESTA0, TESTA1 }, { TESTA2, TESTA3 },
302 { TESTA4, TESTA5 }, { TESTA6, TESTA7 },
303 { TESTA8, TESTA9 }, { TESTA10, TESTA11 },
304 { TESTA12, TESTA13 }, { TESTA14, TESTA15 },
305 { TESTA16, TESTA17 }, { TESTA18, TESTA19 }
308 float64_t testsetb[10][2] = {
309 { TESTB0, TESTB1 }, { TESTB2, TESTB3 },
310 { TESTB4, TESTB5 }, { TESTB6, TESTB7 },
311 { TESTB8, TESTB9 }, { TESTB10, TESTB11 },
312 { TESTB12, TESTB13 }, { TESTB14, TESTB15 },
313 { TESTB16, TESTB17 }, { TESTB18, TESTB19 }
316 float64_t answset[10][2] = {
317 { ANSW0, ANSW1 }, { ANSW2, ANSW3 },
318 { ANSW4, ANSW5 }, { ANSW6, ANSW7 },
319 { ANSW8, ANSW9 }, { ANSW10, ANSW11 },
320 { ANSW12, ANSW13 }, { ANSW14, ANSW15 },
321 { ANSW16, ANSW17 }, { ANSW18, ANSW19 }
324 for (count = 0; count < 10; count++)
326 RUN_TEST (a, b, c, testseta, testsetb, answset, count, 128, 64, 2);
329 return 0;
332 /* { dg-final { scan-assembler-times "fdiv\\tv\[0-9\]+\.2d, v\[0-9\]+\.2d, v\[0-9\]+\.2d" 1 } } */
335 main (int argc, char **argv)
337 if (test_vdiv_f32 ())
338 abort ();
340 if (test_vdiv_f64 ())
341 abort ();
343 if (test_vdivq_f32 ())
344 abort ();
346 if (test_vdivq_f64 ())
347 abort ();
349 return 0;
352 /* { dg-final { cleanup-saved-temps } } */