Debian Codegraph @

gcc/testsuite/gcc.target/avr/fminfmax-1.c

raw
1 /* { dg-do run { target { ! avr_tiny } } } */
2 /* { dg-additional-options { -std=gnu99 -Os -mcall-prologues } } */
3
4 typedef __INT8_TYPE__ int8_t;
5 typedef __UINT8_TYPE__ uint8_t;
6 typedef __UINT16_TYPE__ uint16_t;
7 typedef __UINT64_TYPE__ uint64_t;
8 typedef __INT64_TYPE__ int64_t;
9
10 #define ARRAY_SIZE(X) (sizeof(X) / sizeof(*X))
11
12 const __flash uint64_t vals[] =
13 {
14 // NaNs
15 0xffffffffffffffff,
16 0x7fffffffffffffff,
17 0xfff0000000000001,
18 0x7ff0000000000001,
19
20 // Some non-NaN doubles, increasing in magnitude.
21 0xfff0000000000000, // -Inf
22 0xffefffffffffffff,
23 0xffe0000000000000,
24 0x8010000000000000,
25 0x800fffffffffffff,
26 0x800ffffffffffffe,
27 0x8007fffffffffffe,
28 0x8000000000000001,
29 0x0000000000000000,
30 0x0000000000000001,
31 0x0007fffffffffffe,
32 0x000ffffffffffffe,
33 0x000fffffffffffff,
34 0x0010000000000000,
35 0x7fe0000000000000,
36 0x7fefffffffffffff,
37 0x7ff0000000000000 // +Inf
38 };
39
40 #define SMASK ((uint64_t) 1 << 63)
41
42 char d64_nan_p (uint64_t a)
43 {
44 return (a & ~SMASK) > (uint64_t) 0x7ff << 52;
45 }
46
47 extern uint64_t xmin (uint64_t, uint64_t) __asm("__fmin");
48 extern uint64_t xmax (uint64_t, uint64_t) __asm("__fmax");
49
50 void test_fmin (uint8_t i, uint8_t j)
51 {
52 uint64_t a = vals[i];
53 uint64_t b = vals[j];
54 uint64_t m = xmin (a, b);
55
56 char a_nan_p = d64_nan_p (a);
57 char b_nan_p = d64_nan_p (b);
58
59 if (a_nan_p + b_nan_p == 2)
60 {
61 if (!d64_nan_p (m))
62 __builtin_exit (__LINE__);
63 }
64 else
65 {
66 uint64_t r = 0?0
67 : a_nan_p ? b
68 : b_nan_p ? a
69 : i < j ? a : b;
70 if (r != m)
71 __builtin_exit (__LINE__);
72 }
73 }
74
75
76 void test_fmax (uint8_t i, uint8_t j)
77 {
78 uint64_t a = vals[i];
79 uint64_t b = vals[j];
80 uint64_t m = xmax (a, b);
81
82 char a_nan_p = d64_nan_p (a);
83 char b_nan_p = d64_nan_p (b);
84
85 if (a_nan_p + b_nan_p == 2)
86 {
87 if (!d64_nan_p (m))
88 __builtin_exit (__LINE__);
89 }
90 else
91 {
92 uint64_t r = 0?0
93 : a_nan_p ? b
94 : b_nan_p ? a
95 : i > j ? a : b;
96 if (r != m)
97 __builtin_exit (__LINE__);
98 }
99 }
100
101
102 void tests (void)
103 {
104 for (uint8_t i = 0; i < ARRAY_SIZE (vals); ++i)
105 for (uint8_t j = 0; j < ARRAY_SIZE (vals); ++j)
106 {
107 test_fmin (i, j);
108 }
109 }
110
111
112 int main (void)
113 {
114 tests ();
115 return 0;
116 }