Linux 4.1.18
[linux/fpc-iii.git] / arch / mips / math-emu / sp_fdp.c
blob3797148893adb62c10a989dc78e5e9dce56e1e9e
1 /* IEEE754 floating point arithmetic
2 * single precision
3 */
4 /*
5 * MIPS floating point support
6 * Copyright (C) 1994-2000 Algorithmics Ltd.
8 * This program is free software; you can distribute it and/or modify it
9 * under the terms of the GNU General Public License (Version 2) as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "ieee754sp.h"
23 #include "ieee754dp.h"
25 static inline union ieee754sp ieee754sp_nan_fdp(int xs, u64 xm)
27 return buildsp(xs, SP_EMAX + 1 + SP_EBIAS,
28 xm >> (DP_FBITS - SP_FBITS));
31 union ieee754sp ieee754sp_fdp(union ieee754dp x)
33 union ieee754sp y;
34 u32 rm;
36 COMPXDP;
37 COMPYSP;
39 EXPLODEXDP;
41 ieee754_clearcx();
43 FLUSHXDP;
45 switch (xc) {
46 case IEEE754_CLASS_SNAN:
47 return ieee754sp_nanxcpt(ieee754sp_nan_fdp(xs, xm));
49 case IEEE754_CLASS_QNAN:
50 y = ieee754sp_nan_fdp(xs, xm);
51 EXPLODEYSP;
52 if (!ieee754_class_nan(yc))
53 y = ieee754sp_indef();
54 return y;
56 case IEEE754_CLASS_INF:
57 return ieee754sp_inf(xs);
59 case IEEE754_CLASS_ZERO:
60 return ieee754sp_zero(xs);
62 case IEEE754_CLASS_DNORM:
63 /* can't possibly be sp representable */
64 ieee754_setcx(IEEE754_UNDERFLOW);
65 ieee754_setcx(IEEE754_INEXACT);
66 if ((ieee754_csr.rm == FPU_CSR_RU && !xs) ||
67 (ieee754_csr.rm == FPU_CSR_RD && xs))
68 return ieee754sp_mind(xs);
69 return ieee754sp_zero(xs);
71 case IEEE754_CLASS_NORM:
72 break;
76 * Convert from DP_FBITS to SP_FBITS+3 with sticky right shift.
78 rm = (xm >> (DP_FBITS - (SP_FBITS + 3))) |
79 ((xm << (64 - (DP_FBITS - (SP_FBITS + 3)))) != 0);
81 return ieee754sp_format(xs, xe, rm);