2 /*============================================================================
4 This C source fragment is part of the SoftFloat IEC/IEEE Floating-point
5 Arithmetic Package, Release 2b.
7 Written by John R. Hauser. This work was made possible in part by the
8 International Computer Science Institute, located at Suite 600, 1947 Center
9 Street, Berkeley, California 94704. Funding was partially provided by the
10 National Science Foundation under grant MIP-9311980. The original version
11 of this code was written as part of a project to build a fixed-point vector
12 processor in collaboration with the University of California at Berkeley,
13 overseen by Profs. Nelson Morgan and John Wawrzynek. More information
14 is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
15 arithmetic/SoftFloat.html'.
17 THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
18 been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
19 RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
20 AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
21 COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
22 EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
23 INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
24 OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
26 Derivative works are acceptable, even for commercial purposes, so long as
27 (1) the source code for the derivative work includes prominent notice that
28 the work is derivative, and (2) the source code includes prominent notice with
29 these four paragraphs for those parts of this code that are retained.
31 =============================================================================*/
33 #if defined(TARGET_MIPS) || defined(TARGET_SH4)
34 #define SNAN_BIT_IS_ONE 1
36 #define SNAN_BIT_IS_ONE 0
39 /*----------------------------------------------------------------------------
40 | Raises the exceptions specified by `flags'. Floating-point traps can be
41 | defined here if desired. It is currently not possible for such a trap
42 | to substitute a result value. If traps are not implemented, this routine
43 | should be simply `float_exception_flags |= flags;'.
44 *----------------------------------------------------------------------------*/
46 void float_raise( int8 flags STATUS_PARAM )
48 STATUS(float_exception_flags) |= flags;
51 /*----------------------------------------------------------------------------
52 | Internal canonical NaN format.
53 *----------------------------------------------------------------------------*/
59 /*----------------------------------------------------------------------------
60 | The pattern for a default generated half-precision NaN.
61 *----------------------------------------------------------------------------*/
62 #if defined(TARGET_ARM)
63 #define float16_default_nan make_float16(0x7E00)
65 #define float16_default_nan make_float16(0x7DFF)
67 #define float16_default_nan make_float16(0xFE00)
70 /*----------------------------------------------------------------------------
71 | Returns 1 if the half-precision floating-point value `a' is a quiet
72 | NaN; otherwise returns 0.
73 *----------------------------------------------------------------------------*/
75 int float16_is_quiet_nan(float16 a_)
77 uint16_t a = float16_val(a_);
79 return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
81 return ((a & ~0x8000) >= 0x7c80);
85 /*----------------------------------------------------------------------------
86 | Returns 1 if the half-precision floating-point value `a' is a signaling
87 | NaN; otherwise returns 0.
88 *----------------------------------------------------------------------------*/
90 int float16_is_signaling_nan(float16 a_)
92 uint16_t a = float16_val(a_);
94 return ((a & ~0x8000) >= 0x7c80);
96 return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF);
100 /*----------------------------------------------------------------------------
101 | Returns a quiet NaN if the half-precision floating point value `a' is a
102 | signaling NaN; otherwise returns `a'.
103 *----------------------------------------------------------------------------*/
104 float16 float16_maybe_silence_nan(float16 a_)
106 if (float16_is_signaling_nan(a_)) {
108 # if defined(TARGET_MIPS) || defined(TARGET_SH4)
109 return float16_default_nan;
111 # error Rules for silencing a signaling NaN are target-specific
114 uint16_t a = float16_val(a_);
116 return make_float16(a);
122 /*----------------------------------------------------------------------------
123 | Returns the result of converting the canonical NaN `a' to the half-
124 | precision floating-point format.
125 *----------------------------------------------------------------------------*/
127 static float16 commonNaNToFloat16(commonNaNT a STATUS_PARAM)
129 uint16_t mantissa = a.high>>54;
131 if (STATUS(default_nan_mode)) {
132 return float16_default_nan;
136 return make_float16(((((uint16_t) a.sign) << 15)
137 | (0x1F << 10) | mantissa));
139 return float16_default_nan;
143 /*----------------------------------------------------------------------------
144 | The pattern for a default generated single-precision NaN.
145 *----------------------------------------------------------------------------*/
146 #if defined(TARGET_SPARC)
147 #define float32_default_nan make_float32(0x7FFFFFFF)
148 #elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA)
149 #define float32_default_nan make_float32(0x7FC00000)
150 #elif SNAN_BIT_IS_ONE
151 #define float32_default_nan make_float32(0x7FBFFFFF)
153 #define float32_default_nan make_float32(0xFFC00000)
156 /*----------------------------------------------------------------------------
157 | Returns 1 if the single-precision floating-point value `a' is a quiet
158 | NaN; otherwise returns 0.
159 *----------------------------------------------------------------------------*/
161 int float32_is_quiet_nan( float32 a_ )
163 uint32_t a = float32_val(a_);
165 return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
167 return ( 0xFF800000 <= (bits32) ( a<<1 ) );
171 /*----------------------------------------------------------------------------
172 | Returns 1 if the single-precision floating-point value `a' is a signaling
173 | NaN; otherwise returns 0.
174 *----------------------------------------------------------------------------*/
176 int float32_is_signaling_nan( float32 a_ )
178 uint32_t a = float32_val(a_);
180 return ( 0xFF800000 <= (bits32) ( a<<1 ) );
182 return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
186 /*----------------------------------------------------------------------------
187 | Returns a quiet NaN if the single-precision floating point value `a' is a
188 | signaling NaN; otherwise returns `a'.
189 *----------------------------------------------------------------------------*/
191 float32 float32_maybe_silence_nan( float32 a_ )
193 if (float32_is_signaling_nan(a_)) {
195 # if defined(TARGET_MIPS) || defined(TARGET_SH4)
196 return float32_default_nan;
198 # error Rules for silencing a signaling NaN are target-specific
201 bits32 a = float32_val(a_);
203 return make_float32(a);
209 /*----------------------------------------------------------------------------
210 | Returns the result of converting the single-precision floating-point NaN
211 | `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid
212 | exception is raised.
213 *----------------------------------------------------------------------------*/
215 static commonNaNT float32ToCommonNaN( float32 a STATUS_PARAM )
219 if ( float32_is_signaling_nan( a ) ) float_raise( float_flag_invalid STATUS_VAR );
220 z.sign = float32_val(a)>>31;
222 z.high = ( (bits64) float32_val(a) )<<41;
226 /*----------------------------------------------------------------------------
227 | Returns the result of converting the canonical NaN `a' to the single-
228 | precision floating-point format.
229 *----------------------------------------------------------------------------*/
231 static float32 commonNaNToFloat32( commonNaNT a STATUS_PARAM)
233 bits32 mantissa = a.high>>41;
235 if ( STATUS(default_nan_mode) ) {
236 return float32_default_nan;
241 ( ( (bits32) a.sign )<<31 ) | 0x7F800000 | ( a.high>>41 ) );
243 return float32_default_nan;
246 /*----------------------------------------------------------------------------
247 | Select which NaN to propagate for a two-input operation.
248 | IEEE754 doesn't specify all the details of this, so the
249 | algorithm is target-specific.
250 | The routine is passed various bits of information about the
251 | two NaNs and should return 0 to select NaN a and 1 for NaN b.
252 | Note that signalling NaNs are always squashed to quiet NaNs
253 | by the caller, by calling floatXX_maybe_silence_nan() before
256 | aIsLargerSignificand is only valid if both a and b are NaNs
257 | of some kind, and is true if a has the larger significand,
258 | or if both a and b have the same significand but a is
259 | positive but b is negative. It is only needed for the x87
261 *----------------------------------------------------------------------------*/
263 #if defined(TARGET_ARM)
264 static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
265 flag aIsLargerSignificand)
267 /* ARM mandated NaN propagation rules: take the first of:
268 * 1. A if it is signaling
269 * 2. B if it is signaling
272 * A signaling NaN is always quietened before returning it.
276 } else if (bIsSNaN) {
278 } else if (aIsQNaN) {
284 #elif defined(TARGET_MIPS)
285 static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
286 flag aIsLargerSignificand)
288 /* According to MIPS specifications, if one of the two operands is
289 * a sNaN, a new qNaN has to be generated. This is done in
290 * floatXX_maybe_silence_nan(). For qNaN inputs the specifications
291 * says: "When possible, this QNaN result is one of the operand QNaN
292 * values." In practice it seems that most implementations choose
293 * the first operand if both operands are qNaN. In short this gives
294 * the following rules:
295 * 1. A if it is signaling
296 * 2. B if it is signaling
299 * A signaling NaN is always silenced before returning it.
303 } else if (bIsSNaN) {
305 } else if (aIsQNaN) {
311 #elif defined(TARGET_PPC)
312 static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
313 flag aIsLargerSignificand)
315 /* PowerPC propagation rules:
316 * 1. A if it sNaN or qNaN
317 * 2. B if it sNaN or qNaN
318 * A signaling NaN is always silenced before returning it.
320 if (aIsSNaN || aIsQNaN) {
327 static int pickNaN(flag aIsQNaN, flag aIsSNaN, flag bIsQNaN, flag bIsSNaN,
328 flag aIsLargerSignificand)
330 /* This implements x87 NaN propagation rules:
331 * SNaN + QNaN => return the QNaN
332 * two SNaNs => return the one with the larger significand, silenced
333 * two QNaNs => return the one with the larger significand
334 * SNaN and a non-NaN => return the SNaN, silenced
335 * QNaN and a non-NaN => return the QNaN
337 * If we get down to comparing significands and they are the same,
338 * return the NaN with the positive sign bit (if any).
342 return aIsLargerSignificand ? 0 : 1;
344 return bIsQNaN ? 1 : 0;
347 if (bIsSNaN || !bIsQNaN)
350 return aIsLargerSignificand ? 0 : 1;
358 /*----------------------------------------------------------------------------
359 | Takes two single-precision floating-point values `a' and `b', one of which
360 | is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
361 | signaling NaN, the invalid exception is raised.
362 *----------------------------------------------------------------------------*/
364 static float32 propagateFloat32NaN( float32 a, float32 b STATUS_PARAM)
366 flag aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN;
367 flag aIsLargerSignificand;
370 aIsQuietNaN = float32_is_quiet_nan( a );
371 aIsSignalingNaN = float32_is_signaling_nan( a );
372 bIsQuietNaN = float32_is_quiet_nan( b );
373 bIsSignalingNaN = float32_is_signaling_nan( b );
377 if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid STATUS_VAR);
379 if ( STATUS(default_nan_mode) )
380 return float32_default_nan;
382 if ((bits32)(av<<1) < (bits32)(bv<<1)) {
383 aIsLargerSignificand = 0;
384 } else if ((bits32)(bv<<1) < (bits32)(av<<1)) {
385 aIsLargerSignificand = 1;
387 aIsLargerSignificand = (av < bv) ? 1 : 0;
390 if (pickNaN(aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN,
391 aIsLargerSignificand)) {
392 return float32_maybe_silence_nan(b);
394 return float32_maybe_silence_nan(a);
398 /*----------------------------------------------------------------------------
399 | The pattern for a default generated double-precision NaN.
400 *----------------------------------------------------------------------------*/
401 #if defined(TARGET_SPARC)
402 #define float64_default_nan make_float64(LIT64( 0x7FFFFFFFFFFFFFFF ))
403 #elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA)
404 #define float64_default_nan make_float64(LIT64( 0x7FF8000000000000 ))
405 #elif SNAN_BIT_IS_ONE
406 #define float64_default_nan make_float64(LIT64( 0x7FF7FFFFFFFFFFFF ))
408 #define float64_default_nan make_float64(LIT64( 0xFFF8000000000000 ))
411 /*----------------------------------------------------------------------------
412 | Returns 1 if the double-precision floating-point value `a' is a quiet
413 | NaN; otherwise returns 0.
414 *----------------------------------------------------------------------------*/
416 int float64_is_quiet_nan( float64 a_ )
418 bits64 a = float64_val(a_);
421 ( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
422 && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
424 return ( LIT64( 0xFFF0000000000000 ) <= (bits64) ( a<<1 ) );
428 /*----------------------------------------------------------------------------
429 | Returns 1 if the double-precision floating-point value `a' is a signaling
430 | NaN; otherwise returns 0.
431 *----------------------------------------------------------------------------*/
433 int float64_is_signaling_nan( float64 a_ )
435 bits64 a = float64_val(a_);
437 return ( LIT64( 0xFFF0000000000000 ) <= (bits64) ( a<<1 ) );
440 ( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
441 && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
445 /*----------------------------------------------------------------------------
446 | Returns a quiet NaN if the double-precision floating point value `a' is a
447 | signaling NaN; otherwise returns `a'.
448 *----------------------------------------------------------------------------*/
450 float64 float64_maybe_silence_nan( float64 a_ )
452 if (float64_is_signaling_nan(a_)) {
454 # if defined(TARGET_MIPS) || defined(TARGET_SH4)
455 return float64_default_nan;
457 # error Rules for silencing a signaling NaN are target-specific
460 bits64 a = float64_val(a_);
461 a |= LIT64( 0x0008000000000000 );
462 return make_float64(a);
468 /*----------------------------------------------------------------------------
469 | Returns the result of converting the double-precision floating-point NaN
470 | `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid
471 | exception is raised.
472 *----------------------------------------------------------------------------*/
474 static commonNaNT float64ToCommonNaN( float64 a STATUS_PARAM)
478 if ( float64_is_signaling_nan( a ) ) float_raise( float_flag_invalid STATUS_VAR);
479 z.sign = float64_val(a)>>63;
481 z.high = float64_val(a)<<12;
485 /*----------------------------------------------------------------------------
486 | Returns the result of converting the canonical NaN `a' to the double-
487 | precision floating-point format.
488 *----------------------------------------------------------------------------*/
490 static float64 commonNaNToFloat64( commonNaNT a STATUS_PARAM)
492 bits64 mantissa = a.high>>12;
494 if ( STATUS(default_nan_mode) ) {
495 return float64_default_nan;
500 ( ( (bits64) a.sign )<<63 )
501 | LIT64( 0x7FF0000000000000 )
504 return float64_default_nan;
507 /*----------------------------------------------------------------------------
508 | Takes two double-precision floating-point values `a' and `b', one of which
509 | is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
510 | signaling NaN, the invalid exception is raised.
511 *----------------------------------------------------------------------------*/
513 static float64 propagateFloat64NaN( float64 a, float64 b STATUS_PARAM)
515 flag aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN;
516 flag aIsLargerSignificand;
519 aIsQuietNaN = float64_is_quiet_nan( a );
520 aIsSignalingNaN = float64_is_signaling_nan( a );
521 bIsQuietNaN = float64_is_quiet_nan( b );
522 bIsSignalingNaN = float64_is_signaling_nan( b );
526 if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid STATUS_VAR);
528 if ( STATUS(default_nan_mode) )
529 return float64_default_nan;
531 if ((bits64)(av<<1) < (bits64)(bv<<1)) {
532 aIsLargerSignificand = 0;
533 } else if ((bits64)(bv<<1) < (bits64)(av<<1)) {
534 aIsLargerSignificand = 1;
536 aIsLargerSignificand = (av < bv) ? 1 : 0;
539 if (pickNaN(aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN,
540 aIsLargerSignificand)) {
541 return float64_maybe_silence_nan(b);
543 return float64_maybe_silence_nan(a);
549 /*----------------------------------------------------------------------------
550 | The pattern for a default generated extended double-precision NaN. The
551 | `high' and `low' values hold the most- and least-significant bits,
553 *----------------------------------------------------------------------------*/
555 #define floatx80_default_nan_high 0x7FFF
556 #define floatx80_default_nan_low LIT64( 0xBFFFFFFFFFFFFFFF )
558 #define floatx80_default_nan_high 0xFFFF
559 #define floatx80_default_nan_low LIT64( 0xC000000000000000 )
562 /*----------------------------------------------------------------------------
563 | Returns 1 if the extended double-precision floating-point value `a' is a
564 | quiet NaN; otherwise returns 0. This slightly differs from the same
565 | function for other types as floatx80 has an explicit bit.
566 *----------------------------------------------------------------------------*/
568 int floatx80_is_quiet_nan( floatx80 a )
573 aLow = a.low & ~ LIT64( 0x4000000000000000 );
575 ( ( a.high & 0x7FFF ) == 0x7FFF )
576 && (bits64) ( aLow<<1 )
577 && ( a.low == aLow );
579 return ( ( a.high & 0x7FFF ) == 0x7FFF )
580 && (LIT64( 0x8000000000000000 ) <= ((bits64) ( a.low<<1 )));
584 /*----------------------------------------------------------------------------
585 | Returns 1 if the extended double-precision floating-point value `a' is a
586 | signaling NaN; otherwise returns 0. This slightly differs from the same
587 | function for other types as floatx80 has an explicit bit.
588 *----------------------------------------------------------------------------*/
590 int floatx80_is_signaling_nan( floatx80 a )
593 return ( ( a.high & 0x7FFF ) == 0x7FFF )
594 && (LIT64( 0x8000000000000000 ) <= ((bits64) ( a.low<<1 )));
598 aLow = a.low & ~ LIT64( 0x4000000000000000 );
600 ( ( a.high & 0x7FFF ) == 0x7FFF )
601 && (bits64) ( aLow<<1 )
602 && ( a.low == aLow );
606 /*----------------------------------------------------------------------------
607 | Returns a quiet NaN if the extended double-precision floating point value
608 | `a' is a signaling NaN; otherwise returns `a'.
609 *----------------------------------------------------------------------------*/
611 floatx80 floatx80_maybe_silence_nan( floatx80 a )
613 if (floatx80_is_signaling_nan(a)) {
615 # if defined(TARGET_MIPS) || defined(TARGET_SH4)
616 a.low = floatx80_default_nan_low;
617 a.high = floatx80_default_nan_high;
619 # error Rules for silencing a signaling NaN are target-specific
622 a.low |= LIT64( 0xC000000000000000 );
629 /*----------------------------------------------------------------------------
630 | Returns the result of converting the extended double-precision floating-
631 | point NaN `a' to the canonical NaN format. If `a' is a signaling NaN, the
632 | invalid exception is raised.
633 *----------------------------------------------------------------------------*/
635 static commonNaNT floatx80ToCommonNaN( floatx80 a STATUS_PARAM)
639 if ( floatx80_is_signaling_nan( a ) ) float_raise( float_flag_invalid STATUS_VAR);
646 /*----------------------------------------------------------------------------
647 | Returns the result of converting the canonical NaN `a' to the extended
648 | double-precision floating-point format.
649 *----------------------------------------------------------------------------*/
651 static floatx80 commonNaNToFloatx80( commonNaNT a STATUS_PARAM)
655 if ( STATUS(default_nan_mode) ) {
656 z.low = floatx80_default_nan_low;
657 z.high = floatx80_default_nan_high;
664 z.low = floatx80_default_nan_low;
665 z.high = ( ( (bits16) a.sign )<<15 ) | 0x7FFF;
669 /*----------------------------------------------------------------------------
670 | Takes two extended double-precision floating-point values `a' and `b', one
671 | of which is a NaN, and returns the appropriate NaN result. If either `a' or
672 | `b' is a signaling NaN, the invalid exception is raised.
673 *----------------------------------------------------------------------------*/
675 static floatx80 propagateFloatx80NaN( floatx80 a, floatx80 b STATUS_PARAM)
677 flag aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN;
678 flag aIsLargerSignificand;
680 aIsQuietNaN = floatx80_is_quiet_nan( a );
681 aIsSignalingNaN = floatx80_is_signaling_nan( a );
682 bIsQuietNaN = floatx80_is_quiet_nan( b );
683 bIsSignalingNaN = floatx80_is_signaling_nan( b );
685 if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid STATUS_VAR);
687 if ( STATUS(default_nan_mode) ) {
688 a.low = floatx80_default_nan_low;
689 a.high = floatx80_default_nan_high;
694 aIsLargerSignificand = 0;
695 } else if (b.low < a.low) {
696 aIsLargerSignificand = 1;
698 aIsLargerSignificand = (a.high < b.high) ? 1 : 0;
701 if (pickNaN(aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN,
702 aIsLargerSignificand)) {
703 return floatx80_maybe_silence_nan(b);
705 return floatx80_maybe_silence_nan(a);
713 /*----------------------------------------------------------------------------
714 | The pattern for a default generated quadruple-precision NaN. The `high' and
715 | `low' values hold the most- and least-significant bits, respectively.
716 *----------------------------------------------------------------------------*/
718 #define float128_default_nan_high LIT64( 0x7FFF7FFFFFFFFFFF )
719 #define float128_default_nan_low LIT64( 0xFFFFFFFFFFFFFFFF )
721 #define float128_default_nan_high LIT64( 0xFFFF800000000000 )
722 #define float128_default_nan_low LIT64( 0x0000000000000000 )
725 /*----------------------------------------------------------------------------
726 | Returns 1 if the quadruple-precision floating-point value `a' is a quiet
727 | NaN; otherwise returns 0.
728 *----------------------------------------------------------------------------*/
730 int float128_is_quiet_nan( float128 a )
734 ( ( ( a.high>>47 ) & 0xFFFF ) == 0xFFFE )
735 && ( a.low || ( a.high & LIT64( 0x00007FFFFFFFFFFF ) ) );
738 ( LIT64( 0xFFFE000000000000 ) <= (bits64) ( a.high<<1 ) )
739 && ( a.low || ( a.high & LIT64( 0x0000FFFFFFFFFFFF ) ) );
743 /*----------------------------------------------------------------------------
744 | Returns 1 if the quadruple-precision floating-point value `a' is a
745 | signaling NaN; otherwise returns 0.
746 *----------------------------------------------------------------------------*/
748 int float128_is_signaling_nan( float128 a )
752 ( LIT64( 0xFFFE000000000000 ) <= (bits64) ( a.high<<1 ) )
753 && ( a.low || ( a.high & LIT64( 0x0000FFFFFFFFFFFF ) ) );
756 ( ( ( a.high>>47 ) & 0xFFFF ) == 0xFFFE )
757 && ( a.low || ( a.high & LIT64( 0x00007FFFFFFFFFFF ) ) );
761 /*----------------------------------------------------------------------------
762 | Returns a quiet NaN if the quadruple-precision floating point value `a' is
763 | a signaling NaN; otherwise returns `a'.
764 *----------------------------------------------------------------------------*/
766 float128 float128_maybe_silence_nan( float128 a )
768 if (float128_is_signaling_nan(a)) {
770 # if defined(TARGET_MIPS) || defined(TARGET_SH4)
771 a.low = float128_default_nan_low;
772 a.high = float128_default_nan_high;
774 # error Rules for silencing a signaling NaN are target-specific
777 a.high |= LIT64( 0x0000800000000000 );
784 /*----------------------------------------------------------------------------
785 | Returns the result of converting the quadruple-precision floating-point NaN
786 | `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid
787 | exception is raised.
788 *----------------------------------------------------------------------------*/
790 static commonNaNT float128ToCommonNaN( float128 a STATUS_PARAM)
794 if ( float128_is_signaling_nan( a ) ) float_raise( float_flag_invalid STATUS_VAR);
796 shortShift128Left( a.high, a.low, 16, &z.high, &z.low );
800 /*----------------------------------------------------------------------------
801 | Returns the result of converting the canonical NaN `a' to the quadruple-
802 | precision floating-point format.
803 *----------------------------------------------------------------------------*/
805 static float128 commonNaNToFloat128( commonNaNT a STATUS_PARAM)
809 if ( STATUS(default_nan_mode) ) {
810 z.low = float128_default_nan_low;
811 z.high = float128_default_nan_high;
815 shift128Right( a.high, a.low, 16, &z.high, &z.low );
816 z.high |= ( ( (bits64) a.sign )<<63 ) | LIT64( 0x7FFF000000000000 );
820 /*----------------------------------------------------------------------------
821 | Takes two quadruple-precision floating-point values `a' and `b', one of
822 | which is a NaN, and returns the appropriate NaN result. If either `a' or
823 | `b' is a signaling NaN, the invalid exception is raised.
824 *----------------------------------------------------------------------------*/
826 static float128 propagateFloat128NaN( float128 a, float128 b STATUS_PARAM)
828 flag aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN;
829 flag aIsLargerSignificand;
831 aIsQuietNaN = float128_is_quiet_nan( a );
832 aIsSignalingNaN = float128_is_signaling_nan( a );
833 bIsQuietNaN = float128_is_quiet_nan( b );
834 bIsSignalingNaN = float128_is_signaling_nan( b );
836 if ( aIsSignalingNaN | bIsSignalingNaN ) float_raise( float_flag_invalid STATUS_VAR);
838 if ( STATUS(default_nan_mode) ) {
839 a.low = float128_default_nan_low;
840 a.high = float128_default_nan_high;
844 if (lt128(a.high<<1, a.low, b.high<<1, b.low)) {
845 aIsLargerSignificand = 0;
846 } else if (lt128(b.high<<1, b.low, a.high<<1, a.low)) {
847 aIsLargerSignificand = 1;
849 aIsLargerSignificand = (a.high < b.high) ? 1 : 0;
852 if (pickNaN(aIsQuietNaN, aIsSignalingNaN, bIsQuietNaN, bIsSignalingNaN,
853 aIsLargerSignificand)) {
854 return float128_maybe_silence_nan(b);
856 return float128_maybe_silence_nan(a);