diff options
Diffstat (limited to 'arch/x86/math-emu/fpu_trig.c')
-rw-r--r-- | arch/x86/math-emu/fpu_trig.c | 2922 |
1 files changed, 1360 insertions, 1562 deletions
diff --git a/arch/x86/math-emu/fpu_trig.c b/arch/x86/math-emu/fpu_trig.c index 403cbde1d425..e5316a288a6e 100644 --- a/arch/x86/math-emu/fpu_trig.c +++ b/arch/x86/math-emu/fpu_trig.c | |||
@@ -15,11 +15,10 @@ | |||
15 | #include "fpu_emu.h" | 15 | #include "fpu_emu.h" |
16 | #include "status_w.h" | 16 | #include "status_w.h" |
17 | #include "control_w.h" | 17 | #include "control_w.h" |
18 | #include "reg_constant.h" | 18 | #include "reg_constant.h" |
19 | 19 | ||
20 | static void rem_kernel(unsigned long long st0, unsigned long long *y, | 20 | static void rem_kernel(unsigned long long st0, unsigned long long *y, |
21 | unsigned long long st1, | 21 | unsigned long long st1, unsigned long long q, int n); |
22 | unsigned long long q, int n); | ||
23 | 22 | ||
24 | #define BETTER_THAN_486 | 23 | #define BETTER_THAN_486 |
25 | 24 | ||
@@ -31,790 +30,708 @@ static void rem_kernel(unsigned long long st0, unsigned long long *y, | |||
31 | /* Limited measurements show no results worse than 64 bit precision | 30 | /* Limited measurements show no results worse than 64 bit precision |
32 | except for the results for arguments close to 2^63, where the | 31 | except for the results for arguments close to 2^63, where the |
33 | precision of the result sometimes degrades to about 63.9 bits */ | 32 | precision of the result sometimes degrades to about 63.9 bits */ |
34 | static int trig_arg(FPU_REG *st0_ptr, int even) | 33 | static int trig_arg(FPU_REG * st0_ptr, int even) |
35 | { | 34 | { |
36 | FPU_REG tmp; | 35 | FPU_REG tmp; |
37 | u_char tmptag; | 36 | u_char tmptag; |
38 | unsigned long long q; | 37 | unsigned long long q; |
39 | int old_cw = control_word, saved_status = partial_status; | 38 | int old_cw = control_word, saved_status = partial_status; |
40 | int tag, st0_tag = TAG_Valid; | 39 | int tag, st0_tag = TAG_Valid; |
41 | 40 | ||
42 | if ( exponent(st0_ptr) >= 63 ) | 41 | if (exponent(st0_ptr) >= 63) { |
43 | { | 42 | partial_status |= SW_C2; /* Reduction incomplete. */ |
44 | partial_status |= SW_C2; /* Reduction incomplete. */ | 43 | return -1; |
45 | return -1; | 44 | } |
46 | } | ||
47 | |||
48 | control_word &= ~CW_RC; | ||
49 | control_word |= RC_CHOP; | ||
50 | |||
51 | setpositive(st0_ptr); | ||
52 | tag = FPU_u_div(st0_ptr, &CONST_PI2, &tmp, PR_64_BITS | RC_CHOP | 0x3f, | ||
53 | SIGN_POS); | ||
54 | |||
55 | FPU_round_to_int(&tmp, tag); /* Fortunately, this can't overflow | ||
56 | to 2^64 */ | ||
57 | q = significand(&tmp); | ||
58 | if ( q ) | ||
59 | { | ||
60 | rem_kernel(significand(st0_ptr), | ||
61 | &significand(&tmp), | ||
62 | significand(&CONST_PI2), | ||
63 | q, exponent(st0_ptr) - exponent(&CONST_PI2)); | ||
64 | setexponent16(&tmp, exponent(&CONST_PI2)); | ||
65 | st0_tag = FPU_normalize(&tmp); | ||
66 | FPU_copy_to_reg0(&tmp, st0_tag); | ||
67 | } | ||
68 | |||
69 | if ( (even && !(q & 1)) || (!even && (q & 1)) ) | ||
70 | { | ||
71 | st0_tag = FPU_sub(REV|LOADED|TAG_Valid, (int)&CONST_PI2, FULL_PRECISION); | ||
72 | 45 | ||
73 | #ifdef BETTER_THAN_486 | 46 | control_word &= ~CW_RC; |
74 | /* So far, the results are exact but based upon a 64 bit | 47 | control_word |= RC_CHOP; |
75 | precision approximation to pi/2. The technique used | 48 | |
76 | now is equivalent to using an approximation to pi/2 which | 49 | setpositive(st0_ptr); |
77 | is accurate to about 128 bits. */ | 50 | tag = FPU_u_div(st0_ptr, &CONST_PI2, &tmp, PR_64_BITS | RC_CHOP | 0x3f, |
78 | if ( (exponent(st0_ptr) <= exponent(&CONST_PI2extra) + 64) || (q > 1) ) | 51 | SIGN_POS); |
79 | { | 52 | |
80 | /* This code gives the effect of having pi/2 to better than | 53 | FPU_round_to_int(&tmp, tag); /* Fortunately, this can't overflow |
81 | 128 bits precision. */ | 54 | to 2^64 */ |
82 | 55 | q = significand(&tmp); | |
83 | significand(&tmp) = q + 1; | 56 | if (q) { |
84 | setexponent16(&tmp, 63); | 57 | rem_kernel(significand(st0_ptr), |
85 | FPU_normalize(&tmp); | 58 | &significand(&tmp), |
86 | tmptag = | 59 | significand(&CONST_PI2), |
87 | FPU_u_mul(&CONST_PI2extra, &tmp, &tmp, FULL_PRECISION, SIGN_POS, | 60 | q, exponent(st0_ptr) - exponent(&CONST_PI2)); |
88 | exponent(&CONST_PI2extra) + exponent(&tmp)); | 61 | setexponent16(&tmp, exponent(&CONST_PI2)); |
89 | setsign(&tmp, getsign(&CONST_PI2extra)); | 62 | st0_tag = FPU_normalize(&tmp); |
90 | st0_tag = FPU_add(&tmp, tmptag, 0, FULL_PRECISION); | 63 | FPU_copy_to_reg0(&tmp, st0_tag); |
91 | if ( signnegative(st0_ptr) ) | ||
92 | { | ||
93 | /* CONST_PI2extra is negative, so the result of the addition | ||
94 | can be negative. This means that the argument is actually | ||
95 | in a different quadrant. The correction is always < pi/2, | ||
96 | so it can't overflow into yet another quadrant. */ | ||
97 | setpositive(st0_ptr); | ||
98 | q++; | ||
99 | } | ||
100 | } | 64 | } |
65 | |||
66 | if ((even && !(q & 1)) || (!even && (q & 1))) { | ||
67 | st0_tag = | ||
68 | FPU_sub(REV | LOADED | TAG_Valid, (int)&CONST_PI2, | ||
69 | FULL_PRECISION); | ||
70 | |||
71 | #ifdef BETTER_THAN_486 | ||
72 | /* So far, the results are exact but based upon a 64 bit | ||
73 | precision approximation to pi/2. The technique used | ||
74 | now is equivalent to using an approximation to pi/2 which | ||
75 | is accurate to about 128 bits. */ | ||
76 | if ((exponent(st0_ptr) <= exponent(&CONST_PI2extra) + 64) | ||
77 | || (q > 1)) { | ||
78 | /* This code gives the effect of having pi/2 to better than | ||
79 | 128 bits precision. */ | ||
80 | |||
81 | significand(&tmp) = q + 1; | ||
82 | setexponent16(&tmp, 63); | ||
83 | FPU_normalize(&tmp); | ||
84 | tmptag = | ||
85 | FPU_u_mul(&CONST_PI2extra, &tmp, &tmp, | ||
86 | FULL_PRECISION, SIGN_POS, | ||
87 | exponent(&CONST_PI2extra) + | ||
88 | exponent(&tmp)); | ||
89 | setsign(&tmp, getsign(&CONST_PI2extra)); | ||
90 | st0_tag = FPU_add(&tmp, tmptag, 0, FULL_PRECISION); | ||
91 | if (signnegative(st0_ptr)) { | ||
92 | /* CONST_PI2extra is negative, so the result of the addition | ||
93 | can be negative. This means that the argument is actually | ||
94 | in a different quadrant. The correction is always < pi/2, | ||
95 | so it can't overflow into yet another quadrant. */ | ||
96 | setpositive(st0_ptr); | ||
97 | q++; | ||
98 | } | ||
99 | } | ||
101 | #endif /* BETTER_THAN_486 */ | 100 | #endif /* BETTER_THAN_486 */ |
102 | } | 101 | } |
103 | #ifdef BETTER_THAN_486 | 102 | #ifdef BETTER_THAN_486 |
104 | else | 103 | else { |
105 | { | 104 | /* So far, the results are exact but based upon a 64 bit |
106 | /* So far, the results are exact but based upon a 64 bit | 105 | precision approximation to pi/2. The technique used |
107 | precision approximation to pi/2. The technique used | 106 | now is equivalent to using an approximation to pi/2 which |
108 | now is equivalent to using an approximation to pi/2 which | 107 | is accurate to about 128 bits. */ |
109 | is accurate to about 128 bits. */ | 108 | if (((q > 0) |
110 | if ( ((q > 0) && (exponent(st0_ptr) <= exponent(&CONST_PI2extra) + 64)) | 109 | && (exponent(st0_ptr) <= exponent(&CONST_PI2extra) + 64)) |
111 | || (q > 1) ) | 110 | || (q > 1)) { |
112 | { | 111 | /* This code gives the effect of having p/2 to better than |
113 | /* This code gives the effect of having p/2 to better than | 112 | 128 bits precision. */ |
114 | 128 bits precision. */ | 113 | |
115 | 114 | significand(&tmp) = q; | |
116 | significand(&tmp) = q; | 115 | setexponent16(&tmp, 63); |
117 | setexponent16(&tmp, 63); | 116 | FPU_normalize(&tmp); /* This must return TAG_Valid */ |
118 | FPU_normalize(&tmp); /* This must return TAG_Valid */ | 117 | tmptag = |
119 | tmptag = FPU_u_mul(&CONST_PI2extra, &tmp, &tmp, FULL_PRECISION, | 118 | FPU_u_mul(&CONST_PI2extra, &tmp, &tmp, |
120 | SIGN_POS, | 119 | FULL_PRECISION, SIGN_POS, |
121 | exponent(&CONST_PI2extra) + exponent(&tmp)); | 120 | exponent(&CONST_PI2extra) + |
122 | setsign(&tmp, getsign(&CONST_PI2extra)); | 121 | exponent(&tmp)); |
123 | st0_tag = FPU_sub(LOADED|(tmptag & 0x0f), (int)&tmp, | 122 | setsign(&tmp, getsign(&CONST_PI2extra)); |
124 | FULL_PRECISION); | 123 | st0_tag = FPU_sub(LOADED | (tmptag & 0x0f), (int)&tmp, |
125 | if ( (exponent(st0_ptr) == exponent(&CONST_PI2)) && | 124 | FULL_PRECISION); |
126 | ((st0_ptr->sigh > CONST_PI2.sigh) | 125 | if ((exponent(st0_ptr) == exponent(&CONST_PI2)) && |
127 | || ((st0_ptr->sigh == CONST_PI2.sigh) | 126 | ((st0_ptr->sigh > CONST_PI2.sigh) |
128 | && (st0_ptr->sigl > CONST_PI2.sigl))) ) | 127 | || ((st0_ptr->sigh == CONST_PI2.sigh) |
129 | { | 128 | && (st0_ptr->sigl > CONST_PI2.sigl)))) { |
130 | /* CONST_PI2extra is negative, so the result of the | 129 | /* CONST_PI2extra is negative, so the result of the |
131 | subtraction can be larger than pi/2. This means | 130 | subtraction can be larger than pi/2. This means |
132 | that the argument is actually in a different quadrant. | 131 | that the argument is actually in a different quadrant. |
133 | The correction is always < pi/2, so it can't overflow | 132 | The correction is always < pi/2, so it can't overflow |
134 | into yet another quadrant. */ | 133 | into yet another quadrant. */ |
135 | st0_tag = FPU_sub(REV|LOADED|TAG_Valid, (int)&CONST_PI2, | 134 | st0_tag = |
136 | FULL_PRECISION); | 135 | FPU_sub(REV | LOADED | TAG_Valid, |
137 | q++; | 136 | (int)&CONST_PI2, FULL_PRECISION); |
138 | } | 137 | q++; |
138 | } | ||
139 | } | ||
139 | } | 140 | } |
140 | } | ||
141 | #endif /* BETTER_THAN_486 */ | 141 | #endif /* BETTER_THAN_486 */ |
142 | 142 | ||
143 | FPU_settag0(st0_tag); | 143 | FPU_settag0(st0_tag); |
144 | control_word = old_cw; | 144 | control_word = old_cw; |
145 | partial_status = saved_status & ~SW_C2; /* Reduction complete. */ | 145 | partial_status = saved_status & ~SW_C2; /* Reduction complete. */ |
146 | 146 | ||
147 | return (q & 3) | even; | 147 | return (q & 3) | even; |
148 | } | 148 | } |
149 | 149 | ||
150 | |||
151 | /* Convert a long to register */ | 150 | /* Convert a long to register */ |
152 | static void convert_l2reg(long const *arg, int deststnr) | 151 | static void convert_l2reg(long const *arg, int deststnr) |
153 | { | 152 | { |
154 | int tag; | 153 | int tag; |
155 | long num = *arg; | 154 | long num = *arg; |
156 | u_char sign; | 155 | u_char sign; |
157 | FPU_REG *dest = &st(deststnr); | 156 | FPU_REG *dest = &st(deststnr); |
158 | |||
159 | if (num == 0) | ||
160 | { | ||
161 | FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr); | ||
162 | return; | ||
163 | } | ||
164 | |||
165 | if (num > 0) | ||
166 | { sign = SIGN_POS; } | ||
167 | else | ||
168 | { num = -num; sign = SIGN_NEG; } | ||
169 | |||
170 | dest->sigh = num; | ||
171 | dest->sigl = 0; | ||
172 | setexponent16(dest, 31); | ||
173 | tag = FPU_normalize(dest); | ||
174 | FPU_settagi(deststnr, tag); | ||
175 | setsign(dest, sign); | ||
176 | return; | ||
177 | } | ||
178 | 157 | ||
158 | if (num == 0) { | ||
159 | FPU_copy_to_regi(&CONST_Z, TAG_Zero, deststnr); | ||
160 | return; | ||
161 | } | ||
162 | |||
163 | if (num > 0) { | ||
164 | sign = SIGN_POS; | ||
165 | } else { | ||
166 | num = -num; | ||
167 | sign = SIGN_NEG; | ||
168 | } | ||
179 | 169 | ||
180 | static void single_arg_error(FPU_REG *st0_ptr, u_char st0_tag) | 170 | dest->sigh = num; |
171 | dest->sigl = 0; | ||
172 | setexponent16(dest, 31); | ||
173 | tag = FPU_normalize(dest); | ||
174 | FPU_settagi(deststnr, tag); | ||
175 | setsign(dest, sign); | ||
176 | return; | ||
177 | } | ||
178 | |||
179 | static void single_arg_error(FPU_REG * st0_ptr, u_char st0_tag) | ||
181 | { | 180 | { |
182 | if ( st0_tag == TAG_Empty ) | 181 | if (st0_tag == TAG_Empty) |
183 | FPU_stack_underflow(); /* Puts a QNaN in st(0) */ | 182 | FPU_stack_underflow(); /* Puts a QNaN in st(0) */ |
184 | else if ( st0_tag == TW_NaN ) | 183 | else if (st0_tag == TW_NaN) |
185 | real_1op_NaN(st0_ptr); /* return with a NaN in st(0) */ | 184 | real_1op_NaN(st0_ptr); /* return with a NaN in st(0) */ |
186 | #ifdef PARANOID | 185 | #ifdef PARANOID |
187 | else | 186 | else |
188 | EXCEPTION(EX_INTERNAL|0x0112); | 187 | EXCEPTION(EX_INTERNAL | 0x0112); |
189 | #endif /* PARANOID */ | 188 | #endif /* PARANOID */ |
190 | } | 189 | } |
191 | 190 | ||
192 | 191 | static void single_arg_2_error(FPU_REG * st0_ptr, u_char st0_tag) | |
193 | static void single_arg_2_error(FPU_REG *st0_ptr, u_char st0_tag) | ||
194 | { | 192 | { |
195 | int isNaN; | 193 | int isNaN; |
196 | 194 | ||
197 | switch ( st0_tag ) | 195 | switch (st0_tag) { |
198 | { | 196 | case TW_NaN: |
199 | case TW_NaN: | 197 | isNaN = (exponent(st0_ptr) == EXP_OVER) |
200 | isNaN = (exponent(st0_ptr) == EXP_OVER) && (st0_ptr->sigh & 0x80000000); | 198 | && (st0_ptr->sigh & 0x80000000); |
201 | if ( isNaN && !(st0_ptr->sigh & 0x40000000) ) /* Signaling ? */ | 199 | if (isNaN && !(st0_ptr->sigh & 0x40000000)) { /* Signaling ? */ |
202 | { | 200 | EXCEPTION(EX_Invalid); |
203 | EXCEPTION(EX_Invalid); | 201 | if (control_word & CW_Invalid) { |
204 | if ( control_word & CW_Invalid ) | 202 | /* The masked response */ |
205 | { | 203 | /* Convert to a QNaN */ |
206 | /* The masked response */ | 204 | st0_ptr->sigh |= 0x40000000; |
207 | /* Convert to a QNaN */ | 205 | push(); |
208 | st0_ptr->sigh |= 0x40000000; | 206 | FPU_copy_to_reg0(st0_ptr, TAG_Special); |
209 | push(); | 207 | } |
210 | FPU_copy_to_reg0(st0_ptr, TAG_Special); | 208 | } else if (isNaN) { |
211 | } | 209 | /* A QNaN */ |
212 | } | 210 | push(); |
213 | else if ( isNaN ) | 211 | FPU_copy_to_reg0(st0_ptr, TAG_Special); |
214 | { | 212 | } else { |
215 | /* A QNaN */ | 213 | /* pseudoNaN or other unsupported */ |
216 | push(); | 214 | EXCEPTION(EX_Invalid); |
217 | FPU_copy_to_reg0(st0_ptr, TAG_Special); | 215 | if (control_word & CW_Invalid) { |
218 | } | 216 | /* The masked response */ |
219 | else | 217 | FPU_copy_to_reg0(&CONST_QNaN, TAG_Special); |
220 | { | 218 | push(); |
221 | /* pseudoNaN or other unsupported */ | 219 | FPU_copy_to_reg0(&CONST_QNaN, TAG_Special); |
222 | EXCEPTION(EX_Invalid); | 220 | } |
223 | if ( control_word & CW_Invalid ) | 221 | } |
224 | { | 222 | break; /* return with a NaN in st(0) */ |
225 | /* The masked response */ | ||
226 | FPU_copy_to_reg0(&CONST_QNaN, TAG_Special); | ||
227 | push(); | ||
228 | FPU_copy_to_reg0(&CONST_QNaN, TAG_Special); | ||
229 | } | ||
230 | } | ||
231 | break; /* return with a NaN in st(0) */ | ||
232 | #ifdef PARANOID | 223 | #ifdef PARANOID |
233 | default: | 224 | default: |
234 | EXCEPTION(EX_INTERNAL|0x0112); | 225 | EXCEPTION(EX_INTERNAL | 0x0112); |
235 | #endif /* PARANOID */ | 226 | #endif /* PARANOID */ |
236 | } | 227 | } |
237 | } | 228 | } |
238 | 229 | ||
239 | |||
240 | /*---------------------------------------------------------------------------*/ | 230 | /*---------------------------------------------------------------------------*/ |
241 | 231 | ||
242 | static void f2xm1(FPU_REG *st0_ptr, u_char tag) | 232 | static void f2xm1(FPU_REG * st0_ptr, u_char tag) |
243 | { | 233 | { |
244 | FPU_REG a; | 234 | FPU_REG a; |
245 | 235 | ||
246 | clear_C1(); | 236 | clear_C1(); |
247 | 237 | ||
248 | if ( tag == TAG_Valid ) | 238 | if (tag == TAG_Valid) { |
249 | { | 239 | /* For an 80486 FPU, the result is undefined if the arg is >= 1.0 */ |
250 | /* For an 80486 FPU, the result is undefined if the arg is >= 1.0 */ | 240 | if (exponent(st0_ptr) < 0) { |
251 | if ( exponent(st0_ptr) < 0 ) | 241 | denormal_arg: |
252 | { | ||
253 | denormal_arg: | ||
254 | 242 | ||
255 | FPU_to_exp16(st0_ptr, &a); | 243 | FPU_to_exp16(st0_ptr, &a); |
256 | 244 | ||
257 | /* poly_2xm1(x) requires 0 < st(0) < 1. */ | 245 | /* poly_2xm1(x) requires 0 < st(0) < 1. */ |
258 | poly_2xm1(getsign(st0_ptr), &a, st0_ptr); | 246 | poly_2xm1(getsign(st0_ptr), &a, st0_ptr); |
247 | } | ||
248 | set_precision_flag_up(); /* 80486 appears to always do this */ | ||
249 | return; | ||
259 | } | 250 | } |
260 | set_precision_flag_up(); /* 80486 appears to always do this */ | ||
261 | return; | ||
262 | } | ||
263 | 251 | ||
264 | if ( tag == TAG_Zero ) | 252 | if (tag == TAG_Zero) |
265 | return; | 253 | return; |
266 | 254 | ||
267 | if ( tag == TAG_Special ) | 255 | if (tag == TAG_Special) |
268 | tag = FPU_Special(st0_ptr); | 256 | tag = FPU_Special(st0_ptr); |
269 | 257 | ||
270 | switch ( tag ) | 258 | switch (tag) { |
271 | { | 259 | case TW_Denormal: |
272 | case TW_Denormal: | 260 | if (denormal_operand() < 0) |
273 | if ( denormal_operand() < 0 ) | 261 | return; |
274 | return; | 262 | goto denormal_arg; |
275 | goto denormal_arg; | 263 | case TW_Infinity: |
276 | case TW_Infinity: | 264 | if (signnegative(st0_ptr)) { |
277 | if ( signnegative(st0_ptr) ) | 265 | /* -infinity gives -1 (p16-10) */ |
278 | { | 266 | FPU_copy_to_reg0(&CONST_1, TAG_Valid); |
279 | /* -infinity gives -1 (p16-10) */ | 267 | setnegative(st0_ptr); |
280 | FPU_copy_to_reg0(&CONST_1, TAG_Valid); | 268 | } |
281 | setnegative(st0_ptr); | 269 | return; |
270 | default: | ||
271 | single_arg_error(st0_ptr, tag); | ||
282 | } | 272 | } |
283 | return; | ||
284 | default: | ||
285 | single_arg_error(st0_ptr, tag); | ||
286 | } | ||
287 | } | 273 | } |
288 | 274 | ||
289 | 275 | static void fptan(FPU_REG * st0_ptr, u_char st0_tag) | |
290 | static void fptan(FPU_REG *st0_ptr, u_char st0_tag) | ||
291 | { | 276 | { |
292 | FPU_REG *st_new_ptr; | 277 | FPU_REG *st_new_ptr; |
293 | int q; | 278 | int q; |
294 | u_char arg_sign = getsign(st0_ptr); | 279 | u_char arg_sign = getsign(st0_ptr); |
295 | 280 | ||
296 | /* Stack underflow has higher priority */ | 281 | /* Stack underflow has higher priority */ |
297 | if ( st0_tag == TAG_Empty ) | 282 | if (st0_tag == TAG_Empty) { |
298 | { | 283 | FPU_stack_underflow(); /* Puts a QNaN in st(0) */ |
299 | FPU_stack_underflow(); /* Puts a QNaN in st(0) */ | 284 | if (control_word & CW_Invalid) { |
300 | if ( control_word & CW_Invalid ) | 285 | st_new_ptr = &st(-1); |
301 | { | 286 | push(); |
302 | st_new_ptr = &st(-1); | 287 | FPU_stack_underflow(); /* Puts a QNaN in the new st(0) */ |
303 | push(); | 288 | } |
304 | FPU_stack_underflow(); /* Puts a QNaN in the new st(0) */ | 289 | return; |
305 | } | 290 | } |
306 | return; | 291 | |
307 | } | 292 | if (STACK_OVERFLOW) { |
308 | 293 | FPU_stack_overflow(); | |
309 | if ( STACK_OVERFLOW ) | 294 | return; |
310 | { FPU_stack_overflow(); return; } | ||
311 | |||
312 | if ( st0_tag == TAG_Valid ) | ||
313 | { | ||
314 | if ( exponent(st0_ptr) > -40 ) | ||
315 | { | ||
316 | if ( (q = trig_arg(st0_ptr, 0)) == -1 ) | ||
317 | { | ||
318 | /* Operand is out of range */ | ||
319 | return; | ||
320 | } | ||
321 | |||
322 | poly_tan(st0_ptr); | ||
323 | setsign(st0_ptr, (q & 1) ^ (arg_sign != 0)); | ||
324 | set_precision_flag_up(); /* We do not really know if up or down */ | ||
325 | } | 295 | } |
326 | else | ||
327 | { | ||
328 | /* For a small arg, the result == the argument */ | ||
329 | /* Underflow may happen */ | ||
330 | 296 | ||
331 | denormal_arg: | 297 | if (st0_tag == TAG_Valid) { |
298 | if (exponent(st0_ptr) > -40) { | ||
299 | if ((q = trig_arg(st0_ptr, 0)) == -1) { | ||
300 | /* Operand is out of range */ | ||
301 | return; | ||
302 | } | ||
303 | |||
304 | poly_tan(st0_ptr); | ||
305 | setsign(st0_ptr, (q & 1) ^ (arg_sign != 0)); | ||
306 | set_precision_flag_up(); /* We do not really know if up or down */ | ||
307 | } else { | ||
308 | /* For a small arg, the result == the argument */ | ||
309 | /* Underflow may happen */ | ||
310 | |||
311 | denormal_arg: | ||
312 | |||
313 | FPU_to_exp16(st0_ptr, st0_ptr); | ||
332 | 314 | ||
333 | FPU_to_exp16(st0_ptr, st0_ptr); | 315 | st0_tag = |
334 | 316 | FPU_round(st0_ptr, 1, 0, FULL_PRECISION, arg_sign); | |
335 | st0_tag = FPU_round(st0_ptr, 1, 0, FULL_PRECISION, arg_sign); | 317 | FPU_settag0(st0_tag); |
336 | FPU_settag0(st0_tag); | 318 | } |
319 | push(); | ||
320 | FPU_copy_to_reg0(&CONST_1, TAG_Valid); | ||
321 | return; | ||
337 | } | 322 | } |
338 | push(); | ||
339 | FPU_copy_to_reg0(&CONST_1, TAG_Valid); | ||
340 | return; | ||
341 | } | ||
342 | |||
343 | if ( st0_tag == TAG_Zero ) | ||
344 | { | ||
345 | push(); | ||
346 | FPU_copy_to_reg0(&CONST_1, TAG_Valid); | ||
347 | setcc(0); | ||
348 | return; | ||
349 | } | ||
350 | |||
351 | if ( st0_tag == TAG_Special ) | ||
352 | st0_tag = FPU_Special(st0_ptr); | ||
353 | |||
354 | if ( st0_tag == TW_Denormal ) | ||
355 | { | ||
356 | if ( denormal_operand() < 0 ) | ||
357 | return; | ||
358 | 323 | ||
359 | goto denormal_arg; | 324 | if (st0_tag == TAG_Zero) { |
360 | } | 325 | push(); |
361 | 326 | FPU_copy_to_reg0(&CONST_1, TAG_Valid); | |
362 | if ( st0_tag == TW_Infinity ) | 327 | setcc(0); |
363 | { | 328 | return; |
364 | /* The 80486 treats infinity as an invalid operand */ | 329 | } |
365 | if ( arith_invalid(0) >= 0 ) | 330 | |
366 | { | 331 | if (st0_tag == TAG_Special) |
367 | st_new_ptr = &st(-1); | 332 | st0_tag = FPU_Special(st0_ptr); |
368 | push(); | 333 | |
369 | arith_invalid(0); | 334 | if (st0_tag == TW_Denormal) { |
335 | if (denormal_operand() < 0) | ||
336 | return; | ||
337 | |||
338 | goto denormal_arg; | ||
370 | } | 339 | } |
371 | return; | ||
372 | } | ||
373 | 340 | ||
374 | single_arg_2_error(st0_ptr, st0_tag); | 341 | if (st0_tag == TW_Infinity) { |
375 | } | 342 | /* The 80486 treats infinity as an invalid operand */ |
343 | if (arith_invalid(0) >= 0) { | ||
344 | st_new_ptr = &st(-1); | ||
345 | push(); | ||
346 | arith_invalid(0); | ||
347 | } | ||
348 | return; | ||
349 | } | ||
376 | 350 | ||
351 | single_arg_2_error(st0_ptr, st0_tag); | ||
352 | } | ||
377 | 353 | ||
378 | static void fxtract(FPU_REG *st0_ptr, u_char st0_tag) | 354 | static void fxtract(FPU_REG * st0_ptr, u_char st0_tag) |
379 | { | 355 | { |
380 | FPU_REG *st_new_ptr; | 356 | FPU_REG *st_new_ptr; |
381 | u_char sign; | 357 | u_char sign; |
382 | register FPU_REG *st1_ptr = st0_ptr; /* anticipate */ | 358 | register FPU_REG *st1_ptr = st0_ptr; /* anticipate */ |
383 | |||
384 | if ( STACK_OVERFLOW ) | ||
385 | { FPU_stack_overflow(); return; } | ||
386 | |||
387 | clear_C1(); | ||
388 | |||
389 | if ( st0_tag == TAG_Valid ) | ||
390 | { | ||
391 | long e; | ||
392 | |||
393 | push(); | ||
394 | sign = getsign(st1_ptr); | ||
395 | reg_copy(st1_ptr, st_new_ptr); | ||
396 | setexponent16(st_new_ptr, exponent(st_new_ptr)); | ||
397 | |||
398 | denormal_arg: | ||
399 | |||
400 | e = exponent16(st_new_ptr); | ||
401 | convert_l2reg(&e, 1); | ||
402 | setexponentpos(st_new_ptr, 0); | ||
403 | setsign(st_new_ptr, sign); | ||
404 | FPU_settag0(TAG_Valid); /* Needed if arg was a denormal */ | ||
405 | return; | ||
406 | } | ||
407 | else if ( st0_tag == TAG_Zero ) | ||
408 | { | ||
409 | sign = getsign(st0_ptr); | ||
410 | |||
411 | if ( FPU_divide_by_zero(0, SIGN_NEG) < 0 ) | ||
412 | return; | ||
413 | 359 | ||
414 | push(); | 360 | if (STACK_OVERFLOW) { |
415 | FPU_copy_to_reg0(&CONST_Z, TAG_Zero); | 361 | FPU_stack_overflow(); |
416 | setsign(st_new_ptr, sign); | 362 | return; |
417 | return; | 363 | } |
418 | } | ||
419 | 364 | ||
420 | if ( st0_tag == TAG_Special ) | 365 | clear_C1(); |
421 | st0_tag = FPU_Special(st0_ptr); | ||
422 | 366 | ||
423 | if ( st0_tag == TW_Denormal ) | 367 | if (st0_tag == TAG_Valid) { |
424 | { | 368 | long e; |
425 | if (denormal_operand() < 0 ) | ||
426 | return; | ||
427 | 369 | ||
428 | push(); | 370 | push(); |
429 | sign = getsign(st1_ptr); | 371 | sign = getsign(st1_ptr); |
430 | FPU_to_exp16(st1_ptr, st_new_ptr); | 372 | reg_copy(st1_ptr, st_new_ptr); |
431 | goto denormal_arg; | 373 | setexponent16(st_new_ptr, exponent(st_new_ptr)); |
432 | } | 374 | |
433 | else if ( st0_tag == TW_Infinity ) | 375 | denormal_arg: |
434 | { | 376 | |
435 | sign = getsign(st0_ptr); | 377 | e = exponent16(st_new_ptr); |
436 | setpositive(st0_ptr); | 378 | convert_l2reg(&e, 1); |
437 | push(); | 379 | setexponentpos(st_new_ptr, 0); |
438 | FPU_copy_to_reg0(&CONST_INF, TAG_Special); | 380 | setsign(st_new_ptr, sign); |
439 | setsign(st_new_ptr, sign); | 381 | FPU_settag0(TAG_Valid); /* Needed if arg was a denormal */ |
440 | return; | 382 | return; |
441 | } | 383 | } else if (st0_tag == TAG_Zero) { |
442 | else if ( st0_tag == TW_NaN ) | 384 | sign = getsign(st0_ptr); |
443 | { | 385 | |
444 | if ( real_1op_NaN(st0_ptr) < 0 ) | 386 | if (FPU_divide_by_zero(0, SIGN_NEG) < 0) |
445 | return; | 387 | return; |
446 | 388 | ||
447 | push(); | 389 | push(); |
448 | FPU_copy_to_reg0(st0_ptr, TAG_Special); | 390 | FPU_copy_to_reg0(&CONST_Z, TAG_Zero); |
449 | return; | 391 | setsign(st_new_ptr, sign); |
450 | } | 392 | return; |
451 | else if ( st0_tag == TAG_Empty ) | 393 | } |
452 | { | 394 | |
453 | /* Is this the correct behaviour? */ | 395 | if (st0_tag == TAG_Special) |
454 | if ( control_word & EX_Invalid ) | 396 | st0_tag = FPU_Special(st0_ptr); |
455 | { | 397 | |
456 | FPU_stack_underflow(); | 398 | if (st0_tag == TW_Denormal) { |
457 | push(); | 399 | if (denormal_operand() < 0) |
458 | FPU_stack_underflow(); | 400 | return; |
401 | |||
402 | push(); | ||
403 | sign = getsign(st1_ptr); | ||
404 | FPU_to_exp16(st1_ptr, st_new_ptr); | ||
405 | goto denormal_arg; | ||
406 | } else if (st0_tag == TW_Infinity) { | ||
407 | sign = getsign(st0_ptr); | ||
408 | setpositive(st0_ptr); | ||
409 | push(); | ||
410 | FPU_copy_to_reg0(&CONST_INF, TAG_Special); | ||
411 | setsign(st_new_ptr, sign); | ||
412 | return; | ||
413 | } else if (st0_tag == TW_NaN) { | ||
414 | if (real_1op_NaN(st0_ptr) < 0) | ||
415 | return; | ||
416 | |||
417 | push(); | ||
418 | FPU_copy_to_reg0(st0_ptr, TAG_Special); | ||
419 | return; | ||
420 | } else if (st0_tag == TAG_Empty) { | ||
421 | /* Is this the correct behaviour? */ | ||
422 | if (control_word & EX_Invalid) { | ||
423 | FPU_stack_underflow(); | ||
424 | push(); | ||
425 | FPU_stack_underflow(); | ||
426 | } else | ||
427 | EXCEPTION(EX_StackUnder); | ||
459 | } | 428 | } |
460 | else | ||
461 | EXCEPTION(EX_StackUnder); | ||
462 | } | ||
463 | #ifdef PARANOID | 429 | #ifdef PARANOID |
464 | else | 430 | else |
465 | EXCEPTION(EX_INTERNAL | 0x119); | 431 | EXCEPTION(EX_INTERNAL | 0x119); |
466 | #endif /* PARANOID */ | 432 | #endif /* PARANOID */ |
467 | } | 433 | } |
468 | 434 | ||
469 | |||
470 | static void fdecstp(void) | 435 | static void fdecstp(void) |
471 | { | 436 | { |
472 | clear_C1(); | 437 | clear_C1(); |
473 | top--; | 438 | top--; |
474 | } | 439 | } |
475 | 440 | ||
476 | static void fincstp(void) | 441 | static void fincstp(void) |
477 | { | 442 | { |
478 | clear_C1(); | 443 | clear_C1(); |
479 | top++; | 444 | top++; |
480 | } | 445 | } |
481 | 446 | ||
482 | 447 | static void fsqrt_(FPU_REG * st0_ptr, u_char st0_tag) | |
483 | static void fsqrt_(FPU_REG *st0_ptr, u_char st0_tag) | ||
484 | { | 448 | { |
485 | int expon; | 449 | int expon; |
486 | 450 | ||
487 | clear_C1(); | 451 | clear_C1(); |
488 | |||
489 | if ( st0_tag == TAG_Valid ) | ||
490 | { | ||
491 | u_char tag; | ||
492 | |||
493 | if (signnegative(st0_ptr)) | ||
494 | { | ||
495 | arith_invalid(0); /* sqrt(negative) is invalid */ | ||
496 | return; | ||
497 | } | ||
498 | 452 | ||
499 | /* make st(0) in [1.0 .. 4.0) */ | 453 | if (st0_tag == TAG_Valid) { |
500 | expon = exponent(st0_ptr); | 454 | u_char tag; |
501 | 455 | ||
502 | denormal_arg: | 456 | if (signnegative(st0_ptr)) { |
503 | 457 | arith_invalid(0); /* sqrt(negative) is invalid */ | |
504 | setexponent16(st0_ptr, (expon & 1)); | 458 | return; |
505 | 459 | } | |
506 | /* Do the computation, the sign of the result will be positive. */ | 460 | |
507 | tag = wm_sqrt(st0_ptr, 0, 0, control_word, SIGN_POS); | 461 | /* make st(0) in [1.0 .. 4.0) */ |
508 | addexponent(st0_ptr, expon >> 1); | 462 | expon = exponent(st0_ptr); |
509 | FPU_settag0(tag); | 463 | |
510 | return; | 464 | denormal_arg: |
511 | } | 465 | |
512 | 466 | setexponent16(st0_ptr, (expon & 1)); | |
513 | if ( st0_tag == TAG_Zero ) | 467 | |
514 | return; | 468 | /* Do the computation, the sign of the result will be positive. */ |
515 | 469 | tag = wm_sqrt(st0_ptr, 0, 0, control_word, SIGN_POS); | |
516 | if ( st0_tag == TAG_Special ) | 470 | addexponent(st0_ptr, expon >> 1); |
517 | st0_tag = FPU_Special(st0_ptr); | 471 | FPU_settag0(tag); |
518 | 472 | return; | |
519 | if ( st0_tag == TW_Infinity ) | ||
520 | { | ||
521 | if ( signnegative(st0_ptr) ) | ||
522 | arith_invalid(0); /* sqrt(-Infinity) is invalid */ | ||
523 | return; | ||
524 | } | ||
525 | else if ( st0_tag == TW_Denormal ) | ||
526 | { | ||
527 | if (signnegative(st0_ptr)) | ||
528 | { | ||
529 | arith_invalid(0); /* sqrt(negative) is invalid */ | ||
530 | return; | ||
531 | } | 473 | } |
532 | 474 | ||
533 | if ( denormal_operand() < 0 ) | 475 | if (st0_tag == TAG_Zero) |
534 | return; | 476 | return; |
535 | 477 | ||
536 | FPU_to_exp16(st0_ptr, st0_ptr); | 478 | if (st0_tag == TAG_Special) |
479 | st0_tag = FPU_Special(st0_ptr); | ||
537 | 480 | ||
538 | expon = exponent16(st0_ptr); | 481 | if (st0_tag == TW_Infinity) { |
482 | if (signnegative(st0_ptr)) | ||
483 | arith_invalid(0); /* sqrt(-Infinity) is invalid */ | ||
484 | return; | ||
485 | } else if (st0_tag == TW_Denormal) { | ||
486 | if (signnegative(st0_ptr)) { | ||
487 | arith_invalid(0); /* sqrt(negative) is invalid */ | ||
488 | return; | ||
489 | } | ||
539 | 490 | ||
540 | goto denormal_arg; | 491 | if (denormal_operand() < 0) |
541 | } | 492 | return; |
542 | 493 | ||
543 | single_arg_error(st0_ptr, st0_tag); | 494 | FPU_to_exp16(st0_ptr, st0_ptr); |
544 | 495 | ||
545 | } | 496 | expon = exponent16(st0_ptr); |
497 | |||
498 | goto denormal_arg; | ||
499 | } | ||
546 | 500 | ||
501 | single_arg_error(st0_ptr, st0_tag); | ||
547 | 502 | ||
548 | static void frndint_(FPU_REG *st0_ptr, u_char st0_tag) | 503 | } |
504 | |||
505 | static void frndint_(FPU_REG * st0_ptr, u_char st0_tag) | ||
549 | { | 506 | { |
550 | int flags, tag; | 507 | int flags, tag; |
551 | 508 | ||
552 | if ( st0_tag == TAG_Valid ) | 509 | if (st0_tag == TAG_Valid) { |
553 | { | 510 | u_char sign; |
554 | u_char sign; | ||
555 | 511 | ||
556 | denormal_arg: | 512 | denormal_arg: |
557 | 513 | ||
558 | sign = getsign(st0_ptr); | 514 | sign = getsign(st0_ptr); |
559 | 515 | ||
560 | if (exponent(st0_ptr) > 63) | 516 | if (exponent(st0_ptr) > 63) |
561 | return; | 517 | return; |
518 | |||
519 | if (st0_tag == TW_Denormal) { | ||
520 | if (denormal_operand() < 0) | ||
521 | return; | ||
522 | } | ||
523 | |||
524 | /* Fortunately, this can't overflow to 2^64 */ | ||
525 | if ((flags = FPU_round_to_int(st0_ptr, st0_tag))) | ||
526 | set_precision_flag(flags); | ||
562 | 527 | ||
563 | if ( st0_tag == TW_Denormal ) | 528 | setexponent16(st0_ptr, 63); |
564 | { | 529 | tag = FPU_normalize(st0_ptr); |
565 | if (denormal_operand() < 0 ) | 530 | setsign(st0_ptr, sign); |
566 | return; | 531 | FPU_settag0(tag); |
532 | return; | ||
567 | } | 533 | } |
568 | 534 | ||
569 | /* Fortunately, this can't overflow to 2^64 */ | 535 | if (st0_tag == TAG_Zero) |
570 | if ( (flags = FPU_round_to_int(st0_ptr, st0_tag)) ) | 536 | return; |
571 | set_precision_flag(flags); | ||
572 | |||
573 | setexponent16(st0_ptr, 63); | ||
574 | tag = FPU_normalize(st0_ptr); | ||
575 | setsign(st0_ptr, sign); | ||
576 | FPU_settag0(tag); | ||
577 | return; | ||
578 | } | ||
579 | |||
580 | if ( st0_tag == TAG_Zero ) | ||
581 | return; | ||
582 | |||
583 | if ( st0_tag == TAG_Special ) | ||
584 | st0_tag = FPU_Special(st0_ptr); | ||
585 | |||
586 | if ( st0_tag == TW_Denormal ) | ||
587 | goto denormal_arg; | ||
588 | else if ( st0_tag == TW_Infinity ) | ||
589 | return; | ||
590 | else | ||
591 | single_arg_error(st0_ptr, st0_tag); | ||
592 | } | ||
593 | 537 | ||
538 | if (st0_tag == TAG_Special) | ||
539 | st0_tag = FPU_Special(st0_ptr); | ||
594 | 540 | ||
595 | static int fsin(FPU_REG *st0_ptr, u_char tag) | 541 | if (st0_tag == TW_Denormal) |
542 | goto denormal_arg; | ||
543 | else if (st0_tag == TW_Infinity) | ||
544 | return; | ||
545 | else | ||
546 | single_arg_error(st0_ptr, st0_tag); | ||
547 | } | ||
548 | |||
549 | static int fsin(FPU_REG * st0_ptr, u_char tag) | ||
596 | { | 550 | { |
597 | u_char arg_sign = getsign(st0_ptr); | 551 | u_char arg_sign = getsign(st0_ptr); |
598 | 552 | ||
599 | if ( tag == TAG_Valid ) | 553 | if (tag == TAG_Valid) { |
600 | { | 554 | int q; |
601 | int q; | 555 | |
602 | 556 | if (exponent(st0_ptr) > -40) { | |
603 | if ( exponent(st0_ptr) > -40 ) | 557 | if ((q = trig_arg(st0_ptr, 0)) == -1) { |
604 | { | 558 | /* Operand is out of range */ |
605 | if ( (q = trig_arg(st0_ptr, 0)) == -1 ) | 559 | return 1; |
606 | { | 560 | } |
607 | /* Operand is out of range */ | 561 | |
608 | return 1; | 562 | poly_sine(st0_ptr); |
609 | } | 563 | |
610 | 564 | if (q & 2) | |
611 | poly_sine(st0_ptr); | 565 | changesign(st0_ptr); |
612 | 566 | ||
613 | if (q & 2) | 567 | setsign(st0_ptr, getsign(st0_ptr) ^ arg_sign); |
614 | changesign(st0_ptr); | 568 | |
615 | 569 | /* We do not really know if up or down */ | |
616 | setsign(st0_ptr, getsign(st0_ptr) ^ arg_sign); | 570 | set_precision_flag_up(); |
617 | 571 | return 0; | |
618 | /* We do not really know if up or down */ | 572 | } else { |
619 | set_precision_flag_up(); | 573 | /* For a small arg, the result == the argument */ |
620 | return 0; | 574 | set_precision_flag_up(); /* Must be up. */ |
575 | return 0; | ||
576 | } | ||
621 | } | 577 | } |
622 | else | 578 | |
623 | { | 579 | if (tag == TAG_Zero) { |
624 | /* For a small arg, the result == the argument */ | 580 | setcc(0); |
625 | set_precision_flag_up(); /* Must be up. */ | 581 | return 0; |
626 | return 0; | ||
627 | } | 582 | } |
628 | } | ||
629 | |||
630 | if ( tag == TAG_Zero ) | ||
631 | { | ||
632 | setcc(0); | ||
633 | return 0; | ||
634 | } | ||
635 | |||
636 | if ( tag == TAG_Special ) | ||
637 | tag = FPU_Special(st0_ptr); | ||
638 | |||
639 | if ( tag == TW_Denormal ) | ||
640 | { | ||
641 | if ( denormal_operand() < 0 ) | ||
642 | return 1; | ||
643 | |||
644 | /* For a small arg, the result == the argument */ | ||
645 | /* Underflow may happen */ | ||
646 | FPU_to_exp16(st0_ptr, st0_ptr); | ||
647 | |||
648 | tag = FPU_round(st0_ptr, 1, 0, FULL_PRECISION, arg_sign); | ||
649 | |||
650 | FPU_settag0(tag); | ||
651 | |||
652 | return 0; | ||
653 | } | ||
654 | else if ( tag == TW_Infinity ) | ||
655 | { | ||
656 | /* The 80486 treats infinity as an invalid operand */ | ||
657 | arith_invalid(0); | ||
658 | return 1; | ||
659 | } | ||
660 | else | ||
661 | { | ||
662 | single_arg_error(st0_ptr, tag); | ||
663 | return 1; | ||
664 | } | ||
665 | } | ||
666 | 583 | ||
584 | if (tag == TAG_Special) | ||
585 | tag = FPU_Special(st0_ptr); | ||
667 | 586 | ||
668 | static int f_cos(FPU_REG *st0_ptr, u_char tag) | 587 | if (tag == TW_Denormal) { |
669 | { | 588 | if (denormal_operand() < 0) |
670 | u_char st0_sign; | 589 | return 1; |
671 | 590 | ||
672 | st0_sign = getsign(st0_ptr); | 591 | /* For a small arg, the result == the argument */ |
673 | 592 | /* Underflow may happen */ | |
674 | if ( tag == TAG_Valid ) | 593 | FPU_to_exp16(st0_ptr, st0_ptr); |
675 | { | 594 | |
676 | int q; | 595 | tag = FPU_round(st0_ptr, 1, 0, FULL_PRECISION, arg_sign); |
677 | 596 | ||
678 | if ( exponent(st0_ptr) > -40 ) | 597 | FPU_settag0(tag); |
679 | { | 598 | |
680 | if ( (exponent(st0_ptr) < 0) | 599 | return 0; |
681 | || ((exponent(st0_ptr) == 0) | 600 | } else if (tag == TW_Infinity) { |
682 | && (significand(st0_ptr) <= 0xc90fdaa22168c234LL)) ) | 601 | /* The 80486 treats infinity as an invalid operand */ |
683 | { | 602 | arith_invalid(0); |
684 | poly_cos(st0_ptr); | 603 | return 1; |
685 | 604 | } else { | |
686 | /* We do not really know if up or down */ | 605 | single_arg_error(st0_ptr, tag); |
687 | set_precision_flag_down(); | 606 | return 1; |
688 | |||
689 | return 0; | ||
690 | } | ||
691 | else if ( (q = trig_arg(st0_ptr, FCOS)) != -1 ) | ||
692 | { | ||
693 | poly_sine(st0_ptr); | ||
694 | |||
695 | if ((q+1) & 2) | ||
696 | changesign(st0_ptr); | ||
697 | |||
698 | /* We do not really know if up or down */ | ||
699 | set_precision_flag_down(); | ||
700 | |||
701 | return 0; | ||
702 | } | ||
703 | else | ||
704 | { | ||
705 | /* Operand is out of range */ | ||
706 | return 1; | ||
707 | } | ||
708 | } | 607 | } |
709 | else | 608 | } |
710 | { | 609 | |
711 | denormal_arg: | 610 | static int f_cos(FPU_REG * st0_ptr, u_char tag) |
611 | { | ||
612 | u_char st0_sign; | ||
613 | |||
614 | st0_sign = getsign(st0_ptr); | ||
712 | 615 | ||
713 | setcc(0); | 616 | if (tag == TAG_Valid) { |
714 | FPU_copy_to_reg0(&CONST_1, TAG_Valid); | 617 | int q; |
618 | |||
619 | if (exponent(st0_ptr) > -40) { | ||
620 | if ((exponent(st0_ptr) < 0) | ||
621 | || ((exponent(st0_ptr) == 0) | ||
622 | && (significand(st0_ptr) <= | ||
623 | 0xc90fdaa22168c234LL))) { | ||
624 | poly_cos(st0_ptr); | ||
625 | |||
626 | /* We do not really know if up or down */ | ||
627 | set_precision_flag_down(); | ||
628 | |||
629 | return 0; | ||
630 | } else if ((q = trig_arg(st0_ptr, FCOS)) != -1) { | ||
631 | poly_sine(st0_ptr); | ||
632 | |||
633 | if ((q + 1) & 2) | ||
634 | changesign(st0_ptr); | ||
635 | |||
636 | /* We do not really know if up or down */ | ||
637 | set_precision_flag_down(); | ||
638 | |||
639 | return 0; | ||
640 | } else { | ||
641 | /* Operand is out of range */ | ||
642 | return 1; | ||
643 | } | ||
644 | } else { | ||
645 | denormal_arg: | ||
646 | |||
647 | setcc(0); | ||
648 | FPU_copy_to_reg0(&CONST_1, TAG_Valid); | ||
715 | #ifdef PECULIAR_486 | 649 | #ifdef PECULIAR_486 |
716 | set_precision_flag_down(); /* 80486 appears to do this. */ | 650 | set_precision_flag_down(); /* 80486 appears to do this. */ |
717 | #else | 651 | #else |
718 | set_precision_flag_up(); /* Must be up. */ | 652 | set_precision_flag_up(); /* Must be up. */ |
719 | #endif /* PECULIAR_486 */ | 653 | #endif /* PECULIAR_486 */ |
720 | return 0; | 654 | return 0; |
655 | } | ||
656 | } else if (tag == TAG_Zero) { | ||
657 | FPU_copy_to_reg0(&CONST_1, TAG_Valid); | ||
658 | setcc(0); | ||
659 | return 0; | ||
721 | } | 660 | } |
722 | } | ||
723 | else if ( tag == TAG_Zero ) | ||
724 | { | ||
725 | FPU_copy_to_reg0(&CONST_1, TAG_Valid); | ||
726 | setcc(0); | ||
727 | return 0; | ||
728 | } | ||
729 | |||
730 | if ( tag == TAG_Special ) | ||
731 | tag = FPU_Special(st0_ptr); | ||
732 | |||
733 | if ( tag == TW_Denormal ) | ||
734 | { | ||
735 | if ( denormal_operand() < 0 ) | ||
736 | return 1; | ||
737 | |||
738 | goto denormal_arg; | ||
739 | } | ||
740 | else if ( tag == TW_Infinity ) | ||
741 | { | ||
742 | /* The 80486 treats infinity as an invalid operand */ | ||
743 | arith_invalid(0); | ||
744 | return 1; | ||
745 | } | ||
746 | else | ||
747 | { | ||
748 | single_arg_error(st0_ptr, tag); /* requires st0_ptr == &st(0) */ | ||
749 | return 1; | ||
750 | } | ||
751 | } | ||
752 | 661 | ||
662 | if (tag == TAG_Special) | ||
663 | tag = FPU_Special(st0_ptr); | ||
664 | |||
665 | if (tag == TW_Denormal) { | ||
666 | if (denormal_operand() < 0) | ||
667 | return 1; | ||
668 | |||
669 | goto denormal_arg; | ||
670 | } else if (tag == TW_Infinity) { | ||
671 | /* The 80486 treats infinity as an invalid operand */ | ||
672 | arith_invalid(0); | ||
673 | return 1; | ||
674 | } else { | ||
675 | single_arg_error(st0_ptr, tag); /* requires st0_ptr == &st(0) */ | ||
676 | return 1; | ||
677 | } | ||
678 | } | ||
753 | 679 | ||
754 | static void fcos(FPU_REG *st0_ptr, u_char st0_tag) | 680 | static void fcos(FPU_REG * st0_ptr, u_char st0_tag) |
755 | { | 681 | { |
756 | f_cos(st0_ptr, st0_tag); | 682 | f_cos(st0_ptr, st0_tag); |
757 | } | 683 | } |
758 | 684 | ||
759 | 685 | static void fsincos(FPU_REG * st0_ptr, u_char st0_tag) | |
760 | static void fsincos(FPU_REG *st0_ptr, u_char st0_tag) | ||
761 | { | 686 | { |
762 | FPU_REG *st_new_ptr; | 687 | FPU_REG *st_new_ptr; |
763 | FPU_REG arg; | 688 | FPU_REG arg; |
764 | u_char tag; | 689 | u_char tag; |
765 | 690 | ||
766 | /* Stack underflow has higher priority */ | 691 | /* Stack underflow has higher priority */ |
767 | if ( st0_tag == TAG_Empty ) | 692 | if (st0_tag == TAG_Empty) { |
768 | { | 693 | FPU_stack_underflow(); /* Puts a QNaN in st(0) */ |
769 | FPU_stack_underflow(); /* Puts a QNaN in st(0) */ | 694 | if (control_word & CW_Invalid) { |
770 | if ( control_word & CW_Invalid ) | 695 | st_new_ptr = &st(-1); |
771 | { | 696 | push(); |
772 | st_new_ptr = &st(-1); | 697 | FPU_stack_underflow(); /* Puts a QNaN in the new st(0) */ |
773 | push(); | 698 | } |
774 | FPU_stack_underflow(); /* Puts a QNaN in the new st(0) */ | 699 | return; |
775 | } | 700 | } |
776 | return; | 701 | |
777 | } | 702 | if (STACK_OVERFLOW) { |
778 | 703 | FPU_stack_overflow(); | |
779 | if ( STACK_OVERFLOW ) | 704 | return; |
780 | { FPU_stack_overflow(); return; } | ||
781 | |||
782 | if ( st0_tag == TAG_Special ) | ||
783 | tag = FPU_Special(st0_ptr); | ||
784 | else | ||
785 | tag = st0_tag; | ||
786 | |||
787 | if ( tag == TW_NaN ) | ||
788 | { | ||
789 | single_arg_2_error(st0_ptr, TW_NaN); | ||
790 | return; | ||
791 | } | ||
792 | else if ( tag == TW_Infinity ) | ||
793 | { | ||
794 | /* The 80486 treats infinity as an invalid operand */ | ||
795 | if ( arith_invalid(0) >= 0 ) | ||
796 | { | ||
797 | /* Masked response */ | ||
798 | push(); | ||
799 | arith_invalid(0); | ||
800 | } | 705 | } |
801 | return; | ||
802 | } | ||
803 | |||
804 | reg_copy(st0_ptr, &arg); | ||
805 | if ( !fsin(st0_ptr, st0_tag) ) | ||
806 | { | ||
807 | push(); | ||
808 | FPU_copy_to_reg0(&arg, st0_tag); | ||
809 | f_cos(&st(0), st0_tag); | ||
810 | } | ||
811 | else | ||
812 | { | ||
813 | /* An error, so restore st(0) */ | ||
814 | FPU_copy_to_reg0(&arg, st0_tag); | ||
815 | } | ||
816 | } | ||
817 | 706 | ||
707 | if (st0_tag == TAG_Special) | ||
708 | tag = FPU_Special(st0_ptr); | ||
709 | else | ||
710 | tag = st0_tag; | ||
711 | |||
712 | if (tag == TW_NaN) { | ||
713 | single_arg_2_error(st0_ptr, TW_NaN); | ||
714 | return; | ||
715 | } else if (tag == TW_Infinity) { | ||
716 | /* The 80486 treats infinity as an invalid operand */ | ||
717 | if (arith_invalid(0) >= 0) { | ||
718 | /* Masked response */ | ||
719 | push(); | ||
720 | arith_invalid(0); | ||
721 | } | ||
722 | return; | ||
723 | } | ||
724 | |||
725 | reg_copy(st0_ptr, &arg); | ||
726 | if (!fsin(st0_ptr, st0_tag)) { | ||
727 | push(); | ||
728 | FPU_copy_to_reg0(&arg, st0_tag); | ||
729 | f_cos(&st(0), st0_tag); | ||
730 | } else { | ||
731 | /* An error, so restore st(0) */ | ||
732 | FPU_copy_to_reg0(&arg, st0_tag); | ||
733 | } | ||
734 | } | ||
818 | 735 | ||
819 | /*---------------------------------------------------------------------------*/ | 736 | /*---------------------------------------------------------------------------*/ |
820 | /* The following all require two arguments: st(0) and st(1) */ | 737 | /* The following all require two arguments: st(0) and st(1) */ |
@@ -826,1020 +743,901 @@ static void fsincos(FPU_REG *st0_ptr, u_char st0_tag) | |||
826 | result must be zero. | 743 | result must be zero. |
827 | */ | 744 | */ |
828 | static void rem_kernel(unsigned long long st0, unsigned long long *y, | 745 | static void rem_kernel(unsigned long long st0, unsigned long long *y, |
829 | unsigned long long st1, | 746 | unsigned long long st1, unsigned long long q, int n) |
830 | unsigned long long q, int n) | ||
831 | { | 747 | { |
832 | int dummy; | 748 | int dummy; |
833 | unsigned long long x; | 749 | unsigned long long x; |
834 | 750 | ||
835 | x = st0 << n; | 751 | x = st0 << n; |
836 | 752 | ||
837 | /* Do the required multiplication and subtraction in the one operation */ | 753 | /* Do the required multiplication and subtraction in the one operation */ |
838 | 754 | ||
839 | /* lsw x -= lsw st1 * lsw q */ | 755 | /* lsw x -= lsw st1 * lsw q */ |
840 | asm volatile ("mull %4; subl %%eax,%0; sbbl %%edx,%1" | 756 | asm volatile ("mull %4; subl %%eax,%0; sbbl %%edx,%1":"=m" |
841 | :"=m" (((unsigned *)&x)[0]), "=m" (((unsigned *)&x)[1]), | 757 | (((unsigned *)&x)[0]), "=m"(((unsigned *)&x)[1]), |
842 | "=a" (dummy) | 758 | "=a"(dummy) |
843 | :"2" (((unsigned *)&st1)[0]), "m" (((unsigned *)&q)[0]) | 759 | :"2"(((unsigned *)&st1)[0]), "m"(((unsigned *)&q)[0]) |
844 | :"%dx"); | 760 | :"%dx"); |
845 | /* msw x -= msw st1 * lsw q */ | 761 | /* msw x -= msw st1 * lsw q */ |
846 | asm volatile ("mull %3; subl %%eax,%0" | 762 | asm volatile ("mull %3; subl %%eax,%0":"=m" (((unsigned *)&x)[1]), |
847 | :"=m" (((unsigned *)&x)[1]), "=a" (dummy) | 763 | "=a"(dummy) |
848 | :"1" (((unsigned *)&st1)[1]), "m" (((unsigned *)&q)[0]) | 764 | :"1"(((unsigned *)&st1)[1]), "m"(((unsigned *)&q)[0]) |
849 | :"%dx"); | 765 | :"%dx"); |
850 | /* msw x -= lsw st1 * msw q */ | 766 | /* msw x -= lsw st1 * msw q */ |
851 | asm volatile ("mull %3; subl %%eax,%0" | 767 | asm volatile ("mull %3; subl %%eax,%0":"=m" (((unsigned *)&x)[1]), |
852 | :"=m" (((unsigned *)&x)[1]), "=a" (dummy) | 768 | "=a"(dummy) |
853 | :"1" (((unsigned *)&st1)[0]), "m" (((unsigned *)&q)[1]) | 769 | :"1"(((unsigned *)&st1)[0]), "m"(((unsigned *)&q)[1]) |
854 | :"%dx"); | 770 | :"%dx"); |
855 | 771 | ||
856 | *y = x; | 772 | *y = x; |
857 | } | 773 | } |
858 | 774 | ||
859 | |||
860 | /* Remainder of st(0) / st(1) */ | 775 | /* Remainder of st(0) / st(1) */ |
861 | /* This routine produces exact results, i.e. there is never any | 776 | /* This routine produces exact results, i.e. there is never any |
862 | rounding or truncation, etc of the result. */ | 777 | rounding or truncation, etc of the result. */ |
863 | static void do_fprem(FPU_REG *st0_ptr, u_char st0_tag, int round) | 778 | static void do_fprem(FPU_REG * st0_ptr, u_char st0_tag, int round) |
864 | { | 779 | { |
865 | FPU_REG *st1_ptr = &st(1); | 780 | FPU_REG *st1_ptr = &st(1); |
866 | u_char st1_tag = FPU_gettagi(1); | 781 | u_char st1_tag = FPU_gettagi(1); |
867 | 782 | ||
868 | if ( !((st0_tag ^ TAG_Valid) | (st1_tag ^ TAG_Valid)) ) | 783 | if (!((st0_tag ^ TAG_Valid) | (st1_tag ^ TAG_Valid))) { |
869 | { | 784 | FPU_REG tmp, st0, st1; |
870 | FPU_REG tmp, st0, st1; | 785 | u_char st0_sign, st1_sign; |
871 | u_char st0_sign, st1_sign; | 786 | u_char tmptag; |
872 | u_char tmptag; | 787 | int tag; |
873 | int tag; | 788 | int old_cw; |
874 | int old_cw; | 789 | int expdif; |
875 | int expdif; | 790 | long long q; |
876 | long long q; | 791 | unsigned short saved_status; |
877 | unsigned short saved_status; | 792 | int cc; |
878 | int cc; | 793 | |
879 | 794 | fprem_valid: | |
880 | fprem_valid: | 795 | /* Convert registers for internal use. */ |
881 | /* Convert registers for internal use. */ | 796 | st0_sign = FPU_to_exp16(st0_ptr, &st0); |
882 | st0_sign = FPU_to_exp16(st0_ptr, &st0); | 797 | st1_sign = FPU_to_exp16(st1_ptr, &st1); |
883 | st1_sign = FPU_to_exp16(st1_ptr, &st1); | 798 | expdif = exponent16(&st0) - exponent16(&st1); |
884 | expdif = exponent16(&st0) - exponent16(&st1); | 799 | |
885 | 800 | old_cw = control_word; | |
886 | old_cw = control_word; | 801 | cc = 0; |
887 | cc = 0; | 802 | |
888 | 803 | /* We want the status following the denorm tests, but don't want | |
889 | /* We want the status following the denorm tests, but don't want | 804 | the status changed by the arithmetic operations. */ |
890 | the status changed by the arithmetic operations. */ | 805 | saved_status = partial_status; |
891 | saved_status = partial_status; | 806 | control_word &= ~CW_RC; |
892 | control_word &= ~CW_RC; | 807 | control_word |= RC_CHOP; |
893 | control_word |= RC_CHOP; | 808 | |
894 | 809 | if (expdif < 64) { | |
895 | if ( expdif < 64 ) | 810 | /* This should be the most common case */ |
896 | { | 811 | |
897 | /* This should be the most common case */ | 812 | if (expdif > -2) { |
898 | 813 | u_char sign = st0_sign ^ st1_sign; | |
899 | if ( expdif > -2 ) | 814 | tag = FPU_u_div(&st0, &st1, &tmp, |
900 | { | 815 | PR_64_BITS | RC_CHOP | 0x3f, |
901 | u_char sign = st0_sign ^ st1_sign; | 816 | sign); |
902 | tag = FPU_u_div(&st0, &st1, &tmp, | 817 | setsign(&tmp, sign); |
903 | PR_64_BITS | RC_CHOP | 0x3f, | 818 | |
904 | sign); | 819 | if (exponent(&tmp) >= 0) { |
905 | setsign(&tmp, sign); | 820 | FPU_round_to_int(&tmp, tag); /* Fortunately, this can't |
906 | 821 | overflow to 2^64 */ | |
907 | if ( exponent(&tmp) >= 0 ) | 822 | q = significand(&tmp); |
908 | { | 823 | |
909 | FPU_round_to_int(&tmp, tag); /* Fortunately, this can't | 824 | rem_kernel(significand(&st0), |
910 | overflow to 2^64 */ | 825 | &significand(&tmp), |
911 | q = significand(&tmp); | 826 | significand(&st1), |
912 | 827 | q, expdif); | |
913 | rem_kernel(significand(&st0), | 828 | |
914 | &significand(&tmp), | 829 | setexponent16(&tmp, exponent16(&st1)); |
915 | significand(&st1), | 830 | } else { |
916 | q, expdif); | 831 | reg_copy(&st0, &tmp); |
917 | 832 | q = 0; | |
918 | setexponent16(&tmp, exponent16(&st1)); | 833 | } |
919 | } | 834 | |
920 | else | 835 | if ((round == RC_RND) |
921 | { | 836 | && (tmp.sigh & 0xc0000000)) { |
922 | reg_copy(&st0, &tmp); | 837 | /* We may need to subtract st(1) once more, |
923 | q = 0; | 838 | to get a result <= 1/2 of st(1). */ |
924 | } | 839 | unsigned long long x; |
925 | 840 | expdif = | |
926 | if ( (round == RC_RND) && (tmp.sigh & 0xc0000000) ) | 841 | exponent16(&st1) - exponent16(&tmp); |
927 | { | 842 | if (expdif <= 1) { |
928 | /* We may need to subtract st(1) once more, | 843 | if (expdif == 0) |
929 | to get a result <= 1/2 of st(1). */ | 844 | x = significand(&st1) - |
930 | unsigned long long x; | 845 | significand(&tmp); |
931 | expdif = exponent16(&st1) - exponent16(&tmp); | 846 | else /* expdif is 1 */ |
932 | if ( expdif <= 1 ) | 847 | x = (significand(&st1) |
933 | { | 848 | << 1) - |
934 | if ( expdif == 0 ) | 849 | significand(&tmp); |
935 | x = significand(&st1) - significand(&tmp); | 850 | if ((x < significand(&tmp)) || |
936 | else /* expdif is 1 */ | 851 | /* or equi-distant (from 0 & st(1)) and q is odd */ |
937 | x = (significand(&st1) << 1) - significand(&tmp); | 852 | ((x == significand(&tmp)) |
938 | if ( (x < significand(&tmp)) || | 853 | && (q & 1))) { |
939 | /* or equi-distant (from 0 & st(1)) and q is odd */ | 854 | st0_sign = !st0_sign; |
940 | ((x == significand(&tmp)) && (q & 1) ) ) | 855 | significand(&tmp) = x; |
941 | { | 856 | q++; |
942 | st0_sign = ! st0_sign; | 857 | } |
943 | significand(&tmp) = x; | 858 | } |
944 | q++; | 859 | } |
860 | |||
861 | if (q & 4) | ||
862 | cc |= SW_C0; | ||
863 | if (q & 2) | ||
864 | cc |= SW_C3; | ||
865 | if (q & 1) | ||
866 | cc |= SW_C1; | ||
867 | } else { | ||
868 | control_word = old_cw; | ||
869 | setcc(0); | ||
870 | return; | ||
945 | } | 871 | } |
946 | } | 872 | } else { |
947 | } | 873 | /* There is a large exponent difference ( >= 64 ) */ |
948 | 874 | /* To make much sense, the code in this section should | |
949 | if (q & 4) cc |= SW_C0; | 875 | be done at high precision. */ |
950 | if (q & 2) cc |= SW_C3; | 876 | int exp_1, N; |
951 | if (q & 1) cc |= SW_C1; | 877 | u_char sign; |
952 | } | 878 | |
953 | else | 879 | /* prevent overflow here */ |
954 | { | 880 | /* N is 'a number between 32 and 63' (p26-113) */ |
955 | control_word = old_cw; | 881 | reg_copy(&st0, &tmp); |
956 | setcc(0); | 882 | tmptag = st0_tag; |
957 | return; | 883 | N = (expdif & 0x0000001f) + 32; /* This choice gives results |
958 | } | 884 | identical to an AMD 486 */ |
959 | } | 885 | setexponent16(&tmp, N); |
960 | else | 886 | exp_1 = exponent16(&st1); |
961 | { | 887 | setexponent16(&st1, 0); |
962 | /* There is a large exponent difference ( >= 64 ) */ | 888 | expdif -= N; |
963 | /* To make much sense, the code in this section should | 889 | |
964 | be done at high precision. */ | 890 | sign = getsign(&tmp) ^ st1_sign; |
965 | int exp_1, N; | 891 | tag = |
966 | u_char sign; | 892 | FPU_u_div(&tmp, &st1, &tmp, |
967 | 893 | PR_64_BITS | RC_CHOP | 0x3f, sign); | |
968 | /* prevent overflow here */ | 894 | setsign(&tmp, sign); |
969 | /* N is 'a number between 32 and 63' (p26-113) */ | 895 | |
970 | reg_copy(&st0, &tmp); | 896 | FPU_round_to_int(&tmp, tag); /* Fortunately, this can't |
971 | tmptag = st0_tag; | 897 | overflow to 2^64 */ |
972 | N = (expdif & 0x0000001f) + 32; /* This choice gives results | 898 | |
973 | identical to an AMD 486 */ | 899 | rem_kernel(significand(&st0), |
974 | setexponent16(&tmp, N); | 900 | &significand(&tmp), |
975 | exp_1 = exponent16(&st1); | 901 | significand(&st1), |
976 | setexponent16(&st1, 0); | 902 | significand(&tmp), exponent(&tmp) |
977 | expdif -= N; | 903 | ); |
978 | 904 | setexponent16(&tmp, exp_1 + expdif); | |
979 | sign = getsign(&tmp) ^ st1_sign; | 905 | |
980 | tag = FPU_u_div(&tmp, &st1, &tmp, PR_64_BITS | RC_CHOP | 0x3f, | 906 | /* It is possible for the operation to be complete here. |
981 | sign); | 907 | What does the IEEE standard say? The Intel 80486 manual |
982 | setsign(&tmp, sign); | 908 | implies that the operation will never be completed at this |
983 | 909 | point, and the behaviour of a real 80486 confirms this. | |
984 | FPU_round_to_int(&tmp, tag); /* Fortunately, this can't | 910 | */ |
985 | overflow to 2^64 */ | 911 | if (!(tmp.sigh | tmp.sigl)) { |
986 | 912 | /* The result is zero */ | |
987 | rem_kernel(significand(&st0), | 913 | control_word = old_cw; |
988 | &significand(&tmp), | 914 | partial_status = saved_status; |
989 | significand(&st1), | 915 | FPU_copy_to_reg0(&CONST_Z, TAG_Zero); |
990 | significand(&tmp), | 916 | setsign(&st0, st0_sign); |
991 | exponent(&tmp) | ||
992 | ); | ||
993 | setexponent16(&tmp, exp_1 + expdif); | ||
994 | |||
995 | /* It is possible for the operation to be complete here. | ||
996 | What does the IEEE standard say? The Intel 80486 manual | ||
997 | implies that the operation will never be completed at this | ||
998 | point, and the behaviour of a real 80486 confirms this. | ||
999 | */ | ||
1000 | if ( !(tmp.sigh | tmp.sigl) ) | ||
1001 | { | ||
1002 | /* The result is zero */ | ||
1003 | control_word = old_cw; | ||
1004 | partial_status = saved_status; | ||
1005 | FPU_copy_to_reg0(&CONST_Z, TAG_Zero); | ||
1006 | setsign(&st0, st0_sign); | ||
1007 | #ifdef PECULIAR_486 | 917 | #ifdef PECULIAR_486 |
1008 | setcc(SW_C2); | 918 | setcc(SW_C2); |
1009 | #else | 919 | #else |
1010 | setcc(0); | 920 | setcc(0); |
1011 | #endif /* PECULIAR_486 */ | 921 | #endif /* PECULIAR_486 */ |
1012 | return; | 922 | return; |
1013 | } | 923 | } |
1014 | cc = SW_C2; | 924 | cc = SW_C2; |
1015 | } | 925 | } |
1016 | 926 | ||
1017 | control_word = old_cw; | 927 | control_word = old_cw; |
1018 | partial_status = saved_status; | 928 | partial_status = saved_status; |
1019 | tag = FPU_normalize_nuo(&tmp); | 929 | tag = FPU_normalize_nuo(&tmp); |
1020 | reg_copy(&tmp, st0_ptr); | 930 | reg_copy(&tmp, st0_ptr); |
1021 | 931 | ||
1022 | /* The only condition to be looked for is underflow, | 932 | /* The only condition to be looked for is underflow, |
1023 | and it can occur here only if underflow is unmasked. */ | 933 | and it can occur here only if underflow is unmasked. */ |
1024 | if ( (exponent16(&tmp) <= EXP_UNDER) && (tag != TAG_Zero) | 934 | if ((exponent16(&tmp) <= EXP_UNDER) && (tag != TAG_Zero) |
1025 | && !(control_word & CW_Underflow) ) | 935 | && !(control_word & CW_Underflow)) { |
1026 | { | 936 | setcc(cc); |
1027 | setcc(cc); | 937 | tag = arith_underflow(st0_ptr); |
1028 | tag = arith_underflow(st0_ptr); | 938 | setsign(st0_ptr, st0_sign); |
1029 | setsign(st0_ptr, st0_sign); | 939 | FPU_settag0(tag); |
1030 | FPU_settag0(tag); | 940 | return; |
1031 | return; | 941 | } else if ((exponent16(&tmp) > EXP_UNDER) || (tag == TAG_Zero)) { |
1032 | } | 942 | stdexp(st0_ptr); |
1033 | else if ( (exponent16(&tmp) > EXP_UNDER) || (tag == TAG_Zero) ) | 943 | setsign(st0_ptr, st0_sign); |
1034 | { | 944 | } else { |
1035 | stdexp(st0_ptr); | 945 | tag = |
1036 | setsign(st0_ptr, st0_sign); | 946 | FPU_round(st0_ptr, 0, 0, FULL_PRECISION, st0_sign); |
1037 | } | 947 | } |
1038 | else | 948 | FPU_settag0(tag); |
1039 | { | 949 | setcc(cc); |
1040 | tag = FPU_round(st0_ptr, 0, 0, FULL_PRECISION, st0_sign); | ||
1041 | } | ||
1042 | FPU_settag0(tag); | ||
1043 | setcc(cc); | ||
1044 | 950 | ||
1045 | return; | 951 | return; |
1046 | } | 952 | } |
1047 | 953 | ||
1048 | if ( st0_tag == TAG_Special ) | 954 | if (st0_tag == TAG_Special) |
1049 | st0_tag = FPU_Special(st0_ptr); | 955 | st0_tag = FPU_Special(st0_ptr); |
1050 | if ( st1_tag == TAG_Special ) | 956 | if (st1_tag == TAG_Special) |
1051 | st1_tag = FPU_Special(st1_ptr); | 957 | st1_tag = FPU_Special(st1_ptr); |
1052 | 958 | ||
1053 | if ( ((st0_tag == TAG_Valid) && (st1_tag == TW_Denormal)) | 959 | if (((st0_tag == TAG_Valid) && (st1_tag == TW_Denormal)) |
1054 | || ((st0_tag == TW_Denormal) && (st1_tag == TAG_Valid)) | 960 | || ((st0_tag == TW_Denormal) && (st1_tag == TAG_Valid)) |
1055 | || ((st0_tag == TW_Denormal) && (st1_tag == TW_Denormal)) ) | 961 | || ((st0_tag == TW_Denormal) && (st1_tag == TW_Denormal))) { |
1056 | { | 962 | if (denormal_operand() < 0) |
1057 | if ( denormal_operand() < 0 ) | 963 | return; |
1058 | return; | 964 | goto fprem_valid; |
1059 | goto fprem_valid; | 965 | } else if ((st0_tag == TAG_Empty) || (st1_tag == TAG_Empty)) { |
1060 | } | 966 | FPU_stack_underflow(); |
1061 | else if ( (st0_tag == TAG_Empty) || (st1_tag == TAG_Empty) ) | 967 | return; |
1062 | { | 968 | } else if (st0_tag == TAG_Zero) { |
1063 | FPU_stack_underflow(); | 969 | if (st1_tag == TAG_Valid) { |
1064 | return; | 970 | setcc(0); |
1065 | } | 971 | return; |
1066 | else if ( st0_tag == TAG_Zero ) | 972 | } else if (st1_tag == TW_Denormal) { |
1067 | { | 973 | if (denormal_operand() < 0) |
1068 | if ( st1_tag == TAG_Valid ) | 974 | return; |
1069 | { | 975 | setcc(0); |
1070 | setcc(0); return; | 976 | return; |
1071 | } | 977 | } else if (st1_tag == TAG_Zero) { |
1072 | else if ( st1_tag == TW_Denormal ) | 978 | arith_invalid(0); |
1073 | { | 979 | return; |
1074 | if ( denormal_operand() < 0 ) | 980 | } /* fprem(?,0) always invalid */ |
1075 | return; | 981 | else if (st1_tag == TW_Infinity) { |
1076 | setcc(0); return; | 982 | setcc(0); |
1077 | } | 983 | return; |
1078 | else if ( st1_tag == TAG_Zero ) | 984 | } |
1079 | { arith_invalid(0); return; } /* fprem(?,0) always invalid */ | 985 | } else if ((st0_tag == TAG_Valid) || (st0_tag == TW_Denormal)) { |
1080 | else if ( st1_tag == TW_Infinity ) | 986 | if (st1_tag == TAG_Zero) { |
1081 | { setcc(0); return; } | 987 | arith_invalid(0); /* fprem(Valid,Zero) is invalid */ |
1082 | } | 988 | return; |
1083 | else if ( (st0_tag == TAG_Valid) || (st0_tag == TW_Denormal) ) | 989 | } else if (st1_tag != TW_NaN) { |
1084 | { | 990 | if (((st0_tag == TW_Denormal) |
1085 | if ( st1_tag == TAG_Zero ) | 991 | || (st1_tag == TW_Denormal)) |
1086 | { | 992 | && (denormal_operand() < 0)) |
1087 | arith_invalid(0); /* fprem(Valid,Zero) is invalid */ | 993 | return; |
1088 | return; | 994 | |
1089 | } | 995 | if (st1_tag == TW_Infinity) { |
1090 | else if ( st1_tag != TW_NaN ) | 996 | /* fprem(Valid,Infinity) is o.k. */ |
1091 | { | 997 | setcc(0); |
1092 | if ( ((st0_tag == TW_Denormal) || (st1_tag == TW_Denormal)) | 998 | return; |
1093 | && (denormal_operand() < 0) ) | 999 | } |
1094 | return; | 1000 | } |
1095 | 1001 | } else if (st0_tag == TW_Infinity) { | |
1096 | if ( st1_tag == TW_Infinity ) | 1002 | if (st1_tag != TW_NaN) { |
1097 | { | 1003 | arith_invalid(0); /* fprem(Infinity,?) is invalid */ |
1098 | /* fprem(Valid,Infinity) is o.k. */ | 1004 | return; |
1099 | setcc(0); return; | 1005 | } |
1100 | } | ||
1101 | } | ||
1102 | } | ||
1103 | else if ( st0_tag == TW_Infinity ) | ||
1104 | { | ||
1105 | if ( st1_tag != TW_NaN ) | ||
1106 | { | ||
1107 | arith_invalid(0); /* fprem(Infinity,?) is invalid */ | ||
1108 | return; | ||
1109 | } | 1006 | } |
1110 | } | ||
1111 | 1007 | ||
1112 | /* One of the registers must contain a NaN if we got here. */ | 1008 | /* One of the registers must contain a NaN if we got here. */ |
1113 | 1009 | ||
1114 | #ifdef PARANOID | 1010 | #ifdef PARANOID |
1115 | if ( (st0_tag != TW_NaN) && (st1_tag != TW_NaN) ) | 1011 | if ((st0_tag != TW_NaN) && (st1_tag != TW_NaN)) |
1116 | EXCEPTION(EX_INTERNAL | 0x118); | 1012 | EXCEPTION(EX_INTERNAL | 0x118); |
1117 | #endif /* PARANOID */ | 1013 | #endif /* PARANOID */ |
1118 | 1014 | ||
1119 | real_2op_NaN(st1_ptr, st1_tag, 0, st1_ptr); | 1015 | real_2op_NaN(st1_ptr, st1_tag, 0, st1_ptr); |
1120 | 1016 | ||
1121 | } | 1017 | } |
1122 | 1018 | ||
1123 | |||
1124 | /* ST(1) <- ST(1) * log ST; pop ST */ | 1019 | /* ST(1) <- ST(1) * log ST; pop ST */ |
1125 | static void fyl2x(FPU_REG *st0_ptr, u_char st0_tag) | 1020 | static void fyl2x(FPU_REG * st0_ptr, u_char st0_tag) |
1126 | { | 1021 | { |
1127 | FPU_REG *st1_ptr = &st(1), exponent; | 1022 | FPU_REG *st1_ptr = &st(1), exponent; |
1128 | u_char st1_tag = FPU_gettagi(1); | 1023 | u_char st1_tag = FPU_gettagi(1); |
1129 | u_char sign; | 1024 | u_char sign; |
1130 | int e, tag; | 1025 | int e, tag; |
1131 | 1026 | ||
1132 | clear_C1(); | 1027 | clear_C1(); |
1133 | 1028 | ||
1134 | if ( (st0_tag == TAG_Valid) && (st1_tag == TAG_Valid) ) | 1029 | if ((st0_tag == TAG_Valid) && (st1_tag == TAG_Valid)) { |
1135 | { | 1030 | both_valid: |
1136 | both_valid: | 1031 | /* Both regs are Valid or Denormal */ |
1137 | /* Both regs are Valid or Denormal */ | 1032 | if (signpositive(st0_ptr)) { |
1138 | if ( signpositive(st0_ptr) ) | 1033 | if (st0_tag == TW_Denormal) |
1139 | { | 1034 | FPU_to_exp16(st0_ptr, st0_ptr); |
1140 | if ( st0_tag == TW_Denormal ) | 1035 | else |
1141 | FPU_to_exp16(st0_ptr, st0_ptr); | 1036 | /* Convert st(0) for internal use. */ |
1142 | else | 1037 | setexponent16(st0_ptr, exponent(st0_ptr)); |
1143 | /* Convert st(0) for internal use. */ | 1038 | |
1144 | setexponent16(st0_ptr, exponent(st0_ptr)); | 1039 | if ((st0_ptr->sigh == 0x80000000) |
1145 | 1040 | && (st0_ptr->sigl == 0)) { | |
1146 | if ( (st0_ptr->sigh == 0x80000000) && (st0_ptr->sigl == 0) ) | 1041 | /* Special case. The result can be precise. */ |
1147 | { | 1042 | u_char esign; |
1148 | /* Special case. The result can be precise. */ | 1043 | e = exponent16(st0_ptr); |
1149 | u_char esign; | 1044 | if (e >= 0) { |
1150 | e = exponent16(st0_ptr); | 1045 | exponent.sigh = e; |
1151 | if ( e >= 0 ) | 1046 | esign = SIGN_POS; |
1152 | { | 1047 | } else { |
1153 | exponent.sigh = e; | 1048 | exponent.sigh = -e; |
1154 | esign = SIGN_POS; | 1049 | esign = SIGN_NEG; |
1155 | } | 1050 | } |
1156 | else | 1051 | exponent.sigl = 0; |
1157 | { | 1052 | setexponent16(&exponent, 31); |
1158 | exponent.sigh = -e; | 1053 | tag = FPU_normalize_nuo(&exponent); |
1159 | esign = SIGN_NEG; | 1054 | stdexp(&exponent); |
1055 | setsign(&exponent, esign); | ||
1056 | tag = | ||
1057 | FPU_mul(&exponent, tag, 1, FULL_PRECISION); | ||
1058 | if (tag >= 0) | ||
1059 | FPU_settagi(1, tag); | ||
1060 | } else { | ||
1061 | /* The usual case */ | ||
1062 | sign = getsign(st1_ptr); | ||
1063 | if (st1_tag == TW_Denormal) | ||
1064 | FPU_to_exp16(st1_ptr, st1_ptr); | ||
1065 | else | ||
1066 | /* Convert st(1) for internal use. */ | ||
1067 | setexponent16(st1_ptr, | ||
1068 | exponent(st1_ptr)); | ||
1069 | poly_l2(st0_ptr, st1_ptr, sign); | ||
1070 | } | ||
1071 | } else { | ||
1072 | /* negative */ | ||
1073 | if (arith_invalid(1) < 0) | ||
1074 | return; | ||
1160 | } | 1075 | } |
1161 | exponent.sigl = 0; | ||
1162 | setexponent16(&exponent, 31); | ||
1163 | tag = FPU_normalize_nuo(&exponent); | ||
1164 | stdexp(&exponent); | ||
1165 | setsign(&exponent, esign); | ||
1166 | tag = FPU_mul(&exponent, tag, 1, FULL_PRECISION); | ||
1167 | if ( tag >= 0 ) | ||
1168 | FPU_settagi(1, tag); | ||
1169 | } | ||
1170 | else | ||
1171 | { | ||
1172 | /* The usual case */ | ||
1173 | sign = getsign(st1_ptr); | ||
1174 | if ( st1_tag == TW_Denormal ) | ||
1175 | FPU_to_exp16(st1_ptr, st1_ptr); | ||
1176 | else | ||
1177 | /* Convert st(1) for internal use. */ | ||
1178 | setexponent16(st1_ptr, exponent(st1_ptr)); | ||
1179 | poly_l2(st0_ptr, st1_ptr, sign); | ||
1180 | } | ||
1181 | } | ||
1182 | else | ||
1183 | { | ||
1184 | /* negative */ | ||
1185 | if ( arith_invalid(1) < 0 ) | ||
1186 | return; | ||
1187 | } | ||
1188 | 1076 | ||
1189 | FPU_pop(); | 1077 | FPU_pop(); |
1190 | |||
1191 | return; | ||
1192 | } | ||
1193 | |||
1194 | if ( st0_tag == TAG_Special ) | ||
1195 | st0_tag = FPU_Special(st0_ptr); | ||
1196 | if ( st1_tag == TAG_Special ) | ||
1197 | st1_tag = FPU_Special(st1_ptr); | ||
1198 | |||
1199 | if ( (st0_tag == TAG_Empty) || (st1_tag == TAG_Empty) ) | ||
1200 | { | ||
1201 | FPU_stack_underflow_pop(1); | ||
1202 | return; | ||
1203 | } | ||
1204 | else if ( (st0_tag <= TW_Denormal) && (st1_tag <= TW_Denormal) ) | ||
1205 | { | ||
1206 | if ( st0_tag == TAG_Zero ) | ||
1207 | { | ||
1208 | if ( st1_tag == TAG_Zero ) | ||
1209 | { | ||
1210 | /* Both args zero is invalid */ | ||
1211 | if ( arith_invalid(1) < 0 ) | ||
1212 | return; | ||
1213 | } | ||
1214 | else | ||
1215 | { | ||
1216 | u_char sign; | ||
1217 | sign = getsign(st1_ptr)^SIGN_NEG; | ||
1218 | if ( FPU_divide_by_zero(1, sign) < 0 ) | ||
1219 | return; | ||
1220 | 1078 | ||
1221 | setsign(st1_ptr, sign); | ||
1222 | } | ||
1223 | } | ||
1224 | else if ( st1_tag == TAG_Zero ) | ||
1225 | { | ||
1226 | /* st(1) contains zero, st(0) valid <> 0 */ | ||
1227 | /* Zero is the valid answer */ | ||
1228 | sign = getsign(st1_ptr); | ||
1229 | |||
1230 | if ( signnegative(st0_ptr) ) | ||
1231 | { | ||
1232 | /* log(negative) */ | ||
1233 | if ( arith_invalid(1) < 0 ) | ||
1234 | return; | 1079 | return; |
1235 | } | ||
1236 | else if ( (st0_tag == TW_Denormal) && (denormal_operand() < 0) ) | ||
1237 | return; | ||
1238 | else | ||
1239 | { | ||
1240 | if ( exponent(st0_ptr) < 0 ) | ||
1241 | sign ^= SIGN_NEG; | ||
1242 | |||
1243 | FPU_copy_to_reg1(&CONST_Z, TAG_Zero); | ||
1244 | setsign(st1_ptr, sign); | ||
1245 | } | ||
1246 | } | 1080 | } |
1247 | else | ||
1248 | { | ||
1249 | /* One or both operands are denormals. */ | ||
1250 | if ( denormal_operand() < 0 ) | ||
1251 | return; | ||
1252 | goto both_valid; | ||
1253 | } | ||
1254 | } | ||
1255 | else if ( (st0_tag == TW_NaN) || (st1_tag == TW_NaN) ) | ||
1256 | { | ||
1257 | if ( real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) < 0 ) | ||
1258 | return; | ||
1259 | } | ||
1260 | /* One or both arg must be an infinity */ | ||
1261 | else if ( st0_tag == TW_Infinity ) | ||
1262 | { | ||
1263 | if ( (signnegative(st0_ptr)) || (st1_tag == TAG_Zero) ) | ||
1264 | { | ||
1265 | /* log(-infinity) or 0*log(infinity) */ | ||
1266 | if ( arith_invalid(1) < 0 ) | ||
1267 | return; | ||
1268 | } | ||
1269 | else | ||
1270 | { | ||
1271 | u_char sign = getsign(st1_ptr); | ||
1272 | 1081 | ||
1273 | if ( (st1_tag == TW_Denormal) && (denormal_operand() < 0) ) | 1082 | if (st0_tag == TAG_Special) |
1274 | return; | 1083 | st0_tag = FPU_Special(st0_ptr); |
1084 | if (st1_tag == TAG_Special) | ||
1085 | st1_tag = FPU_Special(st1_ptr); | ||
1275 | 1086 | ||
1276 | FPU_copy_to_reg1(&CONST_INF, TAG_Special); | 1087 | if ((st0_tag == TAG_Empty) || (st1_tag == TAG_Empty)) { |
1277 | setsign(st1_ptr, sign); | 1088 | FPU_stack_underflow_pop(1); |
1278 | } | ||
1279 | } | ||
1280 | /* st(1) must be infinity here */ | ||
1281 | else if ( ((st0_tag == TAG_Valid) || (st0_tag == TW_Denormal)) | ||
1282 | && ( signpositive(st0_ptr) ) ) | ||
1283 | { | ||
1284 | if ( exponent(st0_ptr) >= 0 ) | ||
1285 | { | ||
1286 | if ( (exponent(st0_ptr) == 0) && | ||
1287 | (st0_ptr->sigh == 0x80000000) && | ||
1288 | (st0_ptr->sigl == 0) ) | ||
1289 | { | ||
1290 | /* st(0) holds 1.0 */ | ||
1291 | /* infinity*log(1) */ | ||
1292 | if ( arith_invalid(1) < 0 ) | ||
1293 | return; | 1089 | return; |
1294 | } | 1090 | } else if ((st0_tag <= TW_Denormal) && (st1_tag <= TW_Denormal)) { |
1295 | /* else st(0) is positive and > 1.0 */ | 1091 | if (st0_tag == TAG_Zero) { |
1092 | if (st1_tag == TAG_Zero) { | ||
1093 | /* Both args zero is invalid */ | ||
1094 | if (arith_invalid(1) < 0) | ||
1095 | return; | ||
1096 | } else { | ||
1097 | u_char sign; | ||
1098 | sign = getsign(st1_ptr) ^ SIGN_NEG; | ||
1099 | if (FPU_divide_by_zero(1, sign) < 0) | ||
1100 | return; | ||
1101 | |||
1102 | setsign(st1_ptr, sign); | ||
1103 | } | ||
1104 | } else if (st1_tag == TAG_Zero) { | ||
1105 | /* st(1) contains zero, st(0) valid <> 0 */ | ||
1106 | /* Zero is the valid answer */ | ||
1107 | sign = getsign(st1_ptr); | ||
1108 | |||
1109 | if (signnegative(st0_ptr)) { | ||
1110 | /* log(negative) */ | ||
1111 | if (arith_invalid(1) < 0) | ||
1112 | return; | ||
1113 | } else if ((st0_tag == TW_Denormal) | ||
1114 | && (denormal_operand() < 0)) | ||
1115 | return; | ||
1116 | else { | ||
1117 | if (exponent(st0_ptr) < 0) | ||
1118 | sign ^= SIGN_NEG; | ||
1119 | |||
1120 | FPU_copy_to_reg1(&CONST_Z, TAG_Zero); | ||
1121 | setsign(st1_ptr, sign); | ||
1122 | } | ||
1123 | } else { | ||
1124 | /* One or both operands are denormals. */ | ||
1125 | if (denormal_operand() < 0) | ||
1126 | return; | ||
1127 | goto both_valid; | ||
1128 | } | ||
1129 | } else if ((st0_tag == TW_NaN) || (st1_tag == TW_NaN)) { | ||
1130 | if (real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) < 0) | ||
1131 | return; | ||
1132 | } | ||
1133 | /* One or both arg must be an infinity */ | ||
1134 | else if (st0_tag == TW_Infinity) { | ||
1135 | if ((signnegative(st0_ptr)) || (st1_tag == TAG_Zero)) { | ||
1136 | /* log(-infinity) or 0*log(infinity) */ | ||
1137 | if (arith_invalid(1) < 0) | ||
1138 | return; | ||
1139 | } else { | ||
1140 | u_char sign = getsign(st1_ptr); | ||
1141 | |||
1142 | if ((st1_tag == TW_Denormal) | ||
1143 | && (denormal_operand() < 0)) | ||
1144 | return; | ||
1145 | |||
1146 | FPU_copy_to_reg1(&CONST_INF, TAG_Special); | ||
1147 | setsign(st1_ptr, sign); | ||
1148 | } | ||
1296 | } | 1149 | } |
1297 | else | 1150 | /* st(1) must be infinity here */ |
1298 | { | 1151 | else if (((st0_tag == TAG_Valid) || (st0_tag == TW_Denormal)) |
1299 | /* st(0) is positive and < 1.0 */ | 1152 | && (signpositive(st0_ptr))) { |
1153 | if (exponent(st0_ptr) >= 0) { | ||
1154 | if ((exponent(st0_ptr) == 0) && | ||
1155 | (st0_ptr->sigh == 0x80000000) && | ||
1156 | (st0_ptr->sigl == 0)) { | ||
1157 | /* st(0) holds 1.0 */ | ||
1158 | /* infinity*log(1) */ | ||
1159 | if (arith_invalid(1) < 0) | ||
1160 | return; | ||
1161 | } | ||
1162 | /* else st(0) is positive and > 1.0 */ | ||
1163 | } else { | ||
1164 | /* st(0) is positive and < 1.0 */ | ||
1300 | 1165 | ||
1301 | if ( (st0_tag == TW_Denormal) && (denormal_operand() < 0) ) | 1166 | if ((st0_tag == TW_Denormal) |
1302 | return; | 1167 | && (denormal_operand() < 0)) |
1168 | return; | ||
1303 | 1169 | ||
1304 | changesign(st1_ptr); | 1170 | changesign(st1_ptr); |
1305 | } | 1171 | } |
1306 | } | 1172 | } else { |
1307 | else | 1173 | /* st(0) must be zero or negative */ |
1308 | { | 1174 | if (st0_tag == TAG_Zero) { |
1309 | /* st(0) must be zero or negative */ | 1175 | /* This should be invalid, but a real 80486 is happy with it. */ |
1310 | if ( st0_tag == TAG_Zero ) | ||
1311 | { | ||
1312 | /* This should be invalid, but a real 80486 is happy with it. */ | ||
1313 | 1176 | ||
1314 | #ifndef PECULIAR_486 | 1177 | #ifndef PECULIAR_486 |
1315 | sign = getsign(st1_ptr); | 1178 | sign = getsign(st1_ptr); |
1316 | if ( FPU_divide_by_zero(1, sign) < 0 ) | 1179 | if (FPU_divide_by_zero(1, sign) < 0) |
1317 | return; | 1180 | return; |
1318 | #endif /* PECULIAR_486 */ | 1181 | #endif /* PECULIAR_486 */ |
1319 | 1182 | ||
1320 | changesign(st1_ptr); | 1183 | changesign(st1_ptr); |
1184 | } else if (arith_invalid(1) < 0) /* log(negative) */ | ||
1185 | return; | ||
1321 | } | 1186 | } |
1322 | else if ( arith_invalid(1) < 0 ) /* log(negative) */ | ||
1323 | return; | ||
1324 | } | ||
1325 | 1187 | ||
1326 | FPU_pop(); | 1188 | FPU_pop(); |
1327 | } | 1189 | } |
1328 | 1190 | ||
1329 | 1191 | static void fpatan(FPU_REG * st0_ptr, u_char st0_tag) | |
1330 | static void fpatan(FPU_REG *st0_ptr, u_char st0_tag) | ||
1331 | { | 1192 | { |
1332 | FPU_REG *st1_ptr = &st(1); | 1193 | FPU_REG *st1_ptr = &st(1); |
1333 | u_char st1_tag = FPU_gettagi(1); | 1194 | u_char st1_tag = FPU_gettagi(1); |
1334 | int tag; | 1195 | int tag; |
1335 | 1196 | ||
1336 | clear_C1(); | 1197 | clear_C1(); |
1337 | if ( !((st0_tag ^ TAG_Valid) | (st1_tag ^ TAG_Valid)) ) | 1198 | if (!((st0_tag ^ TAG_Valid) | (st1_tag ^ TAG_Valid))) { |
1338 | { | 1199 | valid_atan: |
1339 | valid_atan: | ||
1340 | 1200 | ||
1341 | poly_atan(st0_ptr, st0_tag, st1_ptr, st1_tag); | 1201 | poly_atan(st0_ptr, st0_tag, st1_ptr, st1_tag); |
1342 | 1202 | ||
1343 | FPU_pop(); | 1203 | FPU_pop(); |
1344 | 1204 | ||
1345 | return; | 1205 | return; |
1346 | } | 1206 | } |
1347 | 1207 | ||
1348 | if ( st0_tag == TAG_Special ) | 1208 | if (st0_tag == TAG_Special) |
1349 | st0_tag = FPU_Special(st0_ptr); | 1209 | st0_tag = FPU_Special(st0_ptr); |
1350 | if ( st1_tag == TAG_Special ) | 1210 | if (st1_tag == TAG_Special) |
1351 | st1_tag = FPU_Special(st1_ptr); | 1211 | st1_tag = FPU_Special(st1_ptr); |
1352 | 1212 | ||
1353 | if ( ((st0_tag == TAG_Valid) && (st1_tag == TW_Denormal)) | 1213 | if (((st0_tag == TAG_Valid) && (st1_tag == TW_Denormal)) |
1354 | || ((st0_tag == TW_Denormal) && (st1_tag == TAG_Valid)) | 1214 | || ((st0_tag == TW_Denormal) && (st1_tag == TAG_Valid)) |
1355 | || ((st0_tag == TW_Denormal) && (st1_tag == TW_Denormal)) ) | 1215 | || ((st0_tag == TW_Denormal) && (st1_tag == TW_Denormal))) { |
1356 | { | 1216 | if (denormal_operand() < 0) |
1357 | if ( denormal_operand() < 0 ) | 1217 | return; |
1358 | return; | ||
1359 | 1218 | ||
1360 | goto valid_atan; | 1219 | goto valid_atan; |
1361 | } | 1220 | } else if ((st0_tag == TAG_Empty) || (st1_tag == TAG_Empty)) { |
1362 | else if ( (st0_tag == TAG_Empty) || (st1_tag == TAG_Empty) ) | 1221 | FPU_stack_underflow_pop(1); |
1363 | { | 1222 | return; |
1364 | FPU_stack_underflow_pop(1); | 1223 | } else if ((st0_tag == TW_NaN) || (st1_tag == TW_NaN)) { |
1365 | return; | 1224 | if (real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) >= 0) |
1366 | } | 1225 | FPU_pop(); |
1367 | else if ( (st0_tag == TW_NaN) || (st1_tag == TW_NaN) ) | ||
1368 | { | ||
1369 | if ( real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) >= 0 ) | ||
1370 | FPU_pop(); | ||
1371 | return; | ||
1372 | } | ||
1373 | else if ( (st0_tag == TW_Infinity) || (st1_tag == TW_Infinity) ) | ||
1374 | { | ||
1375 | u_char sign = getsign(st1_ptr); | ||
1376 | if ( st0_tag == TW_Infinity ) | ||
1377 | { | ||
1378 | if ( st1_tag == TW_Infinity ) | ||
1379 | { | ||
1380 | if ( signpositive(st0_ptr) ) | ||
1381 | { | ||
1382 | FPU_copy_to_reg1(&CONST_PI4, TAG_Valid); | ||
1383 | } | ||
1384 | else | ||
1385 | { | ||
1386 | setpositive(st1_ptr); | ||
1387 | tag = FPU_u_add(&CONST_PI4, &CONST_PI2, st1_ptr, | ||
1388 | FULL_PRECISION, SIGN_POS, | ||
1389 | exponent(&CONST_PI4), exponent(&CONST_PI2)); | ||
1390 | if ( tag >= 0 ) | ||
1391 | FPU_settagi(1, tag); | ||
1392 | } | ||
1393 | } | ||
1394 | else | ||
1395 | { | ||
1396 | if ( (st1_tag == TW_Denormal) && (denormal_operand() < 0) ) | ||
1397 | return; | 1226 | return; |
1227 | } else if ((st0_tag == TW_Infinity) || (st1_tag == TW_Infinity)) { | ||
1228 | u_char sign = getsign(st1_ptr); | ||
1229 | if (st0_tag == TW_Infinity) { | ||
1230 | if (st1_tag == TW_Infinity) { | ||
1231 | if (signpositive(st0_ptr)) { | ||
1232 | FPU_copy_to_reg1(&CONST_PI4, TAG_Valid); | ||
1233 | } else { | ||
1234 | setpositive(st1_ptr); | ||
1235 | tag = | ||
1236 | FPU_u_add(&CONST_PI4, &CONST_PI2, | ||
1237 | st1_ptr, FULL_PRECISION, | ||
1238 | SIGN_POS, | ||
1239 | exponent(&CONST_PI4), | ||
1240 | exponent(&CONST_PI2)); | ||
1241 | if (tag >= 0) | ||
1242 | FPU_settagi(1, tag); | ||
1243 | } | ||
1244 | } else { | ||
1245 | if ((st1_tag == TW_Denormal) | ||
1246 | && (denormal_operand() < 0)) | ||
1247 | return; | ||
1248 | |||
1249 | if (signpositive(st0_ptr)) { | ||
1250 | FPU_copy_to_reg1(&CONST_Z, TAG_Zero); | ||
1251 | setsign(st1_ptr, sign); /* An 80486 preserves the sign */ | ||
1252 | FPU_pop(); | ||
1253 | return; | ||
1254 | } else { | ||
1255 | FPU_copy_to_reg1(&CONST_PI, TAG_Valid); | ||
1256 | } | ||
1257 | } | ||
1258 | } else { | ||
1259 | /* st(1) is infinity, st(0) not infinity */ | ||
1260 | if ((st0_tag == TW_Denormal) | ||
1261 | && (denormal_operand() < 0)) | ||
1262 | return; | ||
1398 | 1263 | ||
1399 | if ( signpositive(st0_ptr) ) | 1264 | FPU_copy_to_reg1(&CONST_PI2, TAG_Valid); |
1400 | { | ||
1401 | FPU_copy_to_reg1(&CONST_Z, TAG_Zero); | ||
1402 | setsign(st1_ptr, sign); /* An 80486 preserves the sign */ | ||
1403 | FPU_pop(); | ||
1404 | return; | ||
1405 | } | 1265 | } |
1406 | else | 1266 | setsign(st1_ptr, sign); |
1407 | { | 1267 | } else if (st1_tag == TAG_Zero) { |
1408 | FPU_copy_to_reg1(&CONST_PI, TAG_Valid); | 1268 | /* st(0) must be valid or zero */ |
1269 | u_char sign = getsign(st1_ptr); | ||
1270 | |||
1271 | if ((st0_tag == TW_Denormal) && (denormal_operand() < 0)) | ||
1272 | return; | ||
1273 | |||
1274 | if (signpositive(st0_ptr)) { | ||
1275 | /* An 80486 preserves the sign */ | ||
1276 | FPU_pop(); | ||
1277 | return; | ||
1409 | } | 1278 | } |
1410 | } | ||
1411 | } | ||
1412 | else | ||
1413 | { | ||
1414 | /* st(1) is infinity, st(0) not infinity */ | ||
1415 | if ( (st0_tag == TW_Denormal) && (denormal_operand() < 0) ) | ||
1416 | return; | ||
1417 | 1279 | ||
1418 | FPU_copy_to_reg1(&CONST_PI2, TAG_Valid); | 1280 | FPU_copy_to_reg1(&CONST_PI, TAG_Valid); |
1419 | } | 1281 | setsign(st1_ptr, sign); |
1420 | setsign(st1_ptr, sign); | 1282 | } else if (st0_tag == TAG_Zero) { |
1421 | } | 1283 | /* st(1) must be TAG_Valid here */ |
1422 | else if ( st1_tag == TAG_Zero ) | 1284 | u_char sign = getsign(st1_ptr); |
1423 | { | ||
1424 | /* st(0) must be valid or zero */ | ||
1425 | u_char sign = getsign(st1_ptr); | ||
1426 | |||
1427 | if ( (st0_tag == TW_Denormal) && (denormal_operand() < 0) ) | ||
1428 | return; | ||
1429 | 1285 | ||
1430 | if ( signpositive(st0_ptr) ) | 1286 | if ((st1_tag == TW_Denormal) && (denormal_operand() < 0)) |
1431 | { | 1287 | return; |
1432 | /* An 80486 preserves the sign */ | ||
1433 | FPU_pop(); | ||
1434 | return; | ||
1435 | } | ||
1436 | 1288 | ||
1437 | FPU_copy_to_reg1(&CONST_PI, TAG_Valid); | 1289 | FPU_copy_to_reg1(&CONST_PI2, TAG_Valid); |
1438 | setsign(st1_ptr, sign); | 1290 | setsign(st1_ptr, sign); |
1439 | } | 1291 | } |
1440 | else if ( st0_tag == TAG_Zero ) | ||
1441 | { | ||
1442 | /* st(1) must be TAG_Valid here */ | ||
1443 | u_char sign = getsign(st1_ptr); | ||
1444 | |||
1445 | if ( (st1_tag == TW_Denormal) && (denormal_operand() < 0) ) | ||
1446 | return; | ||
1447 | |||
1448 | FPU_copy_to_reg1(&CONST_PI2, TAG_Valid); | ||
1449 | setsign(st1_ptr, sign); | ||
1450 | } | ||
1451 | #ifdef PARANOID | 1292 | #ifdef PARANOID |
1452 | else | 1293 | else |
1453 | EXCEPTION(EX_INTERNAL | 0x125); | 1294 | EXCEPTION(EX_INTERNAL | 0x125); |
1454 | #endif /* PARANOID */ | 1295 | #endif /* PARANOID */ |
1455 | 1296 | ||
1456 | FPU_pop(); | 1297 | FPU_pop(); |
1457 | set_precision_flag_up(); /* We do not really know if up or down */ | 1298 | set_precision_flag_up(); /* We do not really know if up or down */ |
1458 | } | 1299 | } |
1459 | 1300 | ||
1460 | 1301 | static void fprem(FPU_REG * st0_ptr, u_char st0_tag) | |
1461 | static void fprem(FPU_REG *st0_ptr, u_char st0_tag) | ||
1462 | { | 1302 | { |
1463 | do_fprem(st0_ptr, st0_tag, RC_CHOP); | 1303 | do_fprem(st0_ptr, st0_tag, RC_CHOP); |
1464 | } | 1304 | } |
1465 | 1305 | ||
1466 | 1306 | static void fprem1(FPU_REG * st0_ptr, u_char st0_tag) | |
1467 | static void fprem1(FPU_REG *st0_ptr, u_char st0_tag) | ||
1468 | { | 1307 | { |
1469 | do_fprem(st0_ptr, st0_tag, RC_RND); | 1308 | do_fprem(st0_ptr, st0_tag, RC_RND); |
1470 | } | 1309 | } |
1471 | 1310 | ||
1472 | 1311 | static void fyl2xp1(FPU_REG * st0_ptr, u_char st0_tag) | |
1473 | static void fyl2xp1(FPU_REG *st0_ptr, u_char st0_tag) | ||
1474 | { | 1312 | { |
1475 | u_char sign, sign1; | 1313 | u_char sign, sign1; |
1476 | FPU_REG *st1_ptr = &st(1), a, b; | 1314 | FPU_REG *st1_ptr = &st(1), a, b; |
1477 | u_char st1_tag = FPU_gettagi(1); | 1315 | u_char st1_tag = FPU_gettagi(1); |
1478 | 1316 | ||
1479 | clear_C1(); | 1317 | clear_C1(); |
1480 | if ( !((st0_tag ^ TAG_Valid) | (st1_tag ^ TAG_Valid)) ) | 1318 | if (!((st0_tag ^ TAG_Valid) | (st1_tag ^ TAG_Valid))) { |
1481 | { | 1319 | valid_yl2xp1: |
1482 | valid_yl2xp1: | ||
1483 | 1320 | ||
1484 | sign = getsign(st0_ptr); | 1321 | sign = getsign(st0_ptr); |
1485 | sign1 = getsign(st1_ptr); | 1322 | sign1 = getsign(st1_ptr); |
1486 | 1323 | ||
1487 | FPU_to_exp16(st0_ptr, &a); | 1324 | FPU_to_exp16(st0_ptr, &a); |
1488 | FPU_to_exp16(st1_ptr, &b); | 1325 | FPU_to_exp16(st1_ptr, &b); |
1489 | 1326 | ||
1490 | if ( poly_l2p1(sign, sign1, &a, &b, st1_ptr) ) | 1327 | if (poly_l2p1(sign, sign1, &a, &b, st1_ptr)) |
1491 | return; | 1328 | return; |
1492 | 1329 | ||
1493 | FPU_pop(); | 1330 | FPU_pop(); |
1494 | return; | 1331 | return; |
1495 | } | 1332 | } |
1496 | 1333 | ||
1497 | if ( st0_tag == TAG_Special ) | 1334 | if (st0_tag == TAG_Special) |
1498 | st0_tag = FPU_Special(st0_ptr); | 1335 | st0_tag = FPU_Special(st0_ptr); |
1499 | if ( st1_tag == TAG_Special ) | 1336 | if (st1_tag == TAG_Special) |
1500 | st1_tag = FPU_Special(st1_ptr); | 1337 | st1_tag = FPU_Special(st1_ptr); |
1501 | 1338 | ||
1502 | if ( ((st0_tag == TAG_Valid) && (st1_tag == TW_Denormal)) | 1339 | if (((st0_tag == TAG_Valid) && (st1_tag == TW_Denormal)) |
1503 | || ((st0_tag == TW_Denormal) && (st1_tag == TAG_Valid)) | 1340 | || ((st0_tag == TW_Denormal) && (st1_tag == TAG_Valid)) |
1504 | || ((st0_tag == TW_Denormal) && (st1_tag == TW_Denormal)) ) | 1341 | || ((st0_tag == TW_Denormal) && (st1_tag == TW_Denormal))) { |
1505 | { | 1342 | if (denormal_operand() < 0) |
1506 | if ( denormal_operand() < 0 ) | 1343 | return; |
1507 | return; | ||
1508 | |||
1509 | goto valid_yl2xp1; | ||
1510 | } | ||
1511 | else if ( (st0_tag == TAG_Empty) | (st1_tag == TAG_Empty) ) | ||
1512 | { | ||
1513 | FPU_stack_underflow_pop(1); | ||
1514 | return; | ||
1515 | } | ||
1516 | else if ( st0_tag == TAG_Zero ) | ||
1517 | { | ||
1518 | switch ( st1_tag ) | ||
1519 | { | ||
1520 | case TW_Denormal: | ||
1521 | if ( denormal_operand() < 0 ) | ||
1522 | return; | ||
1523 | |||
1524 | case TAG_Zero: | ||
1525 | case TAG_Valid: | ||
1526 | setsign(st0_ptr, getsign(st0_ptr) ^ getsign(st1_ptr)); | ||
1527 | FPU_copy_to_reg1(st0_ptr, st0_tag); | ||
1528 | break; | ||
1529 | |||
1530 | case TW_Infinity: | ||
1531 | /* Infinity*log(1) */ | ||
1532 | if ( arith_invalid(1) < 0 ) | ||
1533 | return; | ||
1534 | break; | ||
1535 | 1344 | ||
1536 | case TW_NaN: | 1345 | goto valid_yl2xp1; |
1537 | if ( real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) < 0 ) | 1346 | } else if ((st0_tag == TAG_Empty) | (st1_tag == TAG_Empty)) { |
1538 | return; | 1347 | FPU_stack_underflow_pop(1); |
1539 | break; | 1348 | return; |
1540 | 1349 | } else if (st0_tag == TAG_Zero) { | |
1541 | default: | 1350 | switch (st1_tag) { |
1351 | case TW_Denormal: | ||
1352 | if (denormal_operand() < 0) | ||
1353 | return; | ||
1354 | |||
1355 | case TAG_Zero: | ||
1356 | case TAG_Valid: | ||
1357 | setsign(st0_ptr, getsign(st0_ptr) ^ getsign(st1_ptr)); | ||
1358 | FPU_copy_to_reg1(st0_ptr, st0_tag); | ||
1359 | break; | ||
1360 | |||
1361 | case TW_Infinity: | ||
1362 | /* Infinity*log(1) */ | ||
1363 | if (arith_invalid(1) < 0) | ||
1364 | return; | ||
1365 | break; | ||
1366 | |||
1367 | case TW_NaN: | ||
1368 | if (real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) < 0) | ||
1369 | return; | ||
1370 | break; | ||
1371 | |||
1372 | default: | ||
1542 | #ifdef PARANOID | 1373 | #ifdef PARANOID |
1543 | EXCEPTION(EX_INTERNAL | 0x116); | 1374 | EXCEPTION(EX_INTERNAL | 0x116); |
1544 | return; | 1375 | return; |
1545 | #endif /* PARANOID */ | 1376 | #endif /* PARANOID */ |
1546 | break; | 1377 | break; |
1547 | } | 1378 | } |
1548 | } | 1379 | } else if ((st0_tag == TAG_Valid) || (st0_tag == TW_Denormal)) { |
1549 | else if ( (st0_tag == TAG_Valid) || (st0_tag == TW_Denormal) ) | 1380 | switch (st1_tag) { |
1550 | { | 1381 | case TAG_Zero: |
1551 | switch ( st1_tag ) | 1382 | if (signnegative(st0_ptr)) { |
1552 | { | 1383 | if (exponent(st0_ptr) >= 0) { |
1553 | case TAG_Zero: | 1384 | /* st(0) holds <= -1.0 */ |
1554 | if ( signnegative(st0_ptr) ) | 1385 | #ifdef PECULIAR_486 /* Stupid 80486 doesn't worry about log(negative). */ |
1555 | { | 1386 | changesign(st1_ptr); |
1556 | if ( exponent(st0_ptr) >= 0 ) | ||
1557 | { | ||
1558 | /* st(0) holds <= -1.0 */ | ||
1559 | #ifdef PECULIAR_486 /* Stupid 80486 doesn't worry about log(negative). */ | ||
1560 | changesign(st1_ptr); | ||
1561 | #else | 1387 | #else |
1562 | if ( arith_invalid(1) < 0 ) | 1388 | if (arith_invalid(1) < 0) |
1563 | return; | 1389 | return; |
1564 | #endif /* PECULIAR_486 */ | 1390 | #endif /* PECULIAR_486 */ |
1565 | } | 1391 | } else if ((st0_tag == TW_Denormal) |
1566 | else if ( (st0_tag == TW_Denormal) && (denormal_operand() < 0) ) | 1392 | && (denormal_operand() < 0)) |
1567 | return; | 1393 | return; |
1568 | else | 1394 | else |
1569 | changesign(st1_ptr); | 1395 | changesign(st1_ptr); |
1570 | } | 1396 | } else if ((st0_tag == TW_Denormal) |
1571 | else if ( (st0_tag == TW_Denormal) && (denormal_operand() < 0) ) | 1397 | && (denormal_operand() < 0)) |
1572 | return; | 1398 | return; |
1573 | break; | 1399 | break; |
1574 | 1400 | ||
1575 | case TW_Infinity: | 1401 | case TW_Infinity: |
1576 | if ( signnegative(st0_ptr) ) | 1402 | if (signnegative(st0_ptr)) { |
1577 | { | 1403 | if ((exponent(st0_ptr) >= 0) && |
1578 | if ( (exponent(st0_ptr) >= 0) && | 1404 | !((st0_ptr->sigh == 0x80000000) && |
1579 | !((st0_ptr->sigh == 0x80000000) && | 1405 | (st0_ptr->sigl == 0))) { |
1580 | (st0_ptr->sigl == 0)) ) | 1406 | /* st(0) holds < -1.0 */ |
1581 | { | 1407 | #ifdef PECULIAR_486 /* Stupid 80486 doesn't worry about log(negative). */ |
1582 | /* st(0) holds < -1.0 */ | 1408 | changesign(st1_ptr); |
1583 | #ifdef PECULIAR_486 /* Stupid 80486 doesn't worry about log(negative). */ | ||
1584 | changesign(st1_ptr); | ||
1585 | #else | 1409 | #else |
1586 | if ( arith_invalid(1) < 0 ) return; | 1410 | if (arith_invalid(1) < 0) |
1411 | return; | ||
1587 | #endif /* PECULIAR_486 */ | 1412 | #endif /* PECULIAR_486 */ |
1413 | } else if ((st0_tag == TW_Denormal) | ||
1414 | && (denormal_operand() < 0)) | ||
1415 | return; | ||
1416 | else | ||
1417 | changesign(st1_ptr); | ||
1418 | } else if ((st0_tag == TW_Denormal) | ||
1419 | && (denormal_operand() < 0)) | ||
1420 | return; | ||
1421 | break; | ||
1422 | |||
1423 | case TW_NaN: | ||
1424 | if (real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) < 0) | ||
1425 | return; | ||
1588 | } | 1426 | } |
1589 | else if ( (st0_tag == TW_Denormal) && (denormal_operand() < 0) ) | ||
1590 | return; | ||
1591 | else | ||
1592 | changesign(st1_ptr); | ||
1593 | } | ||
1594 | else if ( (st0_tag == TW_Denormal) && (denormal_operand() < 0) ) | ||
1595 | return; | ||
1596 | break; | ||
1597 | |||
1598 | case TW_NaN: | ||
1599 | if ( real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) < 0 ) | ||
1600 | return; | ||
1601 | } | ||
1602 | 1427 | ||
1603 | } | 1428 | } else if (st0_tag == TW_NaN) { |
1604 | else if ( st0_tag == TW_NaN ) | 1429 | if (real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) < 0) |
1605 | { | 1430 | return; |
1606 | if ( real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) < 0 ) | 1431 | } else if (st0_tag == TW_Infinity) { |
1607 | return; | 1432 | if (st1_tag == TW_NaN) { |
1608 | } | 1433 | if (real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) < 0) |
1609 | else if ( st0_tag == TW_Infinity ) | 1434 | return; |
1610 | { | 1435 | } else if (signnegative(st0_ptr)) { |
1611 | if ( st1_tag == TW_NaN ) | ||
1612 | { | ||
1613 | if ( real_2op_NaN(st0_ptr, st0_tag, 1, st0_ptr) < 0 ) | ||
1614 | return; | ||
1615 | } | ||
1616 | else if ( signnegative(st0_ptr) ) | ||
1617 | { | ||
1618 | #ifndef PECULIAR_486 | 1436 | #ifndef PECULIAR_486 |
1619 | /* This should have higher priority than denormals, but... */ | 1437 | /* This should have higher priority than denormals, but... */ |
1620 | if ( arith_invalid(1) < 0 ) /* log(-infinity) */ | 1438 | if (arith_invalid(1) < 0) /* log(-infinity) */ |
1621 | return; | 1439 | return; |
1622 | #endif /* PECULIAR_486 */ | 1440 | #endif /* PECULIAR_486 */ |
1623 | if ( (st1_tag == TW_Denormal) && (denormal_operand() < 0) ) | 1441 | if ((st1_tag == TW_Denormal) |
1624 | return; | 1442 | && (denormal_operand() < 0)) |
1443 | return; | ||
1625 | #ifdef PECULIAR_486 | 1444 | #ifdef PECULIAR_486 |
1626 | /* Denormal operands actually get higher priority */ | 1445 | /* Denormal operands actually get higher priority */ |
1627 | if ( arith_invalid(1) < 0 ) /* log(-infinity) */ | 1446 | if (arith_invalid(1) < 0) /* log(-infinity) */ |
1628 | return; | 1447 | return; |
1629 | #endif /* PECULIAR_486 */ | 1448 | #endif /* PECULIAR_486 */ |
1630 | } | 1449 | } else if (st1_tag == TAG_Zero) { |
1631 | else if ( st1_tag == TAG_Zero ) | 1450 | /* log(infinity) */ |
1632 | { | 1451 | if (arith_invalid(1) < 0) |
1633 | /* log(infinity) */ | 1452 | return; |
1634 | if ( arith_invalid(1) < 0 ) | 1453 | } |
1635 | return; | ||
1636 | } | ||
1637 | |||
1638 | /* st(1) must be valid here. */ | ||
1639 | 1454 | ||
1640 | else if ( (st1_tag == TW_Denormal) && (denormal_operand() < 0) ) | 1455 | /* st(1) must be valid here. */ |
1641 | return; | 1456 | |
1457 | else if ((st1_tag == TW_Denormal) && (denormal_operand() < 0)) | ||
1458 | return; | ||
1642 | 1459 | ||
1643 | /* The Manual says that log(Infinity) is invalid, but a real | 1460 | /* The Manual says that log(Infinity) is invalid, but a real |
1644 | 80486 sensibly says that it is o.k. */ | 1461 | 80486 sensibly says that it is o.k. */ |
1645 | else | 1462 | else { |
1646 | { | 1463 | u_char sign = getsign(st1_ptr); |
1647 | u_char sign = getsign(st1_ptr); | 1464 | FPU_copy_to_reg1(&CONST_INF, TAG_Special); |
1648 | FPU_copy_to_reg1(&CONST_INF, TAG_Special); | 1465 | setsign(st1_ptr, sign); |
1649 | setsign(st1_ptr, sign); | 1466 | } |
1650 | } | 1467 | } |
1651 | } | ||
1652 | #ifdef PARANOID | 1468 | #ifdef PARANOID |
1653 | else | 1469 | else { |
1654 | { | 1470 | EXCEPTION(EX_INTERNAL | 0x117); |
1655 | EXCEPTION(EX_INTERNAL | 0x117); | 1471 | return; |
1656 | return; | 1472 | } |
1657 | } | ||
1658 | #endif /* PARANOID */ | 1473 | #endif /* PARANOID */ |
1659 | 1474 | ||
1660 | FPU_pop(); | 1475 | FPU_pop(); |
1661 | return; | 1476 | return; |
1662 | 1477 | ||
1663 | } | 1478 | } |
1664 | 1479 | ||
1665 | 1480 | static void fscale(FPU_REG * st0_ptr, u_char st0_tag) | |
1666 | static void fscale(FPU_REG *st0_ptr, u_char st0_tag) | ||
1667 | { | 1481 | { |
1668 | FPU_REG *st1_ptr = &st(1); | 1482 | FPU_REG *st1_ptr = &st(1); |
1669 | u_char st1_tag = FPU_gettagi(1); | 1483 | u_char st1_tag = FPU_gettagi(1); |
1670 | int old_cw = control_word; | 1484 | int old_cw = control_word; |
1671 | u_char sign = getsign(st0_ptr); | 1485 | u_char sign = getsign(st0_ptr); |
1672 | 1486 | ||
1673 | clear_C1(); | 1487 | clear_C1(); |
1674 | if ( !((st0_tag ^ TAG_Valid) | (st1_tag ^ TAG_Valid)) ) | 1488 | if (!((st0_tag ^ TAG_Valid) | (st1_tag ^ TAG_Valid))) { |
1675 | { | 1489 | long scale; |
1676 | long scale; | 1490 | FPU_REG tmp; |
1677 | FPU_REG tmp; | 1491 | |
1678 | 1492 | /* Convert register for internal use. */ | |
1679 | /* Convert register for internal use. */ | 1493 | setexponent16(st0_ptr, exponent(st0_ptr)); |
1680 | setexponent16(st0_ptr, exponent(st0_ptr)); | 1494 | |
1681 | 1495 | valid_scale: | |
1682 | valid_scale: | 1496 | |
1683 | 1497 | if (exponent(st1_ptr) > 30) { | |
1684 | if ( exponent(st1_ptr) > 30 ) | 1498 | /* 2^31 is far too large, would require 2^(2^30) or 2^(-2^30) */ |
1685 | { | 1499 | |
1686 | /* 2^31 is far too large, would require 2^(2^30) or 2^(-2^30) */ | 1500 | if (signpositive(st1_ptr)) { |
1687 | 1501 | EXCEPTION(EX_Overflow); | |
1688 | if ( signpositive(st1_ptr) ) | 1502 | FPU_copy_to_reg0(&CONST_INF, TAG_Special); |
1689 | { | 1503 | } else { |
1690 | EXCEPTION(EX_Overflow); | 1504 | EXCEPTION(EX_Underflow); |
1691 | FPU_copy_to_reg0(&CONST_INF, TAG_Special); | 1505 | FPU_copy_to_reg0(&CONST_Z, TAG_Zero); |
1692 | } | 1506 | } |
1693 | else | 1507 | setsign(st0_ptr, sign); |
1694 | { | 1508 | return; |
1695 | EXCEPTION(EX_Underflow); | 1509 | } |
1696 | FPU_copy_to_reg0(&CONST_Z, TAG_Zero); | ||
1697 | } | ||
1698 | setsign(st0_ptr, sign); | ||
1699 | return; | ||
1700 | } | ||
1701 | |||
1702 | control_word &= ~CW_RC; | ||
1703 | control_word |= RC_CHOP; | ||
1704 | reg_copy(st1_ptr, &tmp); | ||
1705 | FPU_round_to_int(&tmp, st1_tag); /* This can never overflow here */ | ||
1706 | control_word = old_cw; | ||
1707 | scale = signnegative(st1_ptr) ? -tmp.sigl : tmp.sigl; | ||
1708 | scale += exponent16(st0_ptr); | ||
1709 | |||
1710 | setexponent16(st0_ptr, scale); | ||
1711 | |||
1712 | /* Use FPU_round() to properly detect under/overflow etc */ | ||
1713 | FPU_round(st0_ptr, 0, 0, control_word, sign); | ||
1714 | |||
1715 | return; | ||
1716 | } | ||
1717 | |||
1718 | if ( st0_tag == TAG_Special ) | ||
1719 | st0_tag = FPU_Special(st0_ptr); | ||
1720 | if ( st1_tag == TAG_Special ) | ||
1721 | st1_tag = FPU_Special(st1_ptr); | ||
1722 | |||
1723 | if ( (st0_tag == TAG_Valid) || (st0_tag == TW_Denormal) ) | ||
1724 | { | ||
1725 | switch ( st1_tag ) | ||
1726 | { | ||
1727 | case TAG_Valid: | ||
1728 | /* st(0) must be a denormal */ | ||
1729 | if ( (st0_tag == TW_Denormal) && (denormal_operand() < 0) ) | ||
1730 | return; | ||
1731 | |||
1732 | FPU_to_exp16(st0_ptr, st0_ptr); /* Will not be left on stack */ | ||
1733 | goto valid_scale; | ||
1734 | |||
1735 | case TAG_Zero: | ||
1736 | if ( st0_tag == TW_Denormal ) | ||
1737 | denormal_operand(); | ||
1738 | return; | ||
1739 | |||
1740 | case TW_Denormal: | ||
1741 | denormal_operand(); | ||
1742 | return; | ||
1743 | |||
1744 | case TW_Infinity: | ||
1745 | if ( (st0_tag == TW_Denormal) && (denormal_operand() < 0) ) | ||
1746 | return; | ||
1747 | |||
1748 | if ( signpositive(st1_ptr) ) | ||
1749 | FPU_copy_to_reg0(&CONST_INF, TAG_Special); | ||
1750 | else | ||
1751 | FPU_copy_to_reg0(&CONST_Z, TAG_Zero); | ||
1752 | setsign(st0_ptr, sign); | ||
1753 | return; | ||
1754 | 1510 | ||
1755 | case TW_NaN: | 1511 | control_word &= ~CW_RC; |
1756 | real_2op_NaN(st1_ptr, st1_tag, 0, st0_ptr); | 1512 | control_word |= RC_CHOP; |
1757 | return; | 1513 | reg_copy(st1_ptr, &tmp); |
1758 | } | 1514 | FPU_round_to_int(&tmp, st1_tag); /* This can never overflow here */ |
1759 | } | 1515 | control_word = old_cw; |
1760 | else if ( st0_tag == TAG_Zero ) | 1516 | scale = signnegative(st1_ptr) ? -tmp.sigl : tmp.sigl; |
1761 | { | 1517 | scale += exponent16(st0_ptr); |
1762 | switch ( st1_tag ) | ||
1763 | { | ||
1764 | case TAG_Valid: | ||
1765 | case TAG_Zero: | ||
1766 | return; | ||
1767 | 1518 | ||
1768 | case TW_Denormal: | 1519 | setexponent16(st0_ptr, scale); |
1769 | denormal_operand(); | ||
1770 | return; | ||
1771 | 1520 | ||
1772 | case TW_Infinity: | 1521 | /* Use FPU_round() to properly detect under/overflow etc */ |
1773 | if ( signpositive(st1_ptr) ) | 1522 | FPU_round(st0_ptr, 0, 0, control_word, sign); |
1774 | arith_invalid(0); /* Zero scaled by +Infinity */ | ||
1775 | return; | ||
1776 | 1523 | ||
1777 | case TW_NaN: | 1524 | return; |
1778 | real_2op_NaN(st1_ptr, st1_tag, 0, st0_ptr); | ||
1779 | return; | ||
1780 | } | 1525 | } |
1781 | } | ||
1782 | else if ( st0_tag == TW_Infinity ) | ||
1783 | { | ||
1784 | switch ( st1_tag ) | ||
1785 | { | ||
1786 | case TAG_Valid: | ||
1787 | case TAG_Zero: | ||
1788 | return; | ||
1789 | |||
1790 | case TW_Denormal: | ||
1791 | denormal_operand(); | ||
1792 | return; | ||
1793 | 1526 | ||
1794 | case TW_Infinity: | 1527 | if (st0_tag == TAG_Special) |
1795 | if ( signnegative(st1_ptr) ) | 1528 | st0_tag = FPU_Special(st0_ptr); |
1796 | arith_invalid(0); /* Infinity scaled by -Infinity */ | 1529 | if (st1_tag == TAG_Special) |
1797 | return; | 1530 | st1_tag = FPU_Special(st1_ptr); |
1798 | 1531 | ||
1799 | case TW_NaN: | 1532 | if ((st0_tag == TAG_Valid) || (st0_tag == TW_Denormal)) { |
1800 | real_2op_NaN(st1_ptr, st1_tag, 0, st0_ptr); | 1533 | switch (st1_tag) { |
1801 | return; | 1534 | case TAG_Valid: |
1535 | /* st(0) must be a denormal */ | ||
1536 | if ((st0_tag == TW_Denormal) | ||
1537 | && (denormal_operand() < 0)) | ||
1538 | return; | ||
1539 | |||
1540 | FPU_to_exp16(st0_ptr, st0_ptr); /* Will not be left on stack */ | ||
1541 | goto valid_scale; | ||
1542 | |||
1543 | case TAG_Zero: | ||
1544 | if (st0_tag == TW_Denormal) | ||
1545 | denormal_operand(); | ||
1546 | return; | ||
1547 | |||
1548 | case TW_Denormal: | ||
1549 | denormal_operand(); | ||
1550 | return; | ||
1551 | |||
1552 | case TW_Infinity: | ||
1553 | if ((st0_tag == TW_Denormal) | ||
1554 | && (denormal_operand() < 0)) | ||
1555 | return; | ||
1556 | |||
1557 | if (signpositive(st1_ptr)) | ||
1558 | FPU_copy_to_reg0(&CONST_INF, TAG_Special); | ||
1559 | else | ||
1560 | FPU_copy_to_reg0(&CONST_Z, TAG_Zero); | ||
1561 | setsign(st0_ptr, sign); | ||
1562 | return; | ||
1563 | |||
1564 | case TW_NaN: | ||
1565 | real_2op_NaN(st1_ptr, st1_tag, 0, st0_ptr); | ||
1566 | return; | ||
1567 | } | ||
1568 | } else if (st0_tag == TAG_Zero) { | ||
1569 | switch (st1_tag) { | ||
1570 | case TAG_Valid: | ||
1571 | case TAG_Zero: | ||
1572 | return; | ||
1573 | |||
1574 | case TW_Denormal: | ||
1575 | denormal_operand(); | ||
1576 | return; | ||
1577 | |||
1578 | case TW_Infinity: | ||
1579 | if (signpositive(st1_ptr)) | ||
1580 | arith_invalid(0); /* Zero scaled by +Infinity */ | ||
1581 | return; | ||
1582 | |||
1583 | case TW_NaN: | ||
1584 | real_2op_NaN(st1_ptr, st1_tag, 0, st0_ptr); | ||
1585 | return; | ||
1586 | } | ||
1587 | } else if (st0_tag == TW_Infinity) { | ||
1588 | switch (st1_tag) { | ||
1589 | case TAG_Valid: | ||
1590 | case TAG_Zero: | ||
1591 | return; | ||
1592 | |||
1593 | case TW_Denormal: | ||
1594 | denormal_operand(); | ||
1595 | return; | ||
1596 | |||
1597 | case TW_Infinity: | ||
1598 | if (signnegative(st1_ptr)) | ||
1599 | arith_invalid(0); /* Infinity scaled by -Infinity */ | ||
1600 | return; | ||
1601 | |||
1602 | case TW_NaN: | ||
1603 | real_2op_NaN(st1_ptr, st1_tag, 0, st0_ptr); | ||
1604 | return; | ||
1605 | } | ||
1606 | } else if (st0_tag == TW_NaN) { | ||
1607 | if (st1_tag != TAG_Empty) { | ||
1608 | real_2op_NaN(st1_ptr, st1_tag, 0, st0_ptr); | ||
1609 | return; | ||
1610 | } | ||
1802 | } | 1611 | } |
1803 | } | ||
1804 | else if ( st0_tag == TW_NaN ) | ||
1805 | { | ||
1806 | if ( st1_tag != TAG_Empty ) | ||
1807 | { real_2op_NaN(st1_ptr, st1_tag, 0, st0_ptr); return; } | ||
1808 | } | ||
1809 | |||
1810 | #ifdef PARANOID | 1612 | #ifdef PARANOID |
1811 | if ( !((st0_tag == TAG_Empty) || (st1_tag == TAG_Empty)) ) | 1613 | if (!((st0_tag == TAG_Empty) || (st1_tag == TAG_Empty))) { |
1812 | { | 1614 | EXCEPTION(EX_INTERNAL | 0x115); |
1813 | EXCEPTION(EX_INTERNAL | 0x115); | 1615 | return; |
1814 | return; | 1616 | } |
1815 | } | ||
1816 | #endif | 1617 | #endif |
1817 | 1618 | ||
1818 | /* At least one of st(0), st(1) must be empty */ | 1619 | /* At least one of st(0), st(1) must be empty */ |
1819 | FPU_stack_underflow(); | 1620 | FPU_stack_underflow(); |
1820 | 1621 | ||
1821 | } | 1622 | } |
1822 | 1623 | ||
1823 | |||
1824 | /*---------------------------------------------------------------------------*/ | 1624 | /*---------------------------------------------------------------------------*/ |
1825 | 1625 | ||
1826 | static FUNC_ST0 const trig_table_a[] = { | 1626 | static FUNC_ST0 const trig_table_a[] = { |
1827 | f2xm1, fyl2x, fptan, fpatan, | 1627 | f2xm1, fyl2x, fptan, fpatan, |
1828 | fxtract, fprem1, (FUNC_ST0)fdecstp, (FUNC_ST0)fincstp | 1628 | fxtract, fprem1, (FUNC_ST0) fdecstp, (FUNC_ST0) fincstp |
1829 | }; | 1629 | }; |
1830 | 1630 | ||
1831 | void FPU_triga(void) | 1631 | void FPU_triga(void) |
1832 | { | 1632 | { |
1833 | (trig_table_a[FPU_rm])(&st(0), FPU_gettag0()); | 1633 | (trig_table_a[FPU_rm]) (&st(0), FPU_gettag0()); |
1834 | } | 1634 | } |
1835 | 1635 | ||
1836 | 1636 | static FUNC_ST0 const trig_table_b[] = { | |
1837 | static FUNC_ST0 const trig_table_b[] = | 1637 | fprem, fyl2xp1, fsqrt_, fsincos, frndint_, fscale, (FUNC_ST0) fsin, fcos |
1838 | { | 1638 | }; |
1839 | fprem, fyl2xp1, fsqrt_, fsincos, frndint_, fscale, (FUNC_ST0)fsin, fcos | ||
1840 | }; | ||
1841 | 1639 | ||
1842 | void FPU_trigb(void) | 1640 | void FPU_trigb(void) |
1843 | { | 1641 | { |
1844 | (trig_table_b[FPU_rm])(&st(0), FPU_gettag0()); | 1642 | (trig_table_b[FPU_rm]) (&st(0), FPU_gettag0()); |
1845 | } | 1643 | } |