1#ifndef FLOAT
2#define FLOAT double
3#endif
4
5/* Like fp-cmp-4.c, but test that the cmove patterns are correct.  */
6
7static FLOAT
8test_isunordered(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
9{
10  return __builtin_isunordered(x, y) ? a : b;
11}
12
13static FLOAT
14test_not_isunordered(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
15{
16  return !__builtin_isunordered(x, y) ? a : b;
17}
18
19static FLOAT
20test_isless(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
21{
22  return __builtin_isless(x, y) ? a : b;
23}
24
25static FLOAT
26test_not_isless(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
27{
28  return !__builtin_isless(x, y) ? a : b;
29}
30
31static FLOAT
32test_islessequal(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
33{
34  return __builtin_islessequal(x, y) ? a : b;
35}
36
37static FLOAT
38test_not_islessequal(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
39{
40  return !__builtin_islessequal(x, y) ? a : b;
41}
42
43static FLOAT
44test_isgreater(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
45{
46  return __builtin_isgreater(x, y) ? a : b;
47}
48
49static FLOAT
50test_not_isgreater(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
51{
52  return !__builtin_isgreater(x, y) ? a : b;
53}
54
55static FLOAT
56test_isgreaterequal(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
57{
58  return __builtin_isgreaterequal(x, y) ? a : b;
59}
60
61static FLOAT
62test_not_isgreaterequal(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
63{
64  return !__builtin_isgreaterequal(x, y) ? a : b;
65}
66
67static FLOAT
68test_islessgreater(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
69{
70  return __builtin_islessgreater(x, y) ? a : b;
71}
72
73static FLOAT
74test_not_islessgreater(FLOAT x, FLOAT y, FLOAT a, FLOAT b)
75{
76  return !__builtin_islessgreater(x, y) ? a : b;
77}
78
79static void
80one_test(FLOAT x, FLOAT y, int expected,
81         FLOAT (*pos) (FLOAT, FLOAT, FLOAT, FLOAT),
82	 FLOAT (*neg) (FLOAT, FLOAT, FLOAT, FLOAT))
83{
84  if (((*pos)(x, y, 1.0, 2.0) == 1.0) != expected)
85    abort ();
86  if (((*neg)(x, y, 3.0, 4.0) == 4.0) != expected)
87    abort ();
88}
89
90#define NAN (0.0 / 0.0)
91#define INF (1.0 / 0.0)
92
93int
94main()
95{
96  struct try
97  {
98    FLOAT x, y;
99    int result[6];
100  };
101
102  static struct try const data[] =
103  {
104    { NAN, NAN, { 1, 0, 0, 0, 0, 0 } },
105    { 0.0, NAN, { 1, 0, 0, 0, 0, 0 } },
106    { NAN, 0.0, { 1, 0, 0, 0, 0, 0 } },
107    { 0.0, 0.0, { 0, 0, 1, 0, 1, 0 } },
108    { 1.0, 2.0, { 0, 1, 1, 0, 0, 1 } },
109    { 2.0, 1.0, { 0, 0, 0, 1, 1, 1 } },
110    { INF, 0.0, { 0, 0, 0, 1, 1, 1 } },
111    { 1.0, INF, { 0, 1, 1, 0, 0, 1 } },
112    { INF, INF, { 0, 0, 1, 0, 1, 0 } },
113    { 0.0, -INF, { 0, 0, 0, 1, 1, 1 } },
114    { -INF, 1.0, { 0, 1, 1, 0, 0, 1 } },
115    { -INF, -INF, { 0, 0, 1, 0, 1, 0 } },
116    { INF, -INF, { 0, 0, 0, 1, 1, 1 } },
117    { -INF, INF, { 0, 1, 1, 0, 0, 1 } },
118  };
119
120  struct test
121  {
122    FLOAT (*pos)(FLOAT, FLOAT, FLOAT, FLOAT);
123    FLOAT (*neg)(FLOAT, FLOAT, FLOAT, FLOAT);
124  };
125
126  static struct test const tests[] =
127  {
128    { test_isunordered, test_not_isunordered },
129    { test_isless, test_not_isless },
130    { test_islessequal, test_not_islessequal },
131    { test_isgreater, test_not_isgreater },
132    { test_isgreaterequal, test_not_isgreaterequal },
133    { test_islessgreater, test_not_islessgreater }
134  };
135
136  const int n = sizeof(data) / sizeof(data[0]);
137  int i, j;
138
139  for (i = 0; i < n; ++i)
140    for (j = 0; j < 6; ++j)
141      one_test (data[i].x, data[i].y, data[i].result[j],
142		tests[j].pos, tests[j].neg);
143
144  exit (0);
145}
146