Add _FloatN, _FloatNx tests for __builtin_fpclassify.
[official-gcc.git] / gcc / testsuite / gcc.dg / torture / arm-fp16-ops.h
blob320494ee71cf198879770e031daacac8deb64734
1 /* Test various operators on __fp16 and mixed __fp16/float operands. */
3 #include <assert.h>
5 #define CHECK(e,r) assert ((e) == r)
6 #define CHECK2(e,r) (assert ((e) == r), temp = (e), assert (temp == r))
7 #define TEST(e) assert (e)
8 #define TESTNOT(e) assert (!(e))
10 volatile __fp16 h0 = 0.0;
11 volatile __fp16 h1 = 1.0;
12 volatile __fp16 h42 = 42.0;
13 volatile __fp16 hm2 = -2.0;
14 volatile __fp16 temp;
16 volatile float f0 = 0.0;
17 volatile float f1 = 1.0;
18 volatile float f42 = 42.0;
19 volatile float fm2 = -2.0;
21 int main (void)
23 TEST (h1);
24 TESTNOT (h0);
25 TEST (!h0);
26 TESTNOT (!h1);
28 CHECK2 (-h1, -1.0);
29 CHECK2 (+h1, 1.0);
31 CHECK (h1++, 1.0);
32 CHECK (h1, 2.0);
33 CHECK (++h1, 3.0);
34 CHECK (h1, 3.0);
36 CHECK (--h1, 2.0);
37 CHECK (h1, 2.0);
38 CHECK (h1--, 2.0);
39 CHECK (h1, 1.0);
41 CHECK2 (h42 * hm2, -84.0);
42 CHECK2 (h42 * (__fp16) -2.0, -84.0);
43 CHECK2 (h42 * fm2, -84.0);
44 CHECK2 (f42 * hm2, -84.0);
46 CHECK2 (h42 / hm2, -21.0);
47 CHECK2 (h42 / (__fp16) -2.0, -21.0);
48 CHECK2 (h42 / fm2, -21.0);
49 CHECK2 (f42 / hm2, -21.0);
51 CHECK2 (hm2 + h42, 40.0);
52 CHECK2 ((__fp16)-2.0 + h42, 40.0);
53 CHECK2 (hm2 + f42, 40.0);
54 CHECK2 (fm2 + h42, 40.0);
56 CHECK2 (hm2 - h42, -44.0);
57 CHECK2 ((__fp16)-2.0 - h42, -44.0);
58 CHECK2 (hm2 - f42, -44.0);
59 CHECK2 (fm2 - h42, -44.0);
61 TEST (hm2 < h42);
62 TEST (hm2 < (__fp16)42.0);
63 TEST (hm2 < f42);
64 TEST (fm2 < h42);
66 TEST (h42 > hm2);
67 TEST ((__fp16)42.0 > hm2);
68 TEST (h42 > fm2);
69 TEST (f42 > hm2);
71 TEST (hm2 <= h42);
72 TEST (hm2 <= (__fp16)42.0);
73 TEST (hm2 <= f42);
74 TEST (fm2 <= h42);
76 TEST (h42 >= hm2);
77 TEST (h42 >= (__fp16)-2.0);
78 TEST (h42 >= fm2);
79 TEST (f42 >= hm2);
81 TESTNOT (h1 == hm2);
82 TEST (h1 == h1);
83 TEST (h1 == (__fp16)1.0);
84 TEST (h1 == f1);
85 TEST (f1 == h1);
87 TEST (h1 != hm2);
88 TESTNOT (h1 != h1);
89 TESTNOT (h1 != (__fp16)1.0);
90 TESTNOT (h1 != f1);
91 TESTNOT (f1 != h1);
93 CHECK2 ((h1 ? hm2 : h42), -2.0);
94 CHECK2 ((h0 ? hm2 : h42), 42.0);
96 CHECK (h0 = h42, 42.0);
97 CHECK (h0, 42.0);
98 CHECK (h0 = (__fp16)-2.0, -2.0);
99 CHECK (h0, -2.0);
100 CHECK (h0 = f0, 0.0);
101 CHECK (h0, 0.0);
103 CHECK (h0 += h1, 1.0);
104 CHECK (h0, 1.0);
105 CHECK (h0 += (__fp16)1.0, 2.0);
106 CHECK (h0, 2.0);
107 CHECK (h0 += fm2, 0.0);
108 CHECK (h0, 0.0);
110 CHECK (h0 -= h1, -1.0);
111 CHECK (h0, -1.0);
112 CHECK (h0 -= (__fp16)1.0, -2.0);
113 CHECK (h0, -2.0);
114 CHECK (h0 -= fm2, 0.0);
115 CHECK (h0, 0.0);
117 h0 = hm2;
118 CHECK (h0 *= hm2, 4.0);
119 CHECK (h0, 4.0);
120 CHECK (h0 *= (__fp16)-2.0, -8.0);
121 CHECK (h0, -8.0);
122 CHECK (h0 *= fm2, 16.0);
123 CHECK (h0, 16.0);
125 CHECK (h0 /= hm2, -8.0);
126 CHECK (h0, -8.0);
127 CHECK (h0 /= (__fp16)-2.0, 4.0);
128 CHECK (h0, 4.0);
129 CHECK (h0 /= fm2, -2.0);
130 CHECK (h0, -2.0);
132 CHECK ((h0, h1), 1.0);
134 return 0;