1 /* Test vreinterpret_f64_* and vreinterpret_*_f64 intrinsics work correctly. */
2 /* { dg-do run } */
3 /* { dg-options "-O3" } */
4
5 #include <arm_neon.h>
6
7 extern void abort (void);
8
9 #define ABS(a) __builtin_fabs (a)
10 #define ISNAN(a) __builtin_isnan (a)
11
12 #define DOUBLE_EQUALS(a, b, epsilon) \
13 ( \
14 ((a) == (b)) \
15 || (ISNAN (a) && ISNAN (b)) \
16 || (ABS (a - b) < epsilon) \
17 )
18
19 /* Pi accurate up to 16 digits.
20 Further digits are a closest binary approximation. */
21 #define PI_F64 3.14159265358979311599796346854
22 /* Hex representation in Double (IEEE754 Double precision 64-bit) is:
23 0x400921FB54442D18. */
24
25 /* E accurate up to 16 digits.
26 Further digits are a closest binary approximation. */
27 #define E_F64 2.71828182845904509079559829843
28 /* Hex representation in Double (IEEE754 Double precision 64-bit) is:
29 0x4005BF0A8B145769. */
30
31 float32x2_t __attribute__ ((noinline))
wrap_vreinterpret_f32_f64(float64x1_t __a)32 wrap_vreinterpret_f32_f64 (float64x1_t __a)
33 {
34 return vreinterpret_f32_f64 (__a);
35 }
36
37 int __attribute__ ((noinline))
test_vreinterpret_f32_f64()38 test_vreinterpret_f32_f64 ()
39 {
40 float64x1_t a;
41 float32x2_t b;
42 float64_t c[1] = { PI_F64 };
43 /* Values { 0x54442D18, 0x400921FB } reinterpreted as f32. */
44 float32_t d[2] = { 3.3702805504E12, 2.1426990032196044921875E0 };
45 float32_t e[2];
46 int i;
47
48 a = vld1_f64 (c);
49 b = wrap_vreinterpret_f32_f64 (a);
50 vst1_f32 (e, b);
51 for (i = 0; i < 2; i++)
52 if (!DOUBLE_EQUALS (d[i], e[i], __FLT_EPSILON__))
53 return 1;
54 return 0;
55 };
56
57 int8x8_t __attribute__ ((noinline))
wrap_vreinterpret_s8_f64(float64x1_t __a)58 wrap_vreinterpret_s8_f64 (float64x1_t __a)
59 {
60 return vreinterpret_s8_f64 (__a);
61 }
62
63 int __attribute__ ((noinline))
test_vreinterpret_s8_f64()64 test_vreinterpret_s8_f64 ()
65 {
66 float64x1_t a;
67 int8x8_t b;
68 float64_t c[1] = { PI_F64 };
69 int8_t d[8] = { 0x18, 0x2D, 0x44, 0x54, 0xFB, 0x21, 0x09, 0x40 };
70 int8_t e[8];
71 int i;
72
73 a = vld1_f64 (c);
74 b = wrap_vreinterpret_s8_f64 (a);
75 vst1_s8 (e, b);
76 for (i = 0; i < 8; i++)
77 if (d[i] != e[i])
78 return 1;
79 return 0;
80 };
81
82 int16x4_t __attribute__ ((noinline))
wrap_vreinterpret_s16_f64(float64x1_t __a)83 wrap_vreinterpret_s16_f64 (float64x1_t __a)
84 {
85 return vreinterpret_s16_f64 (__a);
86 }
87
88 int __attribute__ ((noinline))
test_vreinterpret_s16_f64()89 test_vreinterpret_s16_f64 ()
90 {
91 float64x1_t a;
92 int16x4_t b;
93 float64_t c[1] = { PI_F64 };
94 int16_t d[4] = { 0x2D18, 0x5444, 0x21FB, 0x4009 };
95 int16_t e[4];
96 int i;
97
98 a = vld1_f64 (c);
99 b = wrap_vreinterpret_s16_f64 (a);
100 vst1_s16 (e, b);
101 for (i = 0; i < 4; i++)
102 if (d[i] != e[i])
103 return 1;
104 return 0;
105 };
106
107 int32x2_t __attribute__ ((noinline))
wrap_vreinterpret_s32_f64(float64x1_t __a)108 wrap_vreinterpret_s32_f64 (float64x1_t __a)
109 {
110 return vreinterpret_s32_f64 (__a);
111 }
112
113 int __attribute__ ((noinline))
test_vreinterpret_s32_f64()114 test_vreinterpret_s32_f64 ()
115 {
116 float64x1_t a;
117 int32x2_t b;
118 float64_t c[1] = { PI_F64 };
119 int32_t d[2] = { 0x54442D18, 0x400921FB };
120 int32_t e[2];
121 int i;
122
123 a = vld1_f64 (c);
124 b = wrap_vreinterpret_s32_f64 (a);
125 vst1_s32 (e, b);
126 for (i = 0; i < 2; i++)
127 if (d[i] != e[i])
128 return 1;
129 return 0;
130 };
131
132 int64x1_t __attribute__ ((noinline))
wrap_vreinterpret_s64_f64(float64x1_t __a)133 wrap_vreinterpret_s64_f64 (float64x1_t __a)
134 {
135 return vreinterpret_s64_f64 (__a);
136 }
137
138 int __attribute__ ((noinline))
test_vreinterpret_s64_f64()139 test_vreinterpret_s64_f64 ()
140 {
141 float64x1_t a;
142 int64x1_t b;
143 float64_t c[1] = { PI_F64 };
144 int64_t d[1] = { 0x400921FB54442D18 };
145 int64_t e[1];
146 int i;
147
148 a = vld1_f64 (c);
149 b = wrap_vreinterpret_s64_f64 (a);
150 vst1_s64 (e, b);
151 if (d[0] != e[0])
152 return 1;
153 return 0;
154 };
155
156 float32x4_t __attribute__ ((noinline))
wrap_vreinterpretq_f32_f64(float64x2_t __a)157 wrap_vreinterpretq_f32_f64 (float64x2_t __a)
158 {
159 return vreinterpretq_f32_f64 (__a);
160 }
161
162 int __attribute__ ((noinline))
test_vreinterpretq_f32_f64()163 test_vreinterpretq_f32_f64 ()
164 {
165 float64x2_t a;
166 float32x4_t b;
167 float64_t c[2] = { PI_F64, E_F64 };
168
169 /* Values corresponding to f32 reinterpret of
170 { 0x54442D18, 0x400921FB, 0x8B145769, 0x4005BF0A }. */
171 float32_t d[4] = { 3.3702805504E12,
172 2.1426990032196044921875E0,
173 -2.8569523269651966444143014594E-32,
174 2.089785099029541015625E0 };
175 float32_t e[4];
176 int i;
177
178 a = vld1q_f64 (c);
179 b = wrap_vreinterpretq_f32_f64 (a);
180 vst1q_f32 (e, b);
181 for (i = 0; i < 4; i++)
182 {
183 if (!DOUBLE_EQUALS (d[i], e[i], __FLT_EPSILON__))
184 return 1;
185 }
186 return 0;
187 };
188
189 int8x16_t __attribute__ ((noinline))
wrap_vreinterpretq_s8_f64(float64x2_t __a)190 wrap_vreinterpretq_s8_f64 (float64x2_t __a)
191 {
192 return vreinterpretq_s8_f64 (__a);
193 }
194
195 int __attribute__ ((noinline))
test_vreinterpretq_s8_f64()196 test_vreinterpretq_s8_f64 ()
197 {
198 float64x2_t a;
199 int8x16_t b;
200 float64_t c[2] = { PI_F64, E_F64 };
201 int8_t d[16] = { 0x18, 0x2D, 0x44, 0x54, 0xFB, 0x21, 0x09, 0x40,
202 0x69, 0x57, 0x14, 0x8B, 0x0A, 0xBF, 0x05, 0x40 };
203 int8_t e[16];
204 int i;
205
206 a = vld1q_f64 (c);
207 b = wrap_vreinterpretq_s8_f64 (a);
208 vst1q_s8 (e, b);
209 for (i = 0; i < 16; i++)
210 if (d[i] != e[i])
211 return 1;
212 return 0;
213 };
214
215 int16x8_t __attribute__ ((noinline))
wrap_vreinterpretq_s16_f64(float64x2_t __a)216 wrap_vreinterpretq_s16_f64 (float64x2_t __a)
217 {
218 return vreinterpretq_s16_f64 (__a);
219 }
220
221 int __attribute__ ((noinline))
test_vreinterpretq_s16_f64()222 test_vreinterpretq_s16_f64 ()
223 {
224 float64x2_t a;
225 int16x8_t b;
226 float64_t c[2] = { PI_F64, E_F64 };
227 int16_t d[8] = { 0x2D18, 0x5444, 0x21FB, 0x4009,
228 0x5769, 0x8B14, 0xBF0A, 0x4005 };
229 int16_t e[8];
230 int i;
231
232 a = vld1q_f64 (c);
233 b = wrap_vreinterpretq_s16_f64 (a);
234 vst1q_s16 (e, b);
235 for (i = 0; i < 8; i++)
236 if (d[i] != e[i])
237 return 1;
238 return 0;
239 };
240
241 int32x4_t __attribute__ ((noinline))
wrap_vreinterpretq_s32_f64(float64x2_t __a)242 wrap_vreinterpretq_s32_f64 (float64x2_t __a)
243 {
244 return vreinterpretq_s32_f64 (__a);
245 }
246
247 int __attribute__ ((noinline))
test_vreinterpretq_s32_f64()248 test_vreinterpretq_s32_f64 ()
249 {
250 float64x2_t a;
251 int32x4_t b;
252 float64_t c[2] = { PI_F64, E_F64 };
253 int32_t d[4] = { 0x54442D18, 0x400921FB, 0x8B145769, 0x4005BF0A };
254 int32_t e[4];
255 int i;
256
257 a = vld1q_f64 (c);
258 b = wrap_vreinterpretq_s32_f64 (a);
259 vst1q_s32 (e, b);
260 for (i = 0; i < 4; i++)
261 if (d[i] != e[i])
262 return 1;
263 return 0;
264 };
265
266 int64x2_t __attribute__ ((noinline))
wrap_vreinterpretq_s64_f64(float64x2_t __a)267 wrap_vreinterpretq_s64_f64 (float64x2_t __a)
268 {
269 return vreinterpretq_s64_f64 (__a);
270 }
271
272 int __attribute__ ((noinline))
test_vreinterpretq_s64_f64()273 test_vreinterpretq_s64_f64 ()
274 {
275 float64x2_t a;
276 int64x2_t b;
277 float64_t c[2] = { PI_F64, E_F64 };
278 int64_t d[2] = { 0x400921FB54442D18, 0x4005BF0A8B145769 };
279 int64_t e[2];
280 int i;
281
282 a = vld1q_f64 (c);
283 b = wrap_vreinterpretq_s64_f64 (a);
284 vst1q_s64 (e, b);
285 for (i = 0; i < 2; i++)
286 if (d[i] != e[i])
287 return 1;
288 return 0;
289 };
290
291 float64x1_t __attribute__ ((noinline))
wrap_vreinterpret_f64_f32(float32x2_t __a)292 wrap_vreinterpret_f64_f32 (float32x2_t __a)
293 {
294 return vreinterpret_f64_f32 (__a);
295 }
296
297 int __attribute__ ((noinline))
test_vreinterpret_f64_f32()298 test_vreinterpret_f64_f32 ()
299 {
300 float32x2_t a;
301 float64x1_t b;
302 /* Values { 0x54442D18, 0x400921FB } reinterpreted as f32. */
303 float32_t c[2] = { 3.3702805504E12, 2.1426990032196044921875E0 };
304 float64_t d[1] = { PI_F64 };
305 float64_t e[1];
306 int i;
307
308 a = vld1_f32 (c);
309 b = wrap_vreinterpret_f64_f32 (a);
310 vst1_f64 (e, b);
311 if (!DOUBLE_EQUALS (d[0], e[0], __DBL_EPSILON__))
312 return 1;
313 return 0;
314 };
315
316 float64x1_t __attribute__ ((noinline))
wrap_vreinterpret_f64_s8(int8x8_t __a)317 wrap_vreinterpret_f64_s8 (int8x8_t __a)
318 {
319 return vreinterpret_f64_s8 (__a);
320 }
321
322 int __attribute__ ((noinline))
test_vreinterpret_f64_s8()323 test_vreinterpret_f64_s8 ()
324 {
325 int8x8_t a;
326 float64x1_t b;
327 int8_t c[8] = { 0x18, 0x2D, 0x44, 0x54, 0xFB, 0x21, 0x09, 0x40 };
328 float64_t d[1] = { PI_F64 };
329 float64_t e[1];
330 int i;
331
332 a = vld1_s8 (c);
333 b = wrap_vreinterpret_f64_s8 (a);
334 vst1_f64 (e, b);
335 if (!DOUBLE_EQUALS (d[0], e[0], __DBL_EPSILON__))
336 return 1;
337 return 0;
338 };
339
340 float64x1_t __attribute__ ((noinline))
wrap_vreinterpret_f64_s16(int16x4_t __a)341 wrap_vreinterpret_f64_s16 (int16x4_t __a)
342 {
343 return vreinterpret_f64_s16 (__a);
344 }
345
346 int __attribute__ ((noinline))
test_vreinterpret_f64_s16()347 test_vreinterpret_f64_s16 ()
348 {
349 int16x4_t a;
350 float64x1_t b;
351 int16_t c[4] = { 0x2D18, 0x5444, 0x21FB, 0x4009 };
352 float64_t d[1] = { PI_F64 };
353 float64_t e[1];
354 int i;
355
356 a = vld1_s16 (c);
357 b = wrap_vreinterpret_f64_s16 (a);
358 vst1_f64 (e, b);
359 if (!DOUBLE_EQUALS (d[0], e[0], __DBL_EPSILON__))
360 return 1;
361 return 0;
362 };
363
364 float64x1_t __attribute__ ((noinline))
wrap_vreinterpret_f64_s32(int32x2_t __a)365 wrap_vreinterpret_f64_s32 (int32x2_t __a)
366 {
367 return vreinterpret_f64_s32 (__a);
368 }
369
370 int __attribute__ ((noinline))
test_vreinterpret_f64_s32()371 test_vreinterpret_f64_s32 ()
372 {
373 int32x2_t a;
374 float64x1_t b;
375 int32_t c[2] = { 0x54442D18, 0x400921FB };
376 float64_t d[1] = { PI_F64 };
377 float64_t e[1];
378 int i;
379
380 a = vld1_s32 (c);
381 b = wrap_vreinterpret_f64_s32 (a);
382 vst1_f64 (e, b);
383 if (!DOUBLE_EQUALS (d[0], e[0], __DBL_EPSILON__))
384 return 1;
385 return 0;
386 };
387
388 float64x1_t __attribute__ ((noinline))
wrap_vreinterpret_f64_s64(int64x1_t __a)389 wrap_vreinterpret_f64_s64 (int64x1_t __a)
390 {
391 return vreinterpret_f64_s64 (__a);
392 }
393
394 int __attribute__ ((noinline))
test_vreinterpret_f64_s64()395 test_vreinterpret_f64_s64 ()
396 {
397 int64x1_t a;
398 float64x1_t b;
399 int64_t c[1] = { 0x400921FB54442D18 };
400 float64_t d[1] = { PI_F64 };
401 float64_t e[1];
402
403 a = vld1_s64 (c);
404 b = wrap_vreinterpret_f64_s64 (a);
405 vst1_f64 (e, b);
406 if (!DOUBLE_EQUALS (d[0], e[0], __DBL_EPSILON__))
407 return 1;
408 return 0;
409 };
410
411 float64x2_t __attribute__ ((noinline))
wrap_vreinterpretq_f64_f32(float32x4_t __a)412 wrap_vreinterpretq_f64_f32 (float32x4_t __a)
413 {
414 return vreinterpretq_f64_f32 (__a);
415 }
416
417 int __attribute__ ((noinline))
test_vreinterpretq_f64_f32()418 test_vreinterpretq_f64_f32 ()
419 {
420 float32x4_t a;
421 float64x2_t b;
422 /* Values corresponding to f32 reinterpret of
423 { 0x54442D18, 0x400921FB, 0x8B145769, 0x4005BF0A }. */
424 float32_t c[4] = { 3.3702805504E12,
425 2.1426990032196044921875E0,
426 -2.8569523269651966444143014594E-32,
427 2.089785099029541015625E0 };
428
429 float64_t d[2] = { PI_F64, E_F64 };
430 float64_t e[2];
431 int i;
432
433 a = vld1q_f32 (c);
434 b = wrap_vreinterpretq_f64_f32 (a);
435 vst1q_f64 (e, b);
436 for (i = 0; i < 2; i++)
437 if (!DOUBLE_EQUALS (d[i], e[i], __DBL_EPSILON__))
438 return 1;
439 return 0;
440 };
441
442 float64x2_t __attribute__ ((noinline))
wrap_vreinterpretq_f64_s8(int8x16_t __a)443 wrap_vreinterpretq_f64_s8 (int8x16_t __a)
444 {
445 return vreinterpretq_f64_s8 (__a);
446 }
447
448 int __attribute__ ((noinline))
test_vreinterpretq_f64_s8()449 test_vreinterpretq_f64_s8 ()
450 {
451 int8x16_t a;
452 float64x2_t b;
453 int8_t c[16] = { 0x18, 0x2D, 0x44, 0x54, 0xFB, 0x21, 0x09, 0x40,
454 0x69, 0x57, 0x14, 0x8B, 0x0A, 0xBF, 0x05, 0x40 };
455 float64_t d[2] = { PI_F64, E_F64 };
456 float64_t e[2];
457 int i;
458
459 a = vld1q_s8 (c);
460 b = wrap_vreinterpretq_f64_s8 (a);
461 vst1q_f64 (e, b);
462 for (i = 0; i < 2; i++)
463 if (!DOUBLE_EQUALS (d[i], e[i], __DBL_EPSILON__))
464 return 1;
465 return 0;
466 };
467
468 float64x2_t __attribute__ ((noinline))
wrap_vreinterpretq_f64_s16(int16x8_t __a)469 wrap_vreinterpretq_f64_s16 (int16x8_t __a)
470 {
471 return vreinterpretq_f64_s16 (__a);
472 }
473
474 int __attribute__ ((noinline))
test_vreinterpretq_f64_s16()475 test_vreinterpretq_f64_s16 ()
476 {
477 int16x8_t a;
478 float64x2_t b;
479 int16_t c[8] = { 0x2D18, 0x5444, 0x21FB, 0x4009,
480 0x5769, 0x8B14, 0xBF0A, 0x4005 };
481 float64_t d[2] = { PI_F64, E_F64 };
482 float64_t e[2];
483 int i;
484
485 a = vld1q_s16 (c);
486 b = wrap_vreinterpretq_f64_s16 (a);
487 vst1q_f64 (e, b);
488 for (i = 0; i < 2; i++)
489 if (!DOUBLE_EQUALS (d[i], e[i], __DBL_EPSILON__))
490 return 1;
491 return 0;
492 };
493
494 float64x2_t __attribute__ ((noinline))
wrap_vreinterpretq_f64_s32(int32x4_t __a)495 wrap_vreinterpretq_f64_s32 (int32x4_t __a)
496 {
497 return vreinterpretq_f64_s32 (__a);
498 }
499
500 int __attribute__ ((noinline))
test_vreinterpretq_f64_s32()501 test_vreinterpretq_f64_s32 ()
502 {
503 int32x4_t a;
504 float64x2_t b;
505 int32_t c[4] = { 0x54442D18, 0x400921FB, 0x8B145769, 0x4005BF0A };
506 float64_t d[2] = { PI_F64, E_F64 };
507 float64_t e[2];
508 int i;
509
510 a = vld1q_s32 (c);
511 b = wrap_vreinterpretq_f64_s32 (a);
512 vst1q_f64 (e, b);
513 for (i = 0; i < 2; i++)
514 if (!DOUBLE_EQUALS (d[i], e[i], __DBL_EPSILON__))
515 return 1;
516 return 0;
517 };
518
519 float64x2_t __attribute__ ((noinline))
wrap_vreinterpretq_f64_s64(int64x2_t __a)520 wrap_vreinterpretq_f64_s64 (int64x2_t __a)
521 {
522 return vreinterpretq_f64_s64 (__a);
523 }
524
525 int __attribute__ ((noinline))
test_vreinterpretq_f64_s64()526 test_vreinterpretq_f64_s64 ()
527 {
528 int64x2_t a;
529 float64x2_t b;
530 int64_t c[2] = { 0x400921FB54442D18, 0x4005BF0A8B145769 };
531 float64_t d[2] = { PI_F64, E_F64 };
532 float64_t e[2];
533 int i;
534
535 a = vld1q_s64 (c);
536 b = wrap_vreinterpretq_f64_s64 (a);
537 vst1q_f64 (e, b);
538 for (i = 0; i < 2; i++)
539 if (!DOUBLE_EQUALS (d[i], e[i], __DBL_EPSILON__))
540 return 1;
541 return 0;
542 };
543
544 int
main(int argc,char ** argv)545 main (int argc, char **argv)
546 {
547 if (test_vreinterpret_f32_f64 ())
548 abort ();
549
550 if (test_vreinterpret_s8_f64 ())
551 abort ();
552 if (test_vreinterpret_s16_f64 ())
553 abort ();
554 if (test_vreinterpret_s32_f64 ())
555 abort ();
556 if (test_vreinterpret_s64_f64 ())
557 abort ();
558
559 if (test_vreinterpretq_f32_f64 ())
560 abort ();
561
562 if (test_vreinterpretq_s8_f64 ())
563 abort ();
564 if (test_vreinterpretq_s16_f64 ())
565 abort ();
566 if (test_vreinterpretq_s32_f64 ())
567 abort ();
568 if (test_vreinterpretq_s64_f64 ())
569 abort ();
570
571 if (test_vreinterpret_f64_f32 ())
572 abort ();
573
574 if (test_vreinterpret_f64_s8 ())
575 abort ();
576 if (test_vreinterpret_f64_s16 ())
577 abort ();
578 if (test_vreinterpret_f64_s32 ())
579 abort ();
580 if (test_vreinterpret_f64_s64 ())
581 abort ();
582
583 if (test_vreinterpretq_f64_f32 ())
584 abort ();
585
586 if (test_vreinterpretq_f64_s8 ())
587 abort ();
588 if (test_vreinterpretq_f64_s16 ())
589 abort ();
590 if (test_vreinterpretq_f64_s32 ())
591 abort ();
592 if (test_vreinterpretq_f64_s64 ())
593 abort ();
594
595 return 0;
596 }
597