1 /* Test vdiv works correctly. */
2 /* { dg-do run } */
3 /* { dg-options "-O3 --save-temps" } */
4
5 #include <arm_neon.h>
6
7 #define FLT_INFINITY (__builtin_inff ())
8 #define DBL_INFINITY (__builtin_inf ())
9
10 #define NAN (0.0 / 0.0)
11
12 #define PI 3.141592653589793
13 #define PI_4 0.7853981633974483
14 #define SQRT2 1.4142135623730951
15 #define SQRT1_2 0.7071067811865475
16
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
42
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
63
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
85
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)
93
94 #define DATA_TYPE_32 float
95 #define DATA_TYPE_64 double
96 #define DATA_TYPE(data_len) DATA_TYPE_##data_len
97
98 #define EPSILON_32 __FLT_EPSILON__
99 #define EPSILON_64 __DBL_EPSILON__
100 #define EPSILON(data_len) EPSILON_##data_len
101
102 #define INDEX64_32 [i]
103 #define INDEX64_64
104 #define INDEX128_32 [i]
105 #define INDEX128_64 [i]
106 #define INDEX(reg_len, data_len) \
107 CONCAT1 (INDEX, reg_len##_##data_len)
108
109 #define LOAD_INST(reg_len, data_len) \
110 CONCAT1 (vld1, POSTFIX (reg_len, data_len))
111 #define DIV_INST(reg_len, data_len) \
112 CONCAT1 (vdiv, POSTFIX (reg_len, data_len))
113
114 #define ABS(a) __builtin_fabs (a)
115 #define ISNAN(a) __builtin_isnan (a)
116 #define FP_equals(a, b, epsilon) \
117 ( \
118 ((a) == (b)) \
119 || (ISNAN (a) && ISNAN (b)) \
120 || (ABS (a - b) < epsilon) \
121 )
122
123 #define INHIB_OPTIMIZATION asm volatile ("" : : : "memory")
124
125 #define RUN_TEST(a, b, c, testseta, testsetb, answset, count, \
126 reg_len, data_len, n) \
127 { \
128 int i; \
129 INHIB_OPTIMIZATION; \
130 (a) = LOAD_INST (reg_len, data_len) (testseta[count]); \
131 (b) = LOAD_INST (reg_len, data_len) (testsetb[count]); \
132 (c) = LOAD_INST (reg_len, data_len) (answset[count]); \
133 INHIB_OPTIMIZATION; \
134 (a) = DIV_INST (reg_len, data_len) (a, b); \
135 for (i = 0; i < n; i++) \
136 { \
137 INHIB_OPTIMIZATION; \
138 if (!FP_equals ((a) INDEX (reg_len, data_len), \
139 (c) INDEX (reg_len, data_len), \
140 EPSILON (data_len))) \
141 return 1; \
142 } \
143 }
144
145 extern void abort (void);
146
147 #define TESTA8 TESTA8_FLT
148 #define ANSW8 ANSW8_FLT
149 #define INFINITY FLT_INFINITY
150
151 int
test_vdiv_f32()152 test_vdiv_f32 ()
153 {
154 int count;
155 float32x2_t a;
156 float32x2_t b;
157 float32x2_t c;
158
159 float32_t testseta[10][2] = {
160 { TESTA0, TESTA1 }, { TESTA2, TESTA3 },
161 { TESTA4, TESTA5 }, { TESTA6, TESTA7 },
162 { TESTA8, TESTA9 }, { TESTA10, TESTA11 },
163 { TESTA12, TESTA13 }, { TESTA14, TESTA15 },
164 { TESTA16, TESTA17 }, { TESTA18, TESTA19 }
165 };
166
167 float32_t testsetb[10][2] = {
168 { TESTB0, TESTB1 }, { TESTB2, TESTB3 },
169 { TESTB4, TESTB5 }, { TESTB6, TESTB7 },
170 { TESTB8, TESTB9 }, { TESTB10, TESTB11 },
171 { TESTB12, TESTB13 }, { TESTB14, TESTB15 },
172 { TESTB16, TESTB17 }, { TESTB18, TESTB19 }
173 };
174
175 float32_t answset[10][2] = {
176 { ANSW0, ANSW1 }, { ANSW2, ANSW3 },
177 { ANSW4, ANSW5 }, { ANSW6, ANSW7 },
178 { ANSW8, ANSW9 }, { ANSW10, ANSW11 },
179 { ANSW12, ANSW13 }, { ANSW14, ANSW15 },
180 { ANSW16, ANSW17 }, { ANSW18, ANSW19 }
181 };
182
183 for (count = 0; count < 10; count++)
184 {
185 RUN_TEST (a, b, c, testseta, testsetb, answset, count, 64, 32, 2);
186 }
187
188 return 0;
189 }
190
191 /* { dg-final { scan-assembler-times "fdiv\\tv\[0-9\]+\.2s, v\[0-9\]+\.2s, v\[0-9\]+\.2s" 1 } } */
192
193 #undef TESTA8
194 #undef ANSW8
195 #undef INFINITY
196
197 #define TESTA8 TESTA8_DBL
198 #define ANSW8 ANSW8_DBL
199 #define INFINITY DBL_INFINITY
200
201 int
test_vdiv_f64()202 test_vdiv_f64 ()
203 {
204 int count;
205 float64x1_t a;
206 float64x1_t b;
207 float64x1_t c;
208
209 float64_t testseta[20][1] = {
210 { TESTA0 }, { TESTA1 }, { TESTA2 }, { TESTA3 },
211 { TESTA4 }, { TESTA5 }, { TESTA6 }, { TESTA7 },
212 { TESTA8 }, { TESTA9 }, { TESTA10 }, { TESTA11 },
213 { TESTA12 }, { TESTA13 }, { TESTA14 }, { TESTA15 },
214 { TESTA16 }, { TESTA17 }, { TESTA18 }, { TESTA19 }
215 };
216
217 float64_t testsetb[20][1] = {
218 { TESTB0 }, { TESTB1 }, { TESTB2 }, { TESTB3 },
219 { TESTB4 }, { TESTB5 }, { TESTB6 }, { TESTB7 },
220 { TESTB8 }, { TESTB9 }, { TESTB10 }, { TESTB11 },
221 { TESTB12 }, { TESTB13 }, { TESTB14 }, { TESTB15 },
222 { TESTB16 }, { TESTB17 }, { TESTB18 }, { TESTB19 }
223 };
224
225 float64_t answset[20][1] = {
226 { ANSW0 }, { ANSW1 }, { ANSW2 }, { ANSW3 },
227 { ANSW4 }, { ANSW5 }, { ANSW6 }, { ANSW7 },
228 { ANSW8 }, { ANSW9 }, { ANSW10 }, { ANSW11 },
229 { ANSW12 }, { ANSW13 }, { ANSW14 }, { ANSW15 },
230 { ANSW16 }, { ANSW17 }, { ANSW18 }, { ANSW19 }
231 };
232
233 for (count = 0; count < 20; count++)
234 {
235 RUN_TEST (a, b, c, testseta, testsetb, answset, count, 64, 64, 1);
236 }
237 return 0;
238 }
239
240 /* The following assembly should match 2 more times,
241 in 64bit NAN generation. */
242 /* { dg-final { scan-assembler-times "fdiv\\td\[0-9\]+, d\[0-9\]+, d\[0-9\]+" 3 } } */
243
244 #undef TESTA8
245 #undef ANSW8
246 #undef INFINITY
247
248 #define TESTA8 TESTA8_FLT
249 #define ANSW8 ANSW8_FLT
250 #define INFINITY FLT_INFINITY
251
252 int
test_vdivq_f32()253 test_vdivq_f32 ()
254 {
255 int count;
256 float32x4_t a;
257 float32x4_t b;
258 float32x4_t c;
259
260 float32_t testseta[5][4] = {
261 { TESTA0, TESTA1, TESTA2, TESTA3 },
262 { TESTA4, TESTA5, TESTA6, TESTA7 },
263 { TESTA8, TESTA9, TESTA10, TESTA11 },
264 { TESTA12, TESTA13, TESTA14, TESTA15 },
265 { TESTA16, TESTA17, TESTA18, TESTA19 }
266 };
267
268 float32_t testsetb[5][4] = {
269 { TESTB0, TESTB1, TESTB2, TESTB3 },
270 { TESTB4, TESTB5, TESTB6, TESTB7 },
271 { TESTB8, TESTB9, TESTB10, TESTB11 },
272 { TESTB12, TESTB13, TESTB14, TESTB15 },
273 { TESTB16, TESTB17, TESTB18, TESTB19 }
274 };
275
276 float32_t answset[5][4] = {
277 { ANSW0, ANSW1, ANSW2, ANSW3 },
278 { ANSW4, ANSW5, ANSW6, ANSW7 },
279 { ANSW8, ANSW9, ANSW10, ANSW11 },
280 { ANSW12, ANSW13, ANSW14, ANSW15 },
281 { ANSW16, ANSW17, ANSW18, ANSW19 }
282 };
283
284 for (count = 0; count < 5; count++)
285 {
286 RUN_TEST (a, b, c, testseta, testsetb, answset, count, 128, 32, 4);
287 }
288 return 0;
289 }
290
291 /* { dg-final { scan-assembler-times "fdiv\\tv\[0-9\]+\.4s, v\[0-9\]+\.4s, v\[0-9\]+\.4s" 1 } } */
292
293 #undef TESTA8
294 #undef ANSW8
295 #undef INFINITY
296
297 #define TESTA8 TESTA8_DBL
298 #define ANSW8 ANSW8_DBL
299 #define INFINITY DBL_INFINITY
300
301 int
test_vdivq_f64()302 test_vdivq_f64 ()
303 {
304 int count;
305 float64x2_t a;
306 float64x2_t b;
307 float64x2_t c;
308
309 float64_t testseta[10][2] = {
310 { TESTA0, TESTA1 }, { TESTA2, TESTA3 },
311 { TESTA4, TESTA5 }, { TESTA6, TESTA7 },
312 { TESTA8, TESTA9 }, { TESTA10, TESTA11 },
313 { TESTA12, TESTA13 }, { TESTA14, TESTA15 },
314 { TESTA16, TESTA17 }, { TESTA18, TESTA19 }
315 };
316
317 float64_t testsetb[10][2] = {
318 { TESTB0, TESTB1 }, { TESTB2, TESTB3 },
319 { TESTB4, TESTB5 }, { TESTB6, TESTB7 },
320 { TESTB8, TESTB9 }, { TESTB10, TESTB11 },
321 { TESTB12, TESTB13 }, { TESTB14, TESTB15 },
322 { TESTB16, TESTB17 }, { TESTB18, TESTB19 }
323 };
324
325 float64_t answset[10][2] = {
326 { ANSW0, ANSW1 }, { ANSW2, ANSW3 },
327 { ANSW4, ANSW5 }, { ANSW6, ANSW7 },
328 { ANSW8, ANSW9 }, { ANSW10, ANSW11 },
329 { ANSW12, ANSW13 }, { ANSW14, ANSW15 },
330 { ANSW16, ANSW17 }, { ANSW18, ANSW19 }
331 };
332
333 for (count = 0; count < 10; count++)
334 {
335 RUN_TEST (a, b, c, testseta, testsetb, answset, count, 128, 64, 2);
336 }
337
338 return 0;
339 }
340
341 /* { dg-final { scan-assembler-times "fdiv\\tv\[0-9\]+\.2d, v\[0-9\]+\.2d, v\[0-9\]+\.2d" 1 } } */
342
343 int
main(int argc,char ** argv)344 main (int argc, char **argv)
345 {
346 if (test_vdiv_f32 ())
347 abort ();
348
349 if (test_vdiv_f64 ())
350 abort ();
351
352 if (test_vdivq_f32 ())
353 abort ();
354
355 if (test_vdivq_f64 ())
356 abort ();
357
358 return 0;
359 }
360
361 /* { dg-final { cleanup-saved-temps } } */
362