summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/torture/arm-fp16-ops.h
blob: 320494ee71cf198879770e031daacac8deb64734 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Test various operators on __fp16 and mixed __fp16/float operands.  */

#include <assert.h>

#define CHECK(e,r) assert ((e) == r)
#define CHECK2(e,r) (assert ((e) == r), temp = (e), assert (temp == r))
#define TEST(e) assert (e)
#define TESTNOT(e) assert (!(e))

volatile __fp16 h0 = 0.0;
volatile __fp16 h1 = 1.0;
volatile __fp16 h42 = 42.0;
volatile __fp16 hm2 = -2.0;
volatile __fp16 temp;

volatile float f0 = 0.0;
volatile float f1 = 1.0;
volatile float f42 = 42.0;
volatile float fm2 = -2.0;

int main (void)
{
  TEST (h1);
  TESTNOT (h0);
  TEST (!h0);
  TESTNOT (!h1);

  CHECK2 (-h1, -1.0);
  CHECK2 (+h1, 1.0);

  CHECK (h1++, 1.0);
  CHECK (h1, 2.0);
  CHECK (++h1, 3.0);
  CHECK (h1, 3.0);

  CHECK (--h1, 2.0);
  CHECK (h1, 2.0);
  CHECK (h1--, 2.0);
  CHECK (h1, 1.0);

  CHECK2 (h42 * hm2, -84.0);
  CHECK2 (h42 * (__fp16) -2.0, -84.0);
  CHECK2 (h42 * fm2, -84.0);
  CHECK2 (f42 * hm2, -84.0);

  CHECK2 (h42 / hm2, -21.0);
  CHECK2 (h42 / (__fp16) -2.0, -21.0);
  CHECK2 (h42 / fm2, -21.0);
  CHECK2 (f42 / hm2, -21.0);

  CHECK2 (hm2 + h42, 40.0);
  CHECK2 ((__fp16)-2.0 + h42, 40.0);
  CHECK2 (hm2 + f42, 40.0);
  CHECK2 (fm2 + h42, 40.0);

  CHECK2 (hm2 - h42, -44.0);
  CHECK2 ((__fp16)-2.0 - h42, -44.0);
  CHECK2 (hm2 - f42, -44.0);
  CHECK2 (fm2 - h42, -44.0);

  TEST (hm2 < h42);
  TEST (hm2 < (__fp16)42.0);
  TEST (hm2 < f42);
  TEST (fm2 < h42);

  TEST (h42 > hm2);
  TEST ((__fp16)42.0 > hm2);
  TEST (h42 > fm2);
  TEST (f42 > hm2);

  TEST (hm2 <= h42);
  TEST (hm2 <= (__fp16)42.0);
  TEST (hm2 <= f42);
  TEST (fm2 <= h42);

  TEST (h42 >= hm2);
  TEST (h42 >= (__fp16)-2.0);
  TEST (h42 >= fm2);
  TEST (f42 >= hm2);

  TESTNOT (h1 == hm2);
  TEST (h1 == h1);
  TEST (h1 == (__fp16)1.0);
  TEST (h1 == f1);
  TEST (f1 == h1);

  TEST (h1 != hm2);
  TESTNOT (h1 != h1);
  TESTNOT (h1 != (__fp16)1.0);
  TESTNOT (h1 != f1);
  TESTNOT (f1 != h1);

  CHECK2 ((h1 ? hm2 : h42), -2.0);
  CHECK2 ((h0 ? hm2 : h42), 42.0);

  CHECK (h0 = h42, 42.0);
  CHECK (h0, 42.0);
  CHECK (h0 = (__fp16)-2.0, -2.0);
  CHECK (h0, -2.0);
  CHECK (h0 = f0, 0.0);
  CHECK (h0, 0.0);

  CHECK (h0 += h1, 1.0);
  CHECK (h0, 1.0);
  CHECK (h0 += (__fp16)1.0, 2.0);
  CHECK (h0, 2.0);
  CHECK (h0 += fm2, 0.0);
  CHECK (h0, 0.0);

  CHECK (h0 -= h1, -1.0);
  CHECK (h0, -1.0);
  CHECK (h0 -= (__fp16)1.0, -2.0);
  CHECK (h0, -2.0);
  CHECK (h0 -= fm2, 0.0);
  CHECK (h0, 0.0);

  h0 = hm2;
  CHECK (h0 *= hm2, 4.0);
  CHECK (h0, 4.0);
  CHECK (h0 *= (__fp16)-2.0, -8.0);
  CHECK (h0, -8.0);
  CHECK (h0 *= fm2, 16.0);
  CHECK (h0, 16.0);

  CHECK (h0 /= hm2, -8.0);
  CHECK (h0, -8.0);
  CHECK (h0 /= (__fp16)-2.0, 4.0);
  CHECK (h0, 4.0);
  CHECK (h0 /= fm2, -2.0);
  CHECK (h0, -2.0);

  CHECK ((h0, h1), 1.0);

  return 0;
}