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, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 The GNU General Public License is contained in the file COPYING.
29 #define POS_NORMAL 0x4000
30 #define NEG_NORMAL 0x8000
31 #define POS_INF 0x5000
32 #define NEG_INF 0x9000
33 #define POS_ZERO 0x2000
34 #define NEG_ZERO 0x12000
35 #define POS_DENORMAL 0x14000
36 #define NEG_DENORMAL 0x18000
38 #define FPRF_MASK 0x1F000
41 int main(int argc, char *argv[])
44 double inf, neg0, nan;
48 unsigned int dummy, dummy2:15, fprf:17;
52 inf = strtod("inf", NULL);
53 neg0 = strtod("-0", NULL);
54 nan = strtod("nan", NULL);
57 /* This set is disabled until fprf is implemented. */
59 double set[] = { inf, 1.5, 0, neg0, -1.5, -inf, nan };
61 for (i = 0; i < 7; ++i) {
62 for (j = 0; j < 7; ++j) {
63 asm("fcmpu 1, %1, %2\n\t" "mffs %0\n":"=f"(fpscr.d)
64 : "f"(set[i]), "f"(set[j])
67 if (i == 6 || j == 6) {
68 fprf = 0x1000; // Unordered
69 } else if (i == j || (i == 2 && j == 3) || (i == 3 && j == 2)) {
70 fprf = 0x2000; // Equal
72 fprf = 0x4000; // Greater Than
74 fprf = 0x8000; // Less Than
77 printf("fcmpu\t%.1f\t%.1f\t%x\t%s\n", set[i], set[j],
78 fpscr.fprf, fpscr.fprf == fprf ? "PASS" : "FAIL");
84 double set[] = { inf, 1.9, 1.1, 0, neg0, -1.1, -1.9, -inf, nan };
85 double frin[] = { inf, 2.0, 1.0, 0, neg0, -1.0, -2.0, -inf, nan };
86 double friz[] = { inf, 1.0, 1.0, 0, neg0, -1.0, -1.0, -inf, nan };
87 double frip[] = { inf, 2.0, 2.0, 0, neg0, -1.0, -1.0, -inf, nan };
88 double frim[] = { inf, 1.0, 1.0, 0, neg0, -2.0, -2.0, -inf, nan };
89 int fprf[] = { POS_INF, POS_NORMAL, POS_NORMAL, POS_ZERO, NEG_ZERO,
90 NEG_NORMAL, NEG_NORMAL, NEG_INF, NAN
92 double set2[] = { 0.9, 0.1, -0.1, -0.9, 1e-40, -1e-40 };
93 double frin2[] = { 1.0, 0.0, -0.0, -1.0, 0.0, -0.0 };
95 { POS_NORMAL, POS_ZERO, NEG_ZERO, NEG_NORMAL, POS_ZERO,
97 double friz2[] = { 0.0, 0.0, -0.0, -0.0, 0.0, -0.0 };
99 { POS_ZERO, POS_ZERO, NEG_ZERO, NEG_ZERO, POS_ZERO, NEG_ZERO };
100 double frip2[] = { 1.0, 1.0, -0.0, -0.0, 1.0, -0.0 };
102 { POS_NORMAL, POS_NORMAL, NEG_ZERO, NEG_ZERO, POS_NORMAL,
104 double frim2[] = { 0.0, 0.0, -1.0, -1.0, 0.0, -1.0 };
106 { POS_ZERO, POS_ZERO, NEG_NORMAL, NEG_NORMAL, POS_ZERO,
111 #define DO_TEST(op,in,out,rf) for (i=0; i<sizeof(in)/sizeof(double); ++i) { \
112 asm (#op" %0, %2\n\t" \
114 : "=f" (ret), "=f" (fpscr.d) \
117 printf(#op"\t%g\t%g\t%x\t%s\n", in[i], ret, fpscr.fprf, \
118 (!bcmp(&ret, &out[i], sizeof(double))) /*&& (rf[i] == fpscr.fprf)*/ \
119 ? "PASS" : "FAIL"); \
121 /* Note: fprf check above is disabled until fprf is implemented. */
124 DO_TEST(frin, set, frin, fprf);
125 DO_TEST(frin, set2, frin2, frin2rf);
126 DO_TEST(friz, set, friz, fprf);
127 DO_TEST(friz, set2, friz2, friz2rf);
128 DO_TEST(frip, set, frip, fprf);
129 DO_TEST(frip, set2, frip2, frip2rf);
130 DO_TEST(frim, set, frim, fprf);
131 DO_TEST(frim, set2, frim2, frim2rf);
134 /* This set is disabled until fprf is implemented. */
136 double set1[] = { inf, 0.9, 0.1, 0, neg0, -0.1, -0.9, -inf, nan };
138 { inf, 0.9f, 0.1f, 0, neg0, -0.1f, -0.9f, -inf, nan };
140 { POS_INF, POS_NORMAL, POS_NORMAL, POS_ZERO, NEG_ZERO,
142 NEG_NORMAL, NEG_INF, NAN
145 { 1.2e-38, 1.1e-38, 1e-40, 8e-44, 9e-44, 8e-46, 7e-46 };
147 { 1.2e-38f, 1.1e-38f, 1e-40f, 8e-44f, 9e-44f, 8e-46f, 0.0 };
148 int fprf2[] = { POS_NORMAL, POS_DENORMAL, POS_DENORMAL, POS_DENORMAL,
149 POS_DENORMAL, POS_DENORMAL, POS_ZERO
152 { -1.2e-38, -1.1e-38, -1e-40, -8e-44, -9e-44, -8e-46, -7e-46 };
154 { -1.2e-38f, -1.1e-38f, -1e-40f, -8e-44f, -9e-44f, -8e-46f,
156 int fprf3[] = { NEG_NORMAL, NEG_DENORMAL, NEG_DENORMAL, NEG_DENORMAL,
157 NEG_DENORMAL, NEG_DENORMAL, NEG_ZERO
161 DO_TEST(frsp, set1, frsp1, fprf1);
162 DO_TEST(frsp, set2, frsp2, fprf2);
163 DO_TEST(frsp, set3, frsp3, fprf3);