Debian Codegraph @

gcc/testsuite/gcc.target/arm/fp16-rounding-alt-1.c

raw
1 /* Test that rounding double to __fp16 happens directly, using an example
2 of a number that would round differently if it went from double to
3 __fp16 via float. */
4
5 /* { dg-do run } */
6 /* { dg-require-effective-target arm_fp16_hw } */
7 /* { dg-require-effective-target arm_fp16_alternative_ok } */
8 /* { dg-options "-std=c99" } */
9 /* { dg-add-options arm_fp16_alternative } */
10
11 #include <stdlib.h>
12
13 /* The original double value. */
14 #define ORIG 0x1.0020008p0
15
16 /* The expected (double)((__fp16)ORIG) value. */
17 #define ROUNDED 0x1.0040000p0
18
19 typedef union u {
20 __fp16 f;
21 unsigned short h;
22 } ufh;
23
24 ufh s = { ORIG };
25 ufh r = { ROUNDED };
26
27 double d = ORIG;
28
29 int
30 main (void)
31 {
32 ufh x;
33
34 /* Test that the rounding is correct for static initializers. */
35 if (s.h != r.h)
36 abort ();
37
38 /* Test that the rounding is correct for a casted constant expression
39 not in a static initializer. */
40 x.f = (__fp16)ORIG;
41 if (x.h != r.h)
42 abort ();
43
44 /* Test that the rounding is correct for a runtime conversion. */
45 x.f = (__fp16)d;
46 if (x.h != r.h)
47 abort ();
48
49 return 0;
50 }