summaryrefslogtreecommitdiffstats
path: root/recipes/glibc/glibc-2.5/ppc-soft-fp-20070115.patch
blob: a84bc2f7cb1e7c8c7b0867af5ef4188598d869cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
2007-01-14  Steven Munroe  <sjmunroe@us.ibm.com>
	    Joe Kerian  <jkerian@us.us.ibm.com>

	[BZ #2749]
	* soft-fp/op-4.h (__FP_FRAC_SUB_3, __FP_FRAC_SUB_4): Correct borrow
	handling for high words.
	* soft-fp/op-common.h (_FP_OVERFLOW_SEMIRAW): Always set inexact
	and overflow for infinity.
	(_FP_PACK_SEMIRAW): Update comment.  Do not round if NaN or Inf.

	* math/basic-test.c (truncdfsf_test): New function.
	[!NO_LONG_DOUBLE] (trunctfsf_test): New function.
	[!NO_LONG_DOUBLE] (trunctfdf_test): New function.
	Change main() to do_test. Define TEST_FUNCTION. Include test-skeleton.c. 
	(do_test): Run new tests.

2007-01-15  Jakub Jelinek  <jakub@redhat.com>

	* soft-fp/op-common.h (FP_TRUNC): When truncating a NaN, clear
	workbits in semi-raw fraction.


diff -urN libc25-cvstip-20070104/math/basic-test.c libc24/math/basic-test.c
--- libc25-cvstip-20070104/math/basic-test.c	2001-07-05 23:55:35.000000000 -0500
+++ libc24/math/basic-test.c	2007-01-15 11:41:17.260963824 -0600
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1999, 2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Andreas Jaeger <aj@suse.de>, 1999.
 
@@ -107,17 +107,90 @@
 TEST_FUNC (double_test, double, nan, DBL_EPSILON, HUGE_VAL)
 #ifndef NO_LONG_DOUBLE
 TEST_FUNC (ldouble_test, long double, nanl, LDBL_EPSILON, HUGE_VALL)
+
+void
+trunctfsf_test(void)
+{
+  volatile long double Inf_var, NaN_var, zero_var, one_var;
+  float x1, x2;
+
+  zero_var = 0.0;
+  one_var = 1.0;
+  NaN_var = zero_var/zero_var;
+  Inf_var = one_var / zero_var;
+
+  (void) &zero_var;
+  (void) &one_var;
+  (void) &NaN_var;
+  (void) &Inf_var;
+
+  x1 = (float)NaN_var;
+  check (" float x = (float)((long double)NaN))", isnan (x1) != 0);
+  x2 = (float)Inf_var;
+  check (" float x = (float)((long double)Inf))", isinf (x2) != 0);
+}
+
+void
+trunctfdf_test(void)
+{
+  volatile long double Inf_var, NaN_var, zero_var, one_var;
+  double x1, x2;
+
+  zero_var = 0.0;
+  one_var = 1.0;
+  NaN_var = zero_var/zero_var;
+  Inf_var = one_var / zero_var;
+
+  (void) &zero_var;
+  (void) &one_var;
+  (void) &NaN_var;
+  (void) &Inf_var;
+
+  x1 = (double)NaN_var;
+  check (" double x = (double)((long double)NaN))", isnan (x1) != 0);
+  x2 = (double)Inf_var;
+  check (" double x = (double)((long double)Inf))", isinf (x2) != 0);
+}
+
 #endif
 
+void
+truncdfsf_test(void)
+{
+  volatile double Inf_var, NaN_var, zero_var, one_var;
+  float x1, x2;
+
+  zero_var = 0.0;
+  one_var = 1.0;
+  NaN_var = zero_var/zero_var;
+  Inf_var = one_var / zero_var;
+
+  (void) &zero_var;
+  (void) &one_var;
+  (void) &NaN_var;
+  (void) &Inf_var;
+
+  x1 = (float)NaN_var;
+  check (" float x = (float)((double)NaN))", isnan (x1) != 0);
+  x2 = (float)Inf_var;
+  check (" float x = (float)((double)Inf))", isinf (x2) != 0);
+}
+
 int
-main (void)
+do_test (void)
 {
   float_test ();
   double_test ();
+  truncdfsf_test();
 
 #ifndef NO_LONG_DOUBLE
   ldouble_test ();
+  trunctfsf_test();
+  trunctfdf_test();
 #endif
 
   return errors != 0;
 }
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff -urN libc25-cvstip-20070104/soft-fp/op-4.h libc24/soft-fp/op-4.h
--- libc25-cvstip-20070104/soft-fp/op-4.h	2006-04-04 03:24:47.000000000 -0500
+++ libc24/soft-fp/op-4.h	2007-01-11 11:00:53.000000000 -0600
@@ -564,7 +564,7 @@
     r1 = x1 - y1;						\
     _c2 = r1 > x1;						\
     r1 -= _c1;							\
-    _c2 |= r1 > _c1;						\
+    _c2 |= _c1 && (y1 == x1);					\
     r2 = x2 - y2 - _c2;						\
   } while (0)
 #endif
@@ -578,11 +578,11 @@
     r1 = x1 - y1;						\
     _c2 = r1 > x1;						\
     r1 -= _c1;							\
-    _c2 |= r1 > _c1;						\
+    _c2 |= _c1 && (y1 == x1);					\
     r2 = x2 - y2;						\
     _c3 = r2 > x2;						\
     r2 -= _c2;							\
-    _c3 |= r2 > _c2;						\
+    _c3 |= _c2 && (y2 == x2);					\
     r3 = x3 - y3 - _c3;						\
   } while (0)
 #endif
diff -urN libc25-cvstip-20070104/soft-fp/op-common.h libc24/soft-fp/op-common.h
--- libc25-cvstip-20070104/soft-fp/op-common.h	2006-04-04 03:24:47.000000000 -0500
+++ libc24/soft-fp/op-common.h	2007-01-15 11:46:17.290882288 -0600
@@ -1,5 +1,5 @@
 /* Software floating-point emulation. Common operations.
-   Copyright (C) 1997,1998,1999,2006 Free Software Foundation, Inc.
+   Copyright (C) 1997,1998,1999,2006,2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Richard Henderson (rth@cygnus.com),
 		  Jakub Jelinek (jj@ultra.linux.cz),
@@ -99,10 +99,10 @@
   else							\
     {							\
       X##_e = _FP_EXPMAX_##fs - 1;			\
-      FP_SET_EXCEPTION(FP_EX_OVERFLOW);			\
-      FP_SET_EXCEPTION(FP_EX_INEXACT);			\
       _FP_FRAC_SET_##wc(X, _FP_MAXFRAC_##wc);		\
     }							\
+    FP_SET_EXCEPTION(FP_EX_INEXACT);			\
+    FP_SET_EXCEPTION(FP_EX_OVERFLOW);			\
 } while (0)
 
 /* Check for a semi-raw value being a signaling NaN and raise the
@@ -1252,6 +1252,9 @@
 	      _FP_FRAC_SRL_##swc(S, (_FP_WFRACBITS_##sfs		     \
 				     - _FP_WFRACBITS_##dfs));		     \
 	      _FP_FRAC_COPY_##dwc##_##swc(D, S);			     \
+	      /* Semi-raw NaN must have all workbits cleared.  */	     \
+	      _FP_FRAC_LOW_##dwc(D)					     \
+		&= ~(_FP_W_TYPE) ((1 << _FP_WORKBITS) - 1);		     \
 	      _FP_FRAC_HIGH_##dfs(D) |= _FP_QNANBIT_SH_##dfs;		     \
 	    }								     \
 	}								     \