- removed support for old-style syntax userbutton shortcuts
[bochs-mirror.git] / fpu / softfloat-specialize.cc
blob303b7572b189825826caf694a3eefb281ee2c5bd
1 /*============================================================================
2 This C source fragment is part of the SoftFloat IEC/IEEE Floating-point
3 Arithmetic Package, Release 2b.
5 Written by John R. Hauser. This work was made possible in part by the
6 International Computer Science Institute, located at Suite 600, 1947 Center
7 Street, Berkeley, California 94704. Funding was partially provided by the
8 National Science Foundation under grant MIP-9311980. The original version
9 of this code was written as part of a project to build a fixed-point vector
10 processor in collaboration with the University of California at Berkeley,
11 overseen by Profs. Nelson Morgan and John Wawrzynek. More information
12 is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
13 arithmetic/SoftFloat.html'.
15 THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
16 been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
17 RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
18 AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
19 COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
20 EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
21 INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
22 OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
24 Derivative works are acceptable, even for commercial purposes, so long as
25 (1) the source code for the derivative work includes prominent notice that
26 the work is derivative, and (2) the source code includes prominent notice with
27 these four paragraphs for those parts of this code that are retained.
28 =============================================================================*/
30 #define FLOAT128
32 /*============================================================================
33 * Adapted for Bochs (x86 achitecture simulator) by
34 * Stanislav Shwartsman [sshwarts at sourceforge net]
35 * ==========================================================================*/
37 #include "softfloat.h"
38 #include "softfloat-specialize.h"
40 /*----------------------------------------------------------------------------
41 | Takes two single-precision floating-point values `a' and `b', one of which
42 | is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
43 | signaling NaN, the invalid exception is raised.
44 *----------------------------------------------------------------------------*/
46 float32 propagateFloat32NaN(float32 a, float32 b, float_status_t &status)
48 int aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN;
50 aIsNaN = float32_is_nan(a);
51 aIsSignalingNaN = float32_is_signaling_nan(a);
52 bIsNaN = float32_is_nan(b);
53 bIsSignalingNaN = float32_is_signaling_nan(b);
54 a |= 0x00400000;
55 b |= 0x00400000;
56 if (aIsSignalingNaN | bIsSignalingNaN) float_raise(status, float_flag_invalid);
57 if (get_float_nan_handling_mode(status) == float_larger_significand_nan) {
58 if (aIsSignalingNaN) {
59 if (bIsSignalingNaN) goto returnLargerSignificand;
60 return bIsNaN ? b : a;
62 else if (aIsNaN) {
63 if (bIsSignalingNaN | ! bIsNaN) return a;
64 returnLargerSignificand:
65 if ((Bit32u) (a<<1) < (Bit32u) (b<<1)) return b;
66 if ((Bit32u) (b<<1) < (Bit32u) (a<<1)) return a;
67 return (a < b) ? a : b;
69 else {
70 return b;
72 } else {
73 return (aIsSignalingNaN | aIsNaN) ? a : b;
77 /*----------------------------------------------------------------------------
78 | Takes two double-precision floating-point values `a' and `b', one of which
79 | is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
80 | signaling NaN, the invalid exception is raised.
81 *----------------------------------------------------------------------------*/
83 float64 propagateFloat64NaN(float64 a, float64 b, float_status_t &status)
85 int aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN;
86 aIsNaN = float64_is_nan(a);
87 aIsSignalingNaN = float64_is_signaling_nan(a);
88 bIsNaN = float64_is_nan(b);
89 bIsSignalingNaN = float64_is_signaling_nan(b);
90 a |= BX_CONST64(0x0008000000000000);
91 b |= BX_CONST64(0x0008000000000000);
92 if (aIsSignalingNaN | bIsSignalingNaN) float_raise(status, float_flag_invalid);
93 if (get_float_nan_handling_mode(status) == float_larger_significand_nan) {
94 if (aIsSignalingNaN) {
95 if (bIsSignalingNaN) goto returnLargerSignificand;
96 return bIsNaN ? b : a;
98 else if (aIsNaN) {
99 if (bIsSignalingNaN | ! bIsNaN) return a;
100 returnLargerSignificand:
101 if ((Bit64u) (a<<1) < (Bit64u) (b<<1)) return b;
102 if ((Bit64u) (b<<1) < (Bit64u) (a<<1)) return a;
103 return (a < b) ? a : b;
105 else {
106 return b;
108 } else {
109 return (aIsSignalingNaN | aIsNaN) ? a : b;
113 #ifdef FLOATX80
115 /*----------------------------------------------------------------------------
116 | Takes two extended double-precision floating-point values `a' and `b', one
117 | of which is a NaN, and returns the appropriate NaN result. If either `a' or
118 | `b' is a signaling NaN, the invalid exception is raised.
119 *----------------------------------------------------------------------------*/
121 floatx80 propagateFloatx80NaN(floatx80 a, floatx80 b, float_status_t &status)
123 int aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN;
124 aIsNaN = floatx80_is_nan(a);
125 aIsSignalingNaN = floatx80_is_signaling_nan(a);
126 bIsNaN = floatx80_is_nan(b);
127 bIsSignalingNaN = floatx80_is_signaling_nan(b);
128 a.fraction |= BX_CONST64(0xC000000000000000);
129 b.fraction |= BX_CONST64(0xC000000000000000);
130 if (aIsSignalingNaN | bIsSignalingNaN) float_raise(status, float_flag_invalid);
131 if (aIsSignalingNaN) {
132 if (bIsSignalingNaN) goto returnLargerSignificand;
133 return bIsNaN ? b : a;
135 else if (aIsNaN) {
136 if (bIsSignalingNaN | ! bIsNaN) return a;
137 returnLargerSignificand:
138 if (a.fraction < b.fraction) return b;
139 if (b.fraction < a.fraction) return a;
140 return (a.exp < b.exp) ? a : b;
142 else {
143 return b;
147 /*----------------------------------------------------------------------------
148 | The pattern for a default generated extended double-precision NaN.
149 *----------------------------------------------------------------------------*/
150 const floatx80 floatx80_default_nan =
151 packFloatx80(0, floatx80_default_nan_exp, floatx80_default_nan_fraction);
153 #endif /* FLOATX80 */
155 #ifdef FLOAT128
157 /*----------------------------------------------------------------------------
158 | Takes two quadruple-precision floating-point values `a' and `b', one of
159 | which is a NaN, and returns the appropriate NaN result. If either `a' or
160 | `b' is a signaling NaN, the invalid exception is raised.
161 *----------------------------------------------------------------------------*/
163 float128 propagateFloat128NaN(float128 a, float128 b, float_status_t &status)
165 int aIsNaN, aIsSignalingNaN, bIsNaN, bIsSignalingNaN;
166 aIsNaN = float128_is_nan(a);
167 aIsSignalingNaN = float128_is_signaling_nan(a);
168 bIsNaN = float128_is_nan(b);
169 bIsSignalingNaN = float128_is_signaling_nan(b);
170 a.hi |= BX_CONST64(0x0000800000000000);
171 b.hi |= BX_CONST64(0x0000800000000000);
172 if (aIsSignalingNaN | bIsSignalingNaN) float_raise(status, float_flag_invalid);
173 if (aIsSignalingNaN) {
174 if (bIsSignalingNaN) goto returnLargerSignificand;
175 return bIsNaN ? b : a;
177 else if (aIsNaN) {
178 if (bIsSignalingNaN | !bIsNaN) return a;
179 returnLargerSignificand:
180 if (lt128(a.hi<<1, a.lo, b.hi<<1, b.lo)) return b;
181 if (lt128(b.hi<<1, b.lo, a.hi<<1, a.lo)) return a;
182 return (a.hi < b.hi) ? a : b;
184 else {
185 return b;
189 /*----------------------------------------------------------------------------
190 | The pattern for a default generated quadruple-precision NaN.
191 *----------------------------------------------------------------------------*/
192 const float128 float128_default_nan =
193 packFloat128(float128_default_nan_hi, float128_default_nan_lo);
195 #endif /* FLOAT128 */