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)
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
25 * @(#) pa/spmath/fcnvuf.c $Revision: 1.1 $
28 * Fixed point to Floating-point Converts
30 * External Interfaces:
31 * dbl_to_dbl_fcnvuf(srcptr,nullptr,dstptr,status)
32 * dbl_to_sgl_fcnvuf(srcptr,nullptr,dstptr,status)
33 * sgl_to_dbl_fcnvuf(srcptr,nullptr,dstptr,status)
34 * sgl_to_sgl_fcnvuf(srcptr,nullptr,dstptr,status)
36 * Internal Interfaces:
39 * <<please update with a overview of the operation of this file>>
46 #include "sgl_float.h"
47 #include "dbl_float.h"
48 #include "cnv_float.h"
50 /************************************************************************
51 * Fixed point to Floating-point Converts *
52 ************************************************************************/
55 * Convert Single Unsigned Fixed to Single Floating-point format
61 unsigned int *nullptr,
62 sgl_floating_point
*dstptr
,
65 register unsigned int src
, result
= 0;
66 register int dst_exponent
;
77 * Generate exponent and normalized mantissa
79 dst_exponent
= 16; /* initialize for normalization */
81 * Check word for most significant bit set. Returns
82 * a value in dst_exponent indicating the bit position,
85 Find_ms_one_bit(src
,dst_exponent
);
86 /* left justify source, with msb at bit position 0 */
87 src
<<= dst_exponent
+1;
88 Sgl_set_mantissa(result
, src
>> SGL_EXP_LENGTH
);
89 Sgl_set_exponent(result
, 30+SGL_BIAS
- dst_exponent
);
91 /* check for inexact */
92 if (Suint_isinexact_to_sgl(src
)) {
93 switch (Rounding_mode()) {
95 Sgl_increment(result
);
97 case ROUNDMINUS
: /* never negative */
100 Sgl_roundnearest_from_suint(src
,result
);
103 if (Is_inexacttrap_enabled()) {
105 return(INEXACTEXCEPTION
);
107 else Set_inexactflag();
114 * Single Unsigned Fixed to Double Floating-point
119 unsigned int *srcptr
,
120 unsigned int *nullptr,
121 dbl_floating_point
*dstptr
,
122 unsigned int *status
)
124 register int dst_exponent
;
125 register unsigned int src
, resultp1
= 0, resultp2
= 0;
131 Dbl_setzero(resultp1
,resultp2
);
132 Dbl_copytoptr(resultp1
,resultp2
,dstptr
);
136 * Generate exponent and normalized mantissa
138 dst_exponent
= 16; /* initialize for normalization */
140 * Check word for most significant bit set. Returns
141 * a value in dst_exponent indicating the bit position,
144 Find_ms_one_bit(src
,dst_exponent
);
145 /* left justify source, with msb at bit position 0 */
146 src
<<= dst_exponent
+1;
147 Dbl_set_mantissap1(resultp1
, src
>> DBL_EXP_LENGTH
);
148 Dbl_set_mantissap2(resultp2
, src
<< (32-DBL_EXP_LENGTH
));
149 Dbl_set_exponent(resultp1
, (30+DBL_BIAS
) - dst_exponent
);
150 Dbl_copytoptr(resultp1
,resultp2
,dstptr
);
155 * Double Unsigned Fixed to Single Floating-point
160 dbl_unsigned
*srcptr
,
161 unsigned int *nullptr,
162 sgl_floating_point
*dstptr
,
163 unsigned int *status
)
166 unsigned int srcp1
, srcp2
, result
= 0;
168 Duint_copyfromptr(srcptr
,srcp1
,srcp2
);
171 if (srcp1
== 0 && srcp2
== 0) {
177 * Generate exponent and normalized mantissa
179 dst_exponent
= 16; /* initialize for normalization */
182 * Check word for most significant bit set. Returns
183 * a value in dst_exponent indicating the bit position,
186 Find_ms_one_bit(srcp2
,dst_exponent
);
187 /* left justify source, with msb at bit position 0 */
188 srcp1
= srcp2
<< dst_exponent
+1;
191 * since msb set is in second word, need to
192 * adjust bit position count
198 * Check word for most significant bit set. Returns
199 * a value in dst_exponent indicating the bit position,
203 Find_ms_one_bit(srcp1
,dst_exponent
);
204 /* left justify source, with msb at bit position 0 */
205 if (dst_exponent
>= 0) {
206 Variable_shift_double(srcp1
,srcp2
,(31-dst_exponent
),
208 srcp2
<<= dst_exponent
+1;
211 Sgl_set_mantissa(result
, srcp1
>> SGL_EXP_LENGTH
);
212 Sgl_set_exponent(result
, (62+SGL_BIAS
) - dst_exponent
);
214 /* check for inexact */
215 if (Duint_isinexact_to_sgl(srcp1
,srcp2
)) {
216 switch (Rounding_mode()) {
218 Sgl_increment(result
);
220 case ROUNDMINUS
: /* never negative */
223 Sgl_roundnearest_from_duint(srcp1
,srcp2
,result
);
226 if (Is_inexacttrap_enabled()) {
228 return(INEXACTEXCEPTION
);
230 else Set_inexactflag();
237 * Double Unsigned Fixed to Double Floating-point
242 dbl_unsigned
*srcptr
,
243 unsigned int *nullptr,
244 dbl_floating_point
*dstptr
,
245 unsigned int *status
)
247 register int dst_exponent
;
248 register unsigned int srcp1
, srcp2
, resultp1
= 0, resultp2
= 0;
250 Duint_copyfromptr(srcptr
,srcp1
,srcp2
);
253 if (srcp1
== 0 && srcp2
==0) {
254 Dbl_setzero(resultp1
,resultp2
);
255 Dbl_copytoptr(resultp1
,resultp2
,dstptr
);
259 * Generate exponent and normalized mantissa
261 dst_exponent
= 16; /* initialize for normalization */
264 * Check word for most significant bit set. Returns
265 * a value in dst_exponent indicating the bit position,
268 Find_ms_one_bit(srcp2
,dst_exponent
);
269 /* left justify source, with msb at bit position 0 */
270 srcp1
= srcp2
<< dst_exponent
+1;
273 * since msb set is in second word, need to
274 * adjust bit position count
280 * Check word for most significant bit set. Returns
281 * a value in dst_exponent indicating the bit position,
284 Find_ms_one_bit(srcp1
,dst_exponent
);
285 /* left justify source, with msb at bit position 0 */
286 if (dst_exponent
>= 0) {
287 Variable_shift_double(srcp1
,srcp2
,(31-dst_exponent
),
289 srcp2
<<= dst_exponent
+1;
292 Dbl_set_mantissap1(resultp1
, srcp1
>> DBL_EXP_LENGTH
);
293 Shiftdouble(srcp1
,srcp2
,DBL_EXP_LENGTH
,resultp2
);
294 Dbl_set_exponent(resultp1
, (62+DBL_BIAS
) - dst_exponent
);
296 /* check for inexact */
297 if (Duint_isinexact_to_dbl(srcp2
)) {
298 switch (Rounding_mode()) {
300 Dbl_increment(resultp1
,resultp2
);
302 case ROUNDMINUS
: /* never negative */
305 Dbl_roundnearest_from_duint(srcp2
,resultp1
,
309 if (Is_inexacttrap_enabled()) {
310 Dbl_copytoptr(resultp1
,resultp2
,dstptr
);
311 return(INEXACTEXCEPTION
);
313 else Set_inexactflag();
315 Dbl_copytoptr(resultp1
,resultp2
,dstptr
);