Add 469782 to NEWS
[valgrind.git] / none / tests / ppc32 / power5+_round.c
blobbca29e074090ab53bd65c5e0ed7aa123cdd5c216
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.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <strings.h>
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
35 #define NAN 0x11000
36 #define FPRF_MASK 0x1F000
39 int main(int argc, char *argv[])
42 double inf, neg0, nan;
43 union {
44 double d;
45 struct {
46 unsigned int dummy, dummy2:15, fprf:17;
48 } fpscr;
50 inf = strtod("inf", NULL);
51 neg0 = strtod("-0", NULL);
52 nan = strtod("nan", NULL);
55 /* This set is disabled until fprf is implemented. */
56 if (0) {
57 double set[] = { inf, 1.5, 0, neg0, -1.5, -inf, nan };
58 int i, j, fprf;
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
69 } else if (i < j) {
70 fprf = 0x4000; // Greater Than
71 } else if (i > j) {
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 };
92 double ret;
93 int i;
95 #define DO_TEST(op,in,out,rf) for (i=0; i<sizeof(in)/sizeof(double); ++i) { \
96 asm (#op" %0, %2\n\t" \
97 "mffs %1\n" \
98 : "=f" (ret), "=f" (fpscr.d) \
99 : "f" (in[i]) \
100 ); \
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. */
119 if (0) {
120 double set1[] = { inf, 0.9, 0.1, 0, neg0, -0.1, -0.9, -inf, nan };
121 double frsp1[] =
122 { inf, 0.9f, 0.1f, 0, neg0, -0.1f, -0.9f, -inf, nan };
123 double set2[] =
124 { 1.2e-38, 1.1e-38, 1e-40, 8e-44, 9e-44, 8e-46, 7e-46 };
125 double frsp2[] =
126 { 1.2e-38f, 1.1e-38f, 1e-40f, 8e-44f, 9e-44f, 8e-46f, 0.0 };
127 double set3[] =
128 { -1.2e-38, -1.1e-38, -1e-40, -8e-44, -9e-44, -8e-46, -7e-46 };
129 double frsp3[] =
130 { -1.2e-38f, -1.1e-38f, -1e-40f, -8e-44f, -9e-44f, -8e-46f,
131 -0.0 };
132 double ret;
133 int i;
134 DO_TEST(frsp, set1, frsp1, fprf1);
135 DO_TEST(frsp, set2, frsp2, fprf2);
136 DO_TEST(frsp, set3, frsp3, fprf3);
140 return 0;