1 /* Copyright (C) 2007 IBM
3 Author: Pete Eberlein eberlein@us.ibm.com
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <http://www.gnu.org/licenses/>.
18 The GNU General Public License is contained in the file COPYING.
27 #define POS_NORMAL 0x4000
28 #define NEG_NORMAL 0x8000
29 #define POS_INF 0x5000
30 #define NEG_INF 0x9000
31 #define POS_ZERO 0x2000
32 #define NEG_ZERO 0x12000
33 #define POS_DENORMAL 0x14000
34 #define NEG_DENORMAL 0x18000
36 #define FPRF_MASK 0x1F000
39 int main(int argc
, char *argv
[])
42 double inf
, neg0
, nan
;
46 unsigned int dummy
, dummy2
:15, fprf
:17;
50 inf
= strtod("inf", NULL
);
51 neg0
= strtod("-0", NULL
);
52 nan
= strtod("nan", NULL
);
55 /* This set is disabled until fprf is implemented. */
57 double set
[] = { inf
, 1.5, 0, neg0
, -1.5, -inf
, nan
};
59 for (i
= 0; i
< 7; ++i
) {
60 for (j
= 0; j
< 7; ++j
) {
61 asm("fcmpu 1, %1, %2\n\t" "mffs %0\n":"=f"(fpscr
.d
)
62 : "f"(set
[i
]), "f"(set
[j
])
65 if (i
== 6 || j
== 6) {
66 fprf
= 0x1000; // Unordered
67 } else if (i
== j
|| (i
== 2 && j
== 3) || (i
== 3 && j
== 2)) {
68 fprf
= 0x2000; // Equal
70 fprf
= 0x4000; // Greater Than
72 fprf
= 0x8000; // Less Than
75 printf("fcmpu\t%.1f\t%.1f\t%x\t%s\n", set
[i
], set
[j
],
76 fpscr
.fprf
, fpscr
.fprf
== fprf
? "PASS" : "FAIL");
82 double set
[] = { inf
, 1.9, 1.1, 0, neg0
, -1.1, -1.9, -inf
, nan
};
83 double frin
[] = { inf
, 2.0, 1.0, 0, neg0
, -1.0, -2.0, -inf
, nan
};
84 double friz
[] = { inf
, 1.0, 1.0, 0, neg0
, -1.0, -1.0, -inf
, nan
};
85 double frip
[] = { inf
, 2.0, 2.0, 0, neg0
, -1.0, -1.0, -inf
, nan
};
86 double frim
[] = { inf
, 1.0, 1.0, 0, neg0
, -2.0, -2.0, -inf
, nan
};
87 double set2
[] = { 0.9, 0.1, -0.1, -0.9, 1e-40, -1e-40 };
88 double frin2
[] = { 1.0, 0.0, -0.0, -1.0, 0.0, -0.0 };
89 double friz2
[] = { 0.0, 0.0, -0.0, -0.0, 0.0, -0.0 };
90 double frip2
[] = { 1.0, 1.0, -0.0, -0.0, 1.0, -0.0 };
91 double frim2
[] = { 0.0, 0.0, -1.0, -1.0, 0.0, -1.0 };
95 #define DO_TEST(op,in,out,rf) for (i=0; i<sizeof(in)/sizeof(double); ++i) { \
96 asm (#op" %0, %2\n\t" \
98 : "=f" (ret), "=f" (fpscr.d) \
101 printf(#op"\t%g\t%g\t%x\t%s\n", in[i], ret, fpscr.fprf, \
102 (!bcmp(&ret, &out[i], sizeof(double))) /*&& (rf[i] == fpscr.fprf)*/ \
103 ? "PASS" : "FAIL"); \
105 /* Note: fprf check above is disabled until fprf is implemented. */
108 DO_TEST(frin
, set
, frin
, fprf
);
109 DO_TEST(frin
, set2
, frin2
, frin2rf
);
110 DO_TEST(friz
, set
, friz
, fprf
);
111 DO_TEST(friz
, set2
, friz2
, friz2rf
);
112 DO_TEST(frip
, set
, frip
, fprf
);
113 DO_TEST(frip
, set2
, frip2
, frip2rf
);
114 DO_TEST(frim
, set
, frim
, fprf
);
115 DO_TEST(frim
, set2
, frim2
, frim2rf
);
118 /* This set is disabled until fprf is implemented. */
120 double set1
[] = { inf
, 0.9, 0.1, 0, neg0
, -0.1, -0.9, -inf
, nan
};
122 { inf
, 0.9f
, 0.1f
, 0, neg0
, -0.1f
, -0.9f
, -inf
, nan
};
124 { 1.2e-38, 1.1e-38, 1e-40, 8e-44, 9e-44, 8e-46, 7e-46 };
126 { 1.2e-38f
, 1.1e-38f
, 1e-40f
, 8e-44f
, 9e-44f
, 8e-46f
, 0.0 };
128 { -1.2e-38, -1.1e-38, -1e-40, -8e-44, -9e-44, -8e-46, -7e-46 };
130 { -1.2e-38f
, -1.1e-38f
, -1e-40f
, -8e-44f
, -9e-44f
, -8e-46f
,
134 DO_TEST(frsp
, set1
, frsp1
, fprf1
);
135 DO_TEST(frsp
, set2
, frsp2
, fprf2
);
136 DO_TEST(frsp
, set3
, frsp3
, fprf3
);