pci-acpi: remove duplicate code for _OSC
[linux-2.6/mini2440.git] / arch / parisc / math-emu / fcnvff.c
blob76c063f7d17cbf994202a51143d4cd1323bea3d7
1 /*
2 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
4 * Floating-point emulation code
5 * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * BEGIN_DESC
24 * File:
25 * @(#) pa/spmath/fcnvff.c $Revision: 1.1 $
27 * Purpose:
28 * Single Floating-point to Double Floating-point
29 * Double Floating-point to Single Floating-point
31 * External Interfaces:
32 * dbl_to_sgl_fcnvff(srcptr,nullptr,dstptr,status)
33 * sgl_to_dbl_fcnvff(srcptr,nullptr,dstptr,status)
35 * Internal Interfaces:
37 * Theory:
38 * <<please update with a overview of the operation of this file>>
40 * END_DESC
44 #include "float.h"
45 #include "sgl_float.h"
46 #include "dbl_float.h"
47 #include "cnv_float.h"
50 * Single Floating-point to Double Floating-point
52 /*ARGSUSED*/
53 int
54 sgl_to_dbl_fcnvff(
55 sgl_floating_point *srcptr,
56 unsigned int *nullptr,
57 dbl_floating_point *dstptr,
58 unsigned int *status)
60 register unsigned int src, resultp1, resultp2;
61 register int src_exponent;
63 src = *srcptr;
64 src_exponent = Sgl_exponent(src);
65 Dbl_allp1(resultp1) = Sgl_all(src); /* set sign of result */
66 /*
67 * Test for NaN or infinity
69 if (src_exponent == SGL_INFINITY_EXPONENT) {
71 * determine if NaN or infinity
73 if (Sgl_iszero_mantissa(src)) {
75 * is infinity; want to return double infinity
77 Dbl_setinfinity_exponentmantissa(resultp1,resultp2);
78 Dbl_copytoptr(resultp1,resultp2,dstptr);
79 return(NOEXCEPTION);
81 else {
82 /*
83 * is NaN; signaling or quiet?
85 if (Sgl_isone_signaling(src)) {
86 /* trap if INVALIDTRAP enabled */
87 if (Is_invalidtrap_enabled())
88 return(INVALIDEXCEPTION);
89 /* make NaN quiet */
90 else {
91 Set_invalidflag();
92 Sgl_set_quiet(src);
95 /*
96 * NaN is quiet, return as double NaN
98 Dbl_setinfinity_exponent(resultp1);
99 Sgl_to_dbl_mantissa(src,resultp1,resultp2);
100 Dbl_copytoptr(resultp1,resultp2,dstptr);
101 return(NOEXCEPTION);
105 * Test for zero or denormalized
107 if (src_exponent == 0) {
109 * determine if zero or denormalized
111 if (Sgl_isnotzero_mantissa(src)) {
113 * is denormalized; want to normalize
115 Sgl_clear_signexponent(src);
116 Sgl_leftshiftby1(src);
117 Sgl_normalize(src,src_exponent);
118 Sgl_to_dbl_exponent(src_exponent,resultp1);
119 Sgl_to_dbl_mantissa(src,resultp1,resultp2);
121 else {
122 Dbl_setzero_exponentmantissa(resultp1,resultp2);
124 Dbl_copytoptr(resultp1,resultp2,dstptr);
125 return(NOEXCEPTION);
128 * No special cases, just complete the conversion
130 Sgl_to_dbl_exponent(src_exponent, resultp1);
131 Sgl_to_dbl_mantissa(Sgl_mantissa(src), resultp1,resultp2);
132 Dbl_copytoptr(resultp1,resultp2,dstptr);
133 return(NOEXCEPTION);
137 * Double Floating-point to Single Floating-point
139 /*ARGSUSED*/
141 dbl_to_sgl_fcnvff(
142 dbl_floating_point *srcptr,
143 unsigned int *nullptr,
144 sgl_floating_point *dstptr,
145 unsigned int *status)
147 register unsigned int srcp1, srcp2, result;
148 register int src_exponent, dest_exponent, dest_mantissa;
149 register boolean inexact = FALSE, guardbit = FALSE, stickybit = FALSE;
150 register boolean lsb_odd = FALSE;
151 boolean is_tiny;
153 Dbl_copyfromptr(srcptr,srcp1,srcp2);
154 src_exponent = Dbl_exponent(srcp1);
155 Sgl_all(result) = Dbl_allp1(srcp1); /* set sign of result */
157 * Test for NaN or infinity
159 if (src_exponent == DBL_INFINITY_EXPONENT) {
161 * determine if NaN or infinity
163 if (Dbl_iszero_mantissa(srcp1,srcp2)) {
165 * is infinity; want to return single infinity
167 Sgl_setinfinity_exponentmantissa(result);
168 *dstptr = result;
169 return(NOEXCEPTION);
172 * is NaN; signaling or quiet?
174 if (Dbl_isone_signaling(srcp1)) {
175 /* trap if INVALIDTRAP enabled */
176 if (Is_invalidtrap_enabled()) return(INVALIDEXCEPTION);
177 else {
178 Set_invalidflag();
179 /* make NaN quiet */
180 Dbl_set_quiet(srcp1);
184 * NaN is quiet, return as single NaN
186 Sgl_setinfinity_exponent(result);
187 Sgl_set_mantissa(result,Dallp1(srcp1)<<3 | Dallp2(srcp2)>>29);
188 if (Sgl_iszero_mantissa(result)) Sgl_set_quiet(result);
189 *dstptr = result;
190 return(NOEXCEPTION);
193 * Generate result
195 Dbl_to_sgl_exponent(src_exponent,dest_exponent);
196 if (dest_exponent > 0) {
197 Dbl_to_sgl_mantissa(srcp1,srcp2,dest_mantissa,inexact,guardbit,
198 stickybit,lsb_odd);
200 else {
201 if (Dbl_iszero_exponentmantissa(srcp1,srcp2)){
202 Sgl_setzero_exponentmantissa(result);
203 *dstptr = result;
204 return(NOEXCEPTION);
206 if (Is_underflowtrap_enabled()) {
207 Dbl_to_sgl_mantissa(srcp1,srcp2,dest_mantissa,inexact,
208 guardbit,stickybit,lsb_odd);
210 else {
211 /* compute result, determine inexact info,
212 * and set Underflowflag if appropriate
214 Dbl_to_sgl_denormalized(srcp1,srcp2,dest_exponent,
215 dest_mantissa,inexact,guardbit,stickybit,lsb_odd,
216 is_tiny);
220 * Now round result if not exact
222 if (inexact) {
223 switch (Rounding_mode()) {
224 case ROUNDPLUS:
225 if (Sgl_iszero_sign(result)) dest_mantissa++;
226 break;
227 case ROUNDMINUS:
228 if (Sgl_isone_sign(result)) dest_mantissa++;
229 break;
230 case ROUNDNEAREST:
231 if (guardbit) {
232 if (stickybit || lsb_odd) dest_mantissa++;
236 Sgl_set_exponentmantissa(result,dest_mantissa);
239 * check for mantissa overflow after rounding
241 if ((dest_exponent>0 || Is_underflowtrap_enabled()) &&
242 Sgl_isone_hidden(result)) dest_exponent++;
245 * Test for overflow
247 if (dest_exponent >= SGL_INFINITY_EXPONENT) {
248 /* trap if OVERFLOWTRAP enabled */
249 if (Is_overflowtrap_enabled()) {
251 * Check for gross overflow
253 if (dest_exponent >= SGL_INFINITY_EXPONENT+SGL_WRAP)
254 return(UNIMPLEMENTEDEXCEPTION);
257 * Adjust bias of result
259 Sgl_setwrapped_exponent(result,dest_exponent,ovfl);
260 *dstptr = result;
261 if (inexact)
262 if (Is_inexacttrap_enabled())
263 return(OVERFLOWEXCEPTION|INEXACTEXCEPTION);
264 else Set_inexactflag();
265 return(OVERFLOWEXCEPTION);
267 Set_overflowflag();
268 inexact = TRUE;
269 /* set result to infinity or largest number */
270 Sgl_setoverflow(result);
273 * Test for underflow
275 else if (dest_exponent <= 0) {
276 /* trap if UNDERFLOWTRAP enabled */
277 if (Is_underflowtrap_enabled()) {
279 * Check for gross underflow
281 if (dest_exponent <= -(SGL_WRAP))
282 return(UNIMPLEMENTEDEXCEPTION);
284 * Adjust bias of result
286 Sgl_setwrapped_exponent(result,dest_exponent,unfl);
287 *dstptr = result;
288 if (inexact)
289 if (Is_inexacttrap_enabled())
290 return(UNDERFLOWEXCEPTION|INEXACTEXCEPTION);
291 else Set_inexactflag();
292 return(UNDERFLOWEXCEPTION);
295 * result is denormalized or signed zero
297 if (inexact && is_tiny) Set_underflowflag();
300 else Sgl_set_exponent(result,dest_exponent);
301 *dstptr = result;
303 * Trap if inexact trap is enabled
305 if (inexact)
306 if (Is_inexacttrap_enabled()) return(INEXACTEXCEPTION);
307 else Set_inexactflag();
308 return(NOEXCEPTION);