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