Debian Codegraph @

gcc/testsuite/gcc.target/avr/cmpdi-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 mant[] =
13 {
14 0x0000000000000,
15 0x0000000000001,
16 0x0000000000100,
17 0x0000000010000,
18 0x0000001000000,
19 0x0000100000000,
20 0x0010000000000,
21 0x1000000000000,
22 0x00000000000ff,
23 0x00000000000ff,
24 0x000000000ffff,
25 0x0000000ffffff,
26 0x00000ffffffff,
27 0x000ffffffffff,
28 0x0ffffffffffff,
29 0xfffffffffffff,
30 0xfffffffffff00,
31 0xfffffffff0000,
32 0xfffffff000000,
33 0xfffff00000000,
34 0xfff0000000000,
35 0xff00000000000,
36 0xf000000000000,
37 0x7ffffffffffff,
38 0x8000000000000,
39 0x8000000000001,
40 0xffffffffffffe
41 };
42
43 const __flash uint16_t expo[] =
44 {
45 0x000,
46 0x001,
47 0x002,
48 0x7fe,
49 0x7ff
50 };
51
52 #define SMASK ((uint64_t) 1 << 63)
53 #define xNAN 0x7f
54
55 char d64_nan_p (uint64_t a)
56 {
57 return (a & ~SMASK) > (uint64_t) 0x7ff << 52;
58 }
59
60 int8_t cmp_d64 (uint64_t a, uint64_t b)
61 {
62 if (d64_nan_p (a) || d64_nan_p (b))
63 return xNAN;
64
65 if (a & SMASK) a = SMASK - a;
66 if (b & SMASK) b = SMASK - b;
67 __asm ("" : "+r" (a));
68 __asm ("" : "+r" (b));
69
70 return a == b
71 ? 0
72 : (int64_t) a > (int64_t) b ? 1 : -1;
73 }
74
75 extern int8_t eq (uint64_t, uint64_t) __asm("__eqdf2");
76 extern int8_t ne (uint64_t, uint64_t) __asm("__nedf2");
77 extern int8_t ge (uint64_t, uint64_t) __asm("__gedf2");
78 extern int8_t gt (uint64_t, uint64_t) __asm("__gtdf2");
79 extern int8_t le (uint64_t, uint64_t) __asm("__ledf2");
80 extern int8_t lt (uint64_t, uint64_t) __asm("__ltdf2");
81 extern int8_t unord (uint64_t, uint64_t) __asm("__unorddf2");
82
83 void test1 (uint64_t a, uint64_t b)
84 {
85 int8_t d, c = cmp_d64 (a, b);
86 d = eq (a, b);
87 if (c == xNAN && d) __builtin_exit (1);
88 if (c != xNAN && d != (c == 0)) __builtin_exit (2);
89
90 d = ne (a, b);
91 if (c == xNAN && d) __builtin_exit (3);
92 if (c != xNAN && d != (c != 0)) __builtin_exit (4);
93
94 d = ge (a, b);
95 if (c == xNAN && d) __builtin_exit (5);
96 if (c != xNAN && d != (c >= 0)) __builtin_exit (6);
97
98 d = gt (a, b);
99 if (c == xNAN && d) __builtin_exit (7);
100 if (c != xNAN && d != (c > 0)) __builtin_exit (8);
101
102 d = le (a, b);
103 if (c == xNAN && d) __builtin_exit (9);
104 if (c != xNAN && d != (c <= 0)) __builtin_exit (10);
105
106 d = lt (a, b);
107 if (c == xNAN && d) __builtin_exit (11);
108 if (c != xNAN && d != (c < 0)) __builtin_exit (12);
109
110 d = unord (a, b);
111 if (c == xNAN && !d) __builtin_exit (13);
112 if (c != xNAN && d) __builtin_exit (14);
113 }
114
115
116 void testAB (uint64_t a, uint64_t b)
117 {
118 test1 (a, b);
119 test1 (a, b ^ SMASK);
120 test1 (a ^ SMASK, b);
121 test1 (a ^ SMASK, b ^ SMASK);
122 }
123
124 void testA (uint64_t a)
125 {
126 for (uint8_t i = 0; i < ARRAY_SIZE (mant); ++i)
127 {
128 uint64_t b = mant[i];
129 for (uint8_t j = 0; j < ARRAY_SIZE (expo); ++j)
130 testAB (a, b | ((uint64_t) expo[j] << 52));
131 }
132 }
133
134 void tests (void)
135 {
136 for (uint8_t i = 0; i < ARRAY_SIZE (mant); ++i)
137 {
138 uint64_t a = mant[i];
139 for (uint8_t j = 0; j < ARRAY_SIZE (expo); ++j)
140 testA (a | ((uint64_t) expo[j] << 52));
141 }
142 }
143
144
145 int main (void)
146 {
147 tests ();
148 return 0;
149 }