diff options
Diffstat (limited to 'arch/mips/math-emu/dp_tint.c')
-rw-r--r-- | arch/mips/math-emu/dp_tint.c | 69 |
1 files changed, 26 insertions, 43 deletions
diff --git a/arch/mips/math-emu/dp_tint.c b/arch/mips/math-emu/dp_tint.c index 0ebe8598b94a..6ffc336c530e 100644 --- a/arch/mips/math-emu/dp_tint.c +++ b/arch/mips/math-emu/dp_tint.c | |||
@@ -5,8 +5,6 @@ | |||
5 | * MIPS floating point support | 5 | * MIPS floating point support |
6 | * Copyright (C) 1994-2000 Algorithmics Ltd. | 6 | * Copyright (C) 1994-2000 Algorithmics Ltd. |
7 | * | 7 | * |
8 | * ######################################################################## | ||
9 | * | ||
10 | * This program is free software; you can distribute it and/or modify it | 8 | * This program is free software; you can distribute it and/or modify it |
11 | * under the terms of the GNU General Public License (Version 2) as | 9 | * under the terms of the GNU General Public License (Version 2) as |
12 | * published by the Free Software Foundation. | 10 | * published by the Free Software Foundation. |
@@ -18,20 +16,21 @@ | |||
18 | * | 16 | * |
19 | * You should have received a copy of the GNU General Public License along | 17 | * You should have received a copy of the GNU General Public License along |
20 | * with this program; if not, write to the Free Software Foundation, Inc., | 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
21 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | 19 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
22 | * | ||
23 | * ######################################################################## | ||
24 | */ | 20 | */ |
25 | 21 | ||
26 | |||
27 | #include <linux/kernel.h> | ||
28 | #include "ieee754dp.h" | 22 | #include "ieee754dp.h" |
29 | 23 | ||
30 | int ieee754dp_tint(ieee754dp x) | 24 | int ieee754dp_tint(union ieee754dp x) |
31 | { | 25 | { |
26 | u64 residue; | ||
27 | int round; | ||
28 | int sticky; | ||
29 | int odd; | ||
30 | |||
32 | COMPXDP; | 31 | COMPXDP; |
33 | 32 | ||
34 | CLEARCX; | 33 | ieee754_clearcx(); |
35 | 34 | ||
36 | EXPLODEXDP; | 35 | EXPLODEXDP; |
37 | FLUSHXDP; | 36 | FLUSHXDP; |
@@ -40,10 +39,12 @@ int ieee754dp_tint(ieee754dp x) | |||
40 | case IEEE754_CLASS_SNAN: | 39 | case IEEE754_CLASS_SNAN: |
41 | case IEEE754_CLASS_QNAN: | 40 | case IEEE754_CLASS_QNAN: |
42 | case IEEE754_CLASS_INF: | 41 | case IEEE754_CLASS_INF: |
43 | SETCX(IEEE754_INVALID_OPERATION); | 42 | ieee754_setcx(IEEE754_INVALID_OPERATION); |
44 | return ieee754si_xcpt(ieee754si_indef(), "dp_tint", x); | 43 | return ieee754si_indef(); |
44 | |||
45 | case IEEE754_CLASS_ZERO: | 45 | case IEEE754_CLASS_ZERO: |
46 | return 0; | 46 | return 0; |
47 | |||
47 | case IEEE754_CLASS_DNORM: | 48 | case IEEE754_CLASS_DNORM: |
48 | case IEEE754_CLASS_NORM: | 49 | case IEEE754_CLASS_NORM: |
49 | break; | 50 | break; |
@@ -51,44 +52,39 @@ int ieee754dp_tint(ieee754dp x) | |||
51 | if (xe > 31) { | 52 | if (xe > 31) { |
52 | /* Set invalid. We will only use overflow for floating | 53 | /* Set invalid. We will only use overflow for floating |
53 | point overflow */ | 54 | point overflow */ |
54 | SETCX(IEEE754_INVALID_OPERATION); | 55 | ieee754_setcx(IEEE754_INVALID_OPERATION); |
55 | return ieee754si_xcpt(ieee754si_indef(), "dp_tint", x); | 56 | return ieee754si_indef(); |
56 | } | 57 | } |
57 | /* oh gawd */ | 58 | /* oh gawd */ |
58 | if (xe > DP_MBITS) { | 59 | if (xe > DP_FBITS) { |
59 | xm <<= xe - DP_MBITS; | 60 | xm <<= xe - DP_FBITS; |
60 | } else if (xe < DP_MBITS) { | 61 | } else if (xe < DP_FBITS) { |
61 | u64 residue; | ||
62 | int round; | ||
63 | int sticky; | ||
64 | int odd; | ||
65 | |||
66 | if (xe < -1) { | 62 | if (xe < -1) { |
67 | residue = xm; | 63 | residue = xm; |
68 | round = 0; | 64 | round = 0; |
69 | sticky = residue != 0; | 65 | sticky = residue != 0; |
70 | xm = 0; | 66 | xm = 0; |
71 | } else { | 67 | } else { |
72 | residue = xm << (64 - DP_MBITS + xe); | 68 | residue = xm << (64 - DP_FBITS + xe); |
73 | round = (residue >> 63) != 0; | 69 | round = (residue >> 63) != 0; |
74 | sticky = (residue << 1) != 0; | 70 | sticky = (residue << 1) != 0; |
75 | xm >>= DP_MBITS - xe; | 71 | xm >>= DP_FBITS - xe; |
76 | } | 72 | } |
77 | /* Note: At this point upper 32 bits of xm are guaranteed | 73 | /* Note: At this point upper 32 bits of xm are guaranteed |
78 | to be zero */ | 74 | to be zero */ |
79 | odd = (xm & 0x1) != 0x0; | 75 | odd = (xm & 0x1) != 0x0; |
80 | switch (ieee754_csr.rm) { | 76 | switch (ieee754_csr.rm) { |
81 | case IEEE754_RN: | 77 | case FPU_CSR_RN: |
82 | if (round && (sticky || odd)) | 78 | if (round && (sticky || odd)) |
83 | xm++; | 79 | xm++; |
84 | break; | 80 | break; |
85 | case IEEE754_RZ: | 81 | case FPU_CSR_RZ: |
86 | break; | 82 | break; |
87 | case IEEE754_RU: /* toward +Infinity */ | 83 | case FPU_CSR_RU: /* toward +Infinity */ |
88 | if ((round || sticky) && !xs) | 84 | if ((round || sticky) && !xs) |
89 | xm++; | 85 | xm++; |
90 | break; | 86 | break; |
91 | case IEEE754_RD: /* toward -Infinity */ | 87 | case FPU_CSR_RD: /* toward -Infinity */ |
92 | if ((round || sticky) && xs) | 88 | if ((round || sticky) && xs) |
93 | xm++; | 89 | xm++; |
94 | break; | 90 | break; |
@@ -96,27 +92,14 @@ int ieee754dp_tint(ieee754dp x) | |||
96 | /* look for valid corner case 0x80000000 */ | 92 | /* look for valid corner case 0x80000000 */ |
97 | if ((xm >> 31) != 0 && (xs == 0 || xm != 0x80000000)) { | 93 | if ((xm >> 31) != 0 && (xs == 0 || xm != 0x80000000)) { |
98 | /* This can happen after rounding */ | 94 | /* This can happen after rounding */ |
99 | SETCX(IEEE754_INVALID_OPERATION); | 95 | ieee754_setcx(IEEE754_INVALID_OPERATION); |
100 | return ieee754si_xcpt(ieee754si_indef(), "dp_tint", x); | 96 | return ieee754si_indef(); |
101 | } | 97 | } |
102 | if (round || sticky) | 98 | if (round || sticky) |
103 | SETCX(IEEE754_INEXACT); | 99 | ieee754_setcx(IEEE754_INEXACT); |
104 | } | 100 | } |
105 | if (xs) | 101 | if (xs) |
106 | return -xm; | 102 | return -xm; |
107 | else | 103 | else |
108 | return xm; | 104 | return xm; |
109 | } | 105 | } |
110 | |||
111 | |||
112 | unsigned int ieee754dp_tuns(ieee754dp x) | ||
113 | { | ||
114 | ieee754dp hb = ieee754dp_1e31(); | ||
115 | |||
116 | /* what if x < 0 ?? */ | ||
117 | if (ieee754dp_lt(x, hb)) | ||
118 | return (unsigned) ieee754dp_tint(x); | ||
119 | |||
120 | return (unsigned) ieee754dp_tint(ieee754dp_sub(x, hb)) | | ||
121 | ((unsigned) 1 << 31); | ||
122 | } | ||