Linux 5.7.6
[linux/fpc-iii.git] / arch / mips / math-emu / dp_fsp.c
blobbe8a929c420698f8e78a90d0ca58c2990349c768
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* IEEE754 floating point arithmetic
3 * double precision: common utilities
4 */
5 /*
6 * MIPS floating point support
7 * Copyright (C) 1994-2000 Algorithmics Ltd.
8 */
10 #include "ieee754sp.h"
11 #include "ieee754dp.h"
13 static inline union ieee754dp ieee754dp_nan_fsp(int xs, u64 xm)
15 return builddp(xs, DP_EMAX + 1 + DP_EBIAS,
16 xm << (DP_FBITS - SP_FBITS));
19 union ieee754dp ieee754dp_fsp(union ieee754sp x)
21 COMPXSP;
23 EXPLODEXSP;
25 ieee754_clearcx();
27 FLUSHXSP;
29 switch (xc) {
30 case IEEE754_CLASS_SNAN:
31 return ieee754dp_nanxcpt(ieee754dp_nan_fsp(xs, xm));
33 case IEEE754_CLASS_QNAN:
34 return ieee754dp_nan_fsp(xs, xm);
36 case IEEE754_CLASS_INF:
37 return ieee754dp_inf(xs);
39 case IEEE754_CLASS_ZERO:
40 return ieee754dp_zero(xs);
42 case IEEE754_CLASS_DNORM:
43 /* normalize */
44 while ((xm >> SP_FBITS) == 0) {
45 xm <<= 1;
46 xe--;
48 break;
50 case IEEE754_CLASS_NORM:
51 break;
55 * Can't possibly overflow,underflow, or need rounding
58 /* drop the hidden bit */
59 xm &= ~SP_HIDDEN_BIT;
61 return builddp(xs, xe + DP_EBIAS,
62 (u64) xm << (DP_FBITS - SP_FBITS));