1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
5 * Floating-point emulation code
12 * @(#) pa/spmath/fcnvuf.c $Revision: 1.1 $
15 * Fixed point to Floating-point Converts
17 * External Interfaces:
18 * dbl_to_dbl_fcnvuf(srcptr,nullptr,dstptr,status)
19 * dbl_to_sgl_fcnvuf(srcptr,nullptr,dstptr,status)
20 * sgl_to_dbl_fcnvuf(srcptr,nullptr,dstptr,status)
21 * sgl_to_sgl_fcnvuf(srcptr,nullptr,dstptr,status)
23 * Internal Interfaces:
26 * <<please update with a overview of the operation of this file>>
33 #include "sgl_float.h"
34 #include "dbl_float.h"
35 #include "cnv_float.h"
37 /************************************************************************
38 * Fixed point to Floating-point Converts *
39 ************************************************************************/
42 * Convert Single Unsigned Fixed to Single Floating-point format
48 unsigned int *nullptr,
49 sgl_floating_point *dstptr,
52 register unsigned int src, result = 0;
53 register int dst_exponent;
64 * Generate exponent and normalized mantissa
66 dst_exponent = 16; /* initialize for normalization */
68 * Check word for most significant bit set. Returns
69 * a value in dst_exponent indicating the bit position,
72 Find_ms_one_bit(src,dst_exponent);
73 /* left justify source, with msb at bit position 0 */
74 src <<= dst_exponent+1;
75 Sgl_set_mantissa(result, src >> SGL_EXP_LENGTH);
76 Sgl_set_exponent(result, 30+SGL_BIAS - dst_exponent);
78 /* check for inexact */
79 if (Suint_isinexact_to_sgl(src)) {
80 switch (Rounding_mode()) {
82 Sgl_increment(result);
84 case ROUNDMINUS: /* never negative */
87 Sgl_roundnearest_from_suint(src,result);
90 if (Is_inexacttrap_enabled()) {
92 return(INEXACTEXCEPTION);
94 else Set_inexactflag();
101 * Single Unsigned Fixed to Double Floating-point
106 unsigned int *srcptr,
107 unsigned int *nullptr,
108 dbl_floating_point *dstptr,
109 unsigned int *status)
111 register int dst_exponent;
112 register unsigned int src, resultp1 = 0, resultp2 = 0;
118 Dbl_setzero(resultp1,resultp2);
119 Dbl_copytoptr(resultp1,resultp2,dstptr);
123 * Generate exponent and normalized mantissa
125 dst_exponent = 16; /* initialize for normalization */
127 * Check word for most significant bit set. Returns
128 * a value in dst_exponent indicating the bit position,
131 Find_ms_one_bit(src,dst_exponent);
132 /* left justify source, with msb at bit position 0 */
133 src <<= dst_exponent+1;
134 Dbl_set_mantissap1(resultp1, src >> DBL_EXP_LENGTH);
135 Dbl_set_mantissap2(resultp2, src << (32-DBL_EXP_LENGTH));
136 Dbl_set_exponent(resultp1, (30+DBL_BIAS) - dst_exponent);
137 Dbl_copytoptr(resultp1,resultp2,dstptr);
142 * Double Unsigned Fixed to Single Floating-point
147 dbl_unsigned *srcptr,
148 unsigned int *nullptr,
149 sgl_floating_point *dstptr,
150 unsigned int *status)
153 unsigned int srcp1, srcp2, result = 0;
155 Duint_copyfromptr(srcptr,srcp1,srcp2);
158 if (srcp1 == 0 && srcp2 == 0) {
164 * Generate exponent and normalized mantissa
166 dst_exponent = 16; /* initialize for normalization */
169 * Check word for most significant bit set. Returns
170 * a value in dst_exponent indicating the bit position,
173 Find_ms_one_bit(srcp2,dst_exponent);
174 /* left justify source, with msb at bit position 0 */
175 srcp1 = srcp2 << dst_exponent+1;
178 * since msb set is in second word, need to
179 * adjust bit position count
185 * Check word for most significant bit set. Returns
186 * a value in dst_exponent indicating the bit position,
190 Find_ms_one_bit(srcp1,dst_exponent);
191 /* left justify source, with msb at bit position 0 */
192 if (dst_exponent >= 0) {
193 Variable_shift_double(srcp1,srcp2,(31-dst_exponent),
195 srcp2 <<= dst_exponent+1;
198 Sgl_set_mantissa(result, srcp1 >> SGL_EXP_LENGTH);
199 Sgl_set_exponent(result, (62+SGL_BIAS) - dst_exponent);
201 /* check for inexact */
202 if (Duint_isinexact_to_sgl(srcp1,srcp2)) {
203 switch (Rounding_mode()) {
205 Sgl_increment(result);
207 case ROUNDMINUS: /* never negative */
210 Sgl_roundnearest_from_duint(srcp1,srcp2,result);
213 if (Is_inexacttrap_enabled()) {
215 return(INEXACTEXCEPTION);
217 else Set_inexactflag();
224 * Double Unsigned Fixed to Double Floating-point
229 dbl_unsigned *srcptr,
230 unsigned int *nullptr,
231 dbl_floating_point *dstptr,
232 unsigned int *status)
234 register int dst_exponent;
235 register unsigned int srcp1, srcp2, resultp1 = 0, resultp2 = 0;
237 Duint_copyfromptr(srcptr,srcp1,srcp2);
240 if (srcp1 == 0 && srcp2 ==0) {
241 Dbl_setzero(resultp1,resultp2);
242 Dbl_copytoptr(resultp1,resultp2,dstptr);
246 * Generate exponent and normalized mantissa
248 dst_exponent = 16; /* initialize for normalization */
251 * Check word for most significant bit set. Returns
252 * a value in dst_exponent indicating the bit position,
255 Find_ms_one_bit(srcp2,dst_exponent);
256 /* left justify source, with msb at bit position 0 */
257 srcp1 = srcp2 << dst_exponent+1;
260 * since msb set is in second word, need to
261 * adjust bit position count
267 * Check word for most significant bit set. Returns
268 * a value in dst_exponent indicating the bit position,
271 Find_ms_one_bit(srcp1,dst_exponent);
272 /* left justify source, with msb at bit position 0 */
273 if (dst_exponent >= 0) {
274 Variable_shift_double(srcp1,srcp2,(31-dst_exponent),
276 srcp2 <<= dst_exponent+1;
279 Dbl_set_mantissap1(resultp1, srcp1 >> DBL_EXP_LENGTH);
280 Shiftdouble(srcp1,srcp2,DBL_EXP_LENGTH,resultp2);
281 Dbl_set_exponent(resultp1, (62+DBL_BIAS) - dst_exponent);
283 /* check for inexact */
284 if (Duint_isinexact_to_dbl(srcp2)) {
285 switch (Rounding_mode()) {
287 Dbl_increment(resultp1,resultp2);
289 case ROUNDMINUS: /* never negative */
292 Dbl_roundnearest_from_duint(srcp2,resultp1,
296 if (Is_inexacttrap_enabled()) {
297 Dbl_copytoptr(resultp1,resultp2,dstptr);
298 return(INEXACTEXCEPTION);
300 else Set_inexactflag();
302 Dbl_copytoptr(resultp1,resultp2,dstptr);