1 /* Copyright (C) 2007 IBM 2 3 Author: Pete Eberlein eberlein (at) us.ibm.com 4 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. 9 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. 14 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 18 02111-1307, USA. 19 20 The GNU General Public License is contained in the file COPYING. 21 */ 22 23 24 25 #include <stdio.h> 26 #include <stdlib.h> 27 #include <strings.h> 28 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 37 #define NAN 0x11000 38 #define FPRF_MASK 0x1F000 39 40 41 int main(int argc, char *argv[]) 42 { 43 44 double inf, neg0, nan; 45 union { 46 double d; 47 struct { 48 unsigned int dummy, dummy2:15, fprf:17; 49 }; 50 } fpscr; 51 52 inf = strtod("inf", NULL); 53 neg0 = strtod("-0", NULL); 54 nan = strtod("nan", NULL); 55 56 57 /* This set is disabled until fprf is implemented. */ 58 if (0) { 59 double set[] = { inf, 1.5, 0, neg0, -1.5, -inf, nan }; 60 int i, j, fprf; 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]) 65 ); 66 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 71 } else if (i < j) { 72 fprf = 0x4000; // Greater Than 73 } else if (i > j) { 74 fprf = 0x8000; // Less Than 75 } 76 77 printf("fcmpu\t%.1f\t%.1f\t%x\t%s\n", set[i], set[j], 78 fpscr.fprf, fpscr.fprf == fprf ? "PASS" : "FAIL"); 79 } 80 } 81 } 82 83 { 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 double set2[] = { 0.9, 0.1, -0.1, -0.9, 1e-40, -1e-40 }; 90 double frin2[] = { 1.0, 0.0, -0.0, -1.0, 0.0, -0.0 }; 91 double friz2[] = { 0.0, 0.0, -0.0, -0.0, 0.0, -0.0 }; 92 double frip2[] = { 1.0, 1.0, -0.0, -0.0, 1.0, -0.0 }; 93 double frim2[] = { 0.0, 0.0, -1.0, -1.0, 0.0, -1.0 }; 94 double ret; 95 int i; 96 97 #define DO_TEST(op,in,out,rf) for (i=0; i<sizeof(in)/sizeof(double); ++i) { \ 98 asm (#op" %0, %2\n\t" \ 99 "mffs %1\n" \ 100 : "=f" (ret), "=f" (fpscr.d) \ 101 : "f" (in[i]) \ 102 ); \ 103 printf(#op"\t%g\t%g\t%x\t%s\n", in[i], ret, fpscr.fprf, \ 104 (!bcmp(&ret, &out[i], sizeof(double))) /*&& (rf[i] == fpscr.fprf)*/ \ 105 ? "PASS" : "FAIL"); \ 106 } 107 /* Note: fprf check above is disabled until fprf is implemented. */ 108 109 110 DO_TEST(frin, set, frin, fprf); 111 DO_TEST(frin, set2, frin2, frin2rf); 112 DO_TEST(friz, set, friz, fprf); 113 DO_TEST(friz, set2, friz2, friz2rf); 114 DO_TEST(frip, set, frip, fprf); 115 DO_TEST(frip, set2, frip2, frip2rf); 116 DO_TEST(frim, set, frim, fprf); 117 DO_TEST(frim, set2, frim2, frim2rf); 118 } 119 120 /* This set is disabled until fprf is implemented. */ 121 if (0) { 122 double set1[] = { inf, 0.9, 0.1, 0, neg0, -0.1, -0.9, -inf, nan }; 123 double frsp1[] = 124 { inf, 0.9f, 0.1f, 0, neg0, -0.1f, -0.9f, -inf, nan }; 125 double set2[] = 126 { 1.2e-38, 1.1e-38, 1e-40, 8e-44, 9e-44, 8e-46, 7e-46 }; 127 double frsp2[] = 128 { 1.2e-38f, 1.1e-38f, 1e-40f, 8e-44f, 9e-44f, 8e-46f, 0.0 }; 129 double set3[] = 130 { -1.2e-38, -1.1e-38, -1e-40, -8e-44, -9e-44, -8e-46, -7e-46 }; 131 double frsp3[] = 132 { -1.2e-38f, -1.1e-38f, -1e-40f, -8e-44f, -9e-44f, -8e-46f, 133 -0.0 }; 134 double ret; 135 int i; 136 DO_TEST(frsp, set1, frsp1, fprf1); 137 DO_TEST(frsp, set2, frsp2, fprf2); 138 DO_TEST(frsp, set3, frsp3, fprf3); 139 } 140 141 142 return 0; 143 } 144