1 /* Copyright (C) 2007 Free Software Foundation, Inc.
3 This file is part of GCC.
5 GCC is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
10 In addition to the permissions in the GNU General Public License, the
11 Free Software Foundation gives you unlimited permission to link the
12 compiled version of this file into combinations with other programs,
13 and to distribute those combinations without any restriction coming
14 from the use of this file. (The General Public License restrictions
15 do apply in other respects; for example, they cover modification of
16 the file, and distribution when not linked into a combine
19 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
20 WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 You should have received a copy of the GNU General Public License
25 along with GCC; see the file COPYING. If not, write to the Free
26 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
29 #include "bid_internal.h"
31 static const UINT64 mult_factor[16] = {
32 1ull, 10ull, 100ull, 1000ull,
33 10000ull, 100000ull, 1000000ull, 10000000ull,
34 100000000ull, 1000000000ull, 10000000000ull, 100000000000ull,
35 1000000000000ull, 10000000000000ull,
36 100000000000000ull, 1000000000000000ull
39 /*****************************************************************************
40 * BID64 non-computational functions:
57 * - bid64_totalOrderMag
59 ****************************************************************************/
61 #if DECIMAL_CALL_BY_REFERENCE
63 bid64_isSigned (int *pres, UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
67 bid64_isSigned (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
71 res = ((x & MASK_SIGN) == MASK_SIGN);
75 // return 1 iff x is not zero, nor NaN nor subnormal nor infinity
76 #if DECIMAL_CALL_BY_REFERENCE
78 bid64_isNormal (int *pres, UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
82 bid64_isNormal (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
89 if ((x & MASK_INF) == MASK_INF) { // x is either INF or NaN
92 // decode number into exponent and significand
93 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
94 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
95 // check for zero or non-canonical
96 if (sig_x > 9999999999999999ull || sig_x == 0) {
97 res = 0; // zero or non-canonical
100 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
102 sig_x = (x & MASK_BINARY_SIG1);
107 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
109 // if exponent is less than -383, the number may be subnormal
110 // if (exp_x - 398 = -383) the number may be subnormal
112 __mul_64x64_to_128MACH (sig_x_prime, sig_x, mult_factor[exp_x]);
113 if (sig_x_prime.w[1] == 0
114 && sig_x_prime.w[0] < 1000000000000000ull) {
115 res = 0; // subnormal
126 // return 1 iff x is not zero, nor NaN nor normal nor infinity
127 #if DECIMAL_CALL_BY_REFERENCE
129 bid64_isSubnormal (int *pres,
130 UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
134 bid64_isSubnormal (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
141 if ((x & MASK_INF) == MASK_INF) { // x is either INF or NaN
144 // decode number into exponent and significand
145 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
146 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
147 // check for zero or non-canonical
148 if (sig_x > 9999999999999999ull || sig_x == 0) {
149 res = 0; // zero or non-canonical
152 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
154 sig_x = (x & MASK_BINARY_SIG1);
159 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
161 // if exponent is less than -383, the number may be subnormal
162 // if (exp_x - 398 = -383) the number may be subnormal
164 __mul_64x64_to_128MACH (sig_x_prime, sig_x, mult_factor[exp_x]);
165 if (sig_x_prime.w[1] == 0
166 && sig_x_prime.w[0] < 1000000000000000ull) {
167 res = 1; // subnormal
178 //iff x is zero, subnormal or normal (not infinity or NaN)
179 #if DECIMAL_CALL_BY_REFERENCE
181 bid64_isFinite (int *pres, UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
185 bid64_isFinite (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
189 res = ((x & MASK_INF) != MASK_INF);
193 #if DECIMAL_CALL_BY_REFERENCE
195 bid64_isZero (int *pres, UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
199 bid64_isZero (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
203 // if infinity or nan, return 0
204 if ((x & MASK_INF) == MASK_INF) {
206 } else if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
207 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1]
208 // => sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
209 // if(sig_x > 9999999999999999ull) {return 1;}
211 (((x & MASK_BINARY_SIG2) | MASK_BINARY_OR2) >
212 9999999999999999ull);
214 res = ((x & MASK_BINARY_SIG1) == 0);
219 #if DECIMAL_CALL_BY_REFERENCE
221 bid64_isInf (int *pres, UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
225 bid64_isInf (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
229 res = ((x & MASK_INF) == MASK_INF) && ((x & MASK_NAN) != MASK_NAN);
233 #if DECIMAL_CALL_BY_REFERENCE
235 bid64_isSignaling (int *pres,
236 UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
240 bid64_isSignaling (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
244 res = ((x & MASK_SNAN) == MASK_SNAN);
248 #if DECIMAL_CALL_BY_REFERENCE
250 bid64_isCanonical (int *pres,
251 UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
255 bid64_isCanonical (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
259 if ((x & MASK_NAN) == MASK_NAN) { // NaN
260 if (x & 0x01fc000000000000ull) {
262 } else if ((x & 0x0003ffffffffffffull) > 999999999999999ull) { // payload
267 } else if ((x & MASK_INF) == MASK_INF) {
268 if (x & 0x03ffffffffffffffull) {
273 } else if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) { // 54-bit coeff.
275 (((x & MASK_BINARY_SIG2) | MASK_BINARY_OR2) <=
276 9999999999999999ull);
277 } else { // 53-bit coeff.
283 #if DECIMAL_CALL_BY_REFERENCE
285 bid64_isNaN (int *pres, UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
289 bid64_isNaN (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
293 res = ((x & MASK_NAN) == MASK_NAN);
297 // copies a floating-point operand x to destination y, with no change
298 #if DECIMAL_CALL_BY_REFERENCE
300 bid64_copy (UINT64 * pres, UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
304 bid64_copy (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
312 // copies a floating-point operand x to destination y, reversing the sign
313 #if DECIMAL_CALL_BY_REFERENCE
315 bid64_negate (UINT64 * pres,
316 UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
320 bid64_negate (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
328 // copies a floating-point operand x to destination y, changing the sign to positive
329 #if DECIMAL_CALL_BY_REFERENCE
331 bid64_abs (UINT64 * pres, UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
335 bid64_abs (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
339 res = x & ~MASK_SIGN;
343 // copies operand x to destination in the same format as x, but
344 // with the sign of y
345 #if DECIMAL_CALL_BY_REFERENCE
347 bid64_copySign (UINT64 * pres, UINT64 * px,
348 UINT64 * py _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
353 bid64_copySign (UINT64 x, UINT64 y _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
357 res = (x & ~MASK_SIGN) | (y & MASK_SIGN);
361 #if DECIMAL_CALL_BY_REFERENCE
363 bid64_class (int *pres, UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
367 bid64_class (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
374 if ((x & MASK_NAN) == MASK_NAN) {
375 // is the NaN signaling?
376 if ((x & MASK_SNAN) == MASK_SNAN) {
380 // if NaN and not signaling, must be quietNaN
383 } else if ((x & MASK_INF) == MASK_INF) {
384 // is the Infinity negative?
385 if ((x & MASK_SIGN) == MASK_SIGN) {
386 res = negativeInfinity;
388 // otherwise, must be positive infinity
389 res = positiveInfinity;
392 } else if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
393 // decode number into exponent and significand
394 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
395 // check for zero or non-canonical
396 if (sig_x > 9999999999999999ull || sig_x == 0) {
397 if ((x & MASK_SIGN) == MASK_SIGN) {
404 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
406 sig_x = (x & MASK_BINARY_SIG1);
409 ((x & MASK_SIGN) == MASK_SIGN) ? negativeZero : positiveZero;
412 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
414 // if exponent is less than -383, number may be subnormal
415 // if (exp_x - 398 < -383)
416 if (exp_x < 15) { // sig_x *10^exp_x
417 __mul_64x64_to_128MACH (sig_x_prime, sig_x, mult_factor[exp_x]);
418 if (sig_x_prime.w[1] == 0
419 && (sig_x_prime.w[0] < 1000000000000000ull)) {
422 MASK_SIGN) ? negativeSubnormal : positiveSubnormal;
426 // otherwise, normal number, determine the sign
428 ((x & MASK_SIGN) == MASK_SIGN) ? negativeNormal : positiveNormal;
432 // true if the exponents of x and y are the same, false otherwise.
433 // The special cases of sameQuantum (NaN, NaN) and sameQuantum (Inf, Inf) are
435 // If exactly one operand is infinite or exactly one operand is NaN, then false
436 #if DECIMAL_CALL_BY_REFERENCE
438 bid64_sameQuantum (int *pres, UINT64 * px,
439 UINT64 * py _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
444 bid64_sameQuantum (UINT64 x, UINT64 y _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
447 unsigned int exp_x, exp_y;
449 // if both operands are NaN, return true; if just one is NaN, return false
450 if ((x & MASK_NAN) == MASK_NAN || ((y & MASK_NAN) == MASK_NAN)) {
451 res = ((x & MASK_NAN) == MASK_NAN && (y & MASK_NAN) == MASK_NAN);
454 // if both operands are INF, return true; if just one is INF, return false
455 if ((x & MASK_INF) == MASK_INF || (y & MASK_INF) == MASK_INF) {
456 res = ((x & MASK_INF) == MASK_INF && (y & MASK_INF) == MASK_INF);
459 // decode exponents for both numbers, and return true if they match
460 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
461 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
463 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
465 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
466 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
468 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
470 res = (exp_x == exp_y);
474 #if DECIMAL_CALL_BY_REFERENCE
476 bid64_totalOrder (int *pres, UINT64 * px,
477 UINT64 * py _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
482 bid64_totalOrder (UINT64 x, UINT64 y _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
486 UINT64 sig_x, sig_y, pyld_y, pyld_x;
488 char x_is_zero = 0, y_is_zero = 0;
491 // if x and y are unordered numerically because either operand is NaN
492 // (1) totalOrder(-NaN, number) is true
493 // (2) totalOrder(number, +NaN) is true
494 // (3) if x and y are both NaN:
495 // i) negative sign bit < positive sign bit
496 // ii) signaling < quiet for +NaN, reverse for -NaN
497 // iii) lesser payload < greater payload for +NaN (reverse for -NaN)
498 // iv) else if bitwise identical (in canonical form), return 1
499 if ((x & MASK_NAN) == MASK_NAN) {
501 if ((x & MASK_SIGN) == MASK_SIGN) {
502 // return true, unless y is -NaN also
503 if ((y & MASK_NAN) != MASK_NAN || (y & MASK_SIGN) != MASK_SIGN) {
504 res = 1; // y is a number, return 1
506 } else { // if y and x are both -NaN
507 // if x and y are both -sNaN or both -qNaN, we have to compare payloads
508 // this xnor statement evaluates to true if both are sNaN or qNaN
510 (((y & MASK_SNAN) == MASK_SNAN) ^ ((x & MASK_SNAN) ==
512 // it comes down to the payload. we want to return true if x has a
513 // larger payload, or if the payloads are equal (canonical forms
514 // are bitwise identical)
515 pyld_y = y & 0x0003ffffffffffffull;
516 pyld_x = x & 0x0003ffffffffffffull;
517 if (pyld_y > 999999999999999ull || pyld_y == 0) {
518 // if y is zero, x must be less than or numerically equal
523 // if x is zero and y isn't, x has the smaller payload
524 // definitely (since we know y isn't 0 at this point)
525 if (pyld_x > 999999999999999ull || pyld_x == 0) {
530 res = (pyld_x >= pyld_y);
533 // either x = -sNaN and y = -qNaN or x = -qNaN and y = -sNaN
534 res = (y & MASK_SNAN) == MASK_SNAN; // totalOrder(-qNaN, -sNaN) == 1
538 } else { // x is +NaN
539 // return false, unless y is +NaN also
540 if ((y & MASK_NAN) != MASK_NAN || (y & MASK_SIGN) == MASK_SIGN) {
541 res = 0; // y is a number, return 1
544 // x and y are both +NaN;
545 // must investigate payload if both quiet or both signaling
546 // this xnor statement will be true if both x and y are +qNaN or +sNaN
548 (((y & MASK_SNAN) == MASK_SNAN) ^ ((x & MASK_SNAN) ==
550 // it comes down to the payload. we want to return true if x has a
551 // smaller payload, or if the payloads are equal (canonical forms
552 // are bitwise identical)
553 pyld_y = y & 0x0003ffffffffffffull;
554 pyld_x = x & 0x0003ffffffffffffull;
555 // if x is zero and y isn't, x has the smaller
556 // payload definitely (since we know y isn't 0 at this point)
557 if (pyld_x > 999999999999999ull || pyld_x == 0) {
561 if (pyld_y > 999999999999999ull || pyld_y == 0) {
562 // if y is zero, x must be less than or numerically equal
566 res = (pyld_x <= pyld_y);
569 // return true if y is +qNaN and x is +sNaN
570 // (we know they're different bc of xor if_stmt above)
571 res = ((x & MASK_SNAN) == MASK_SNAN);
576 } else if ((y & MASK_NAN) == MASK_NAN) {
577 // x is certainly not NAN in this case.
578 // return true if y is positive
579 res = ((y & MASK_SIGN) != MASK_SIGN);
583 // if all the bits are the same, these numbers are equal.
588 // OPPOSITE SIGNS (CASE 3)
589 // if signs are opposite, return 1 if x is negative
590 // (if x<y, totalOrder is true)
591 if (((x & MASK_SIGN) == MASK_SIGN) ^ ((y & MASK_SIGN) == MASK_SIGN)) {
592 res = (x & MASK_SIGN) == MASK_SIGN;
596 if ((x & MASK_INF) == MASK_INF) {
597 // if x==neg_inf, return (y == neg_inf)?1:0;
598 if ((x & MASK_SIGN) == MASK_SIGN) {
602 // x is positive infinity, only return1 if y
603 // is positive infinity as well
604 // (we know y has same sign as x)
605 res = ((y & MASK_INF) == MASK_INF);
608 } else if ((y & MASK_INF) == MASK_INF) {
612 res = ((y & MASK_SIGN) != MASK_SIGN);
615 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
616 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
617 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
618 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
619 if (sig_x > 9999999999999999ull || sig_x == 0) {
623 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
624 sig_x = (x & MASK_BINARY_SIG1);
630 // if steering bits are 11 (condition will be 0), then exponent is G[0:w+1] =>
631 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
632 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
633 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
634 if (sig_y > 9999999999999999ull || sig_y == 0) {
638 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
639 sig_y = (y & MASK_BINARY_SIG1);
646 // if x and y represent the same entities, and
647 // both are negative , return true iff exp_x <= exp_y
648 if (x_is_zero && y_is_zero) {
649 if (!((x & MASK_SIGN) == MASK_SIGN) ^
650 ((y & MASK_SIGN) == MASK_SIGN)) {
651 // if signs are the same:
652 // totalOrder(x,y) iff exp_x >= exp_y for negative numbers
653 // totalOrder(x,y) iff exp_x <= exp_y for positive numbers
654 if (exp_x == exp_y) {
658 res = (exp_x <= exp_y) ^ ((x & MASK_SIGN) == MASK_SIGN);
661 // signs are different.
662 // totalOrder(-0, +0) is true
663 // totalOrder(+0, -0) is false
664 res = ((x & MASK_SIGN) == MASK_SIGN);
668 // if x is zero and y isn't, clearly x has the smaller payload.
670 res = ((y & MASK_SIGN) != MASK_SIGN);
673 // if y is zero, and x isn't, clearly y has the smaller payload.
675 res = ((x & MASK_SIGN) == MASK_SIGN);
678 // REDUNDANT REPRESENTATIONS (CASE6)
679 // if both components are either bigger or smaller,
680 // it is clear what needs to be done
681 if (sig_x > sig_y && exp_x >= exp_y) {
682 res = ((x & MASK_SIGN) == MASK_SIGN);
685 if (sig_x < sig_y && exp_x <= exp_y) {
686 res = ((x & MASK_SIGN) != MASK_SIGN);
689 // if exp_x is 15 greater than exp_y, it is
690 // definitely larger, so no need for compensation
691 if (exp_x - exp_y > 15) {
692 // difference cannot be greater than 10^15
693 res = ((x & MASK_SIGN) == MASK_SIGN);
696 // if exp_x is 15 less than exp_y, it is
697 // definitely smaller, no need for compensation
698 if (exp_y - exp_x > 15) {
699 res = ((x & MASK_SIGN) != MASK_SIGN);
702 // if |exp_x - exp_y| < 15, it comes down
703 // to the compensated significand
705 // otherwise adjust the x significand upwards
706 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
707 mult_factor[exp_x - exp_y]);
708 // if x and y represent the same entities,
709 // and both are negative, return true iff exp_x <= exp_y
710 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
711 // case cannot occure, because all bits must
712 // be the same - would have been caught if (x==y)
713 res = (exp_x <= exp_y) ^ ((x & MASK_SIGN) == MASK_SIGN);
716 // if positive, return 1 if adjusted x is smaller than y
717 res = ((sig_n_prime.w[1] == 0)
718 && sig_n_prime.w[0] < sig_y) ^ ((x & MASK_SIGN) ==
722 // adjust the y significand upwards
723 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
724 mult_factor[exp_y - exp_x]);
726 // if x and y represent the same entities,
727 // and both are negative, return true iff exp_x <= exp_y
728 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
729 // Cannot occur, because all bits must be the same.
730 // Case would have been caught if (x==y)
731 res = (exp_x <= exp_y) ^ ((x & MASK_SIGN) == MASK_SIGN);
734 // values are not equal, for positive numbers return 1
735 // if x is less than y. 0 otherwise
736 res = ((sig_n_prime.w[1] > 0)
737 || (sig_x < sig_n_prime.w[0])) ^ ((x & MASK_SIGN) ==
742 // totalOrderMag is TotalOrder(abs(x), abs(y))
743 #if DECIMAL_CALL_BY_REFERENCE
745 bid64_totalOrderMag (int *pres, UINT64 * px,
746 UINT64 * py _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
751 bid64_totalOrderMag (UINT64 x,
752 UINT64 y _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
756 UINT64 sig_x, sig_y, pyld_y, pyld_x;
758 char x_is_zero = 0, y_is_zero = 0;
761 // if x and y are unordered numerically because either operand is NaN
762 // (1) totalOrder(number, +NaN) is true
763 // (2) if x and y are both NaN:
764 // i) signaling < quiet for +NaN
765 // ii) lesser payload < greater payload for +NaN
766 // iii) else if bitwise identical (in canonical form), return 1
767 if ((x & MASK_NAN) == MASK_NAN) {
770 // return false, unless y is +NaN also
771 if ((y & MASK_NAN) != MASK_NAN) {
772 res = 0; // y is a number, return 1
777 // x and y are both +NaN;
778 // must investigate payload if both quiet or both signaling
779 // this xnor statement will be true if both x and y are +qNaN or +sNaN
781 (((y & MASK_SNAN) == MASK_SNAN) ^ ((x & MASK_SNAN) ==
783 // it comes down to the payload. we want to return true if x has a
784 // smaller payload, or if the payloads are equal (canonical forms
785 // are bitwise identical)
786 pyld_y = y & 0x0003ffffffffffffull;
787 pyld_x = x & 0x0003ffffffffffffull;
788 // if x is zero and y isn't, x has the smaller
789 // payload definitely (since we know y isn't 0 at this point)
790 if (pyld_x > 999999999999999ull || pyld_x == 0) {
795 if (pyld_y > 999999999999999ull || pyld_y == 0) {
796 // if y is zero, x must be less than or numerically equal
800 res = (pyld_x <= pyld_y);
804 // return true if y is +qNaN and x is +sNaN
805 // (we know they're different bc of xor if_stmt above)
806 res = ((x & MASK_SNAN) == MASK_SNAN);
811 } else if ((y & MASK_NAN) == MASK_NAN) {
812 // x is certainly not NAN in this case.
813 // return true if y is positive
818 // if all the bits (except sign bit) are the same,
819 // these numbers are equal.
820 if ((x & ~MASK_SIGN) == (y & ~MASK_SIGN)) {
825 if ((x & MASK_INF) == MASK_INF) {
826 // x is positive infinity, only return1
827 // if y is positive infinity as well
828 res = ((y & MASK_INF) == MASK_INF);
830 } else if ((y & MASK_INF) == MASK_INF) {
836 // if steering bits are 11 (condition will be 0),
837 // then exponent is G[0:w+1] =>
838 if ((x & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
839 exp_x = (x & MASK_BINARY_EXPONENT2) >> 51;
840 sig_x = (x & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
841 if (sig_x > 9999999999999999ull || sig_x == 0) {
845 exp_x = (x & MASK_BINARY_EXPONENT1) >> 53;
846 sig_x = (x & MASK_BINARY_SIG1);
852 // if steering bits are 11 (condition will be 0),
853 // then exponent is G[0:w+1] =>
854 if ((y & MASK_STEERING_BITS) == MASK_STEERING_BITS) {
855 exp_y = (y & MASK_BINARY_EXPONENT2) >> 51;
856 sig_y = (y & MASK_BINARY_SIG2) | MASK_BINARY_OR2;
857 if (sig_y > 9999999999999999ull || sig_y == 0) {
861 exp_y = (y & MASK_BINARY_EXPONENT1) >> 53;
862 sig_y = (y & MASK_BINARY_SIG1);
869 // if x and y represent the same entities,
870 // and both are negative , return true iff exp_x <= exp_y
871 if (x_is_zero && y_is_zero) {
872 // totalOrder(x,y) iff exp_x <= exp_y for positive numbers
873 res = (exp_x <= exp_y);
876 // if x is zero and y isn't, clearly x has the smaller payload.
881 // if y is zero, and x isn't, clearly y has the smaller payload.
886 // REDUNDANT REPRESENTATIONS (CASE6)
887 // if both components are either bigger or smaller
888 if (sig_x > sig_y && exp_x >= exp_y) {
892 if (sig_x < sig_y && exp_x <= exp_y) {
896 // if exp_x is 15 greater than exp_y, it is definitely
897 // larger, so no need for compensation
898 if (exp_x - exp_y > 15) {
899 res = 0; // difference cannot be greater than 10^15
902 // if exp_x is 15 less than exp_y, it is definitely
903 // smaller, no need for compensation
904 if (exp_y - exp_x > 15) {
908 // if |exp_x - exp_y| < 15, it comes down
909 // to the compensated significand
912 // otherwise adjust the x significand upwards
913 __mul_64x64_to_128MACH (sig_n_prime, sig_x,
914 mult_factor[exp_x - exp_y]);
916 // if x and y represent the same entities,
917 // and both are negative, return true iff exp_x <= exp_y
918 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_y)) {
919 // case cannot occur, because all bits
920 // must be the same - would have been caught if (x==y)
921 res = (exp_x <= exp_y);
924 // if positive, return 1 if adjusted x is smaller than y
925 res = ((sig_n_prime.w[1] == 0) && sig_n_prime.w[0] < sig_y);
928 // adjust the y significand upwards
929 __mul_64x64_to_128MACH (sig_n_prime, sig_y,
930 mult_factor[exp_y - exp_x]);
932 // if x and y represent the same entities,
933 // and both are negative, return true iff exp_x <= exp_y
934 if (sig_n_prime.w[1] == 0 && (sig_n_prime.w[0] == sig_x)) {
935 res = (exp_x <= exp_y);
938 // values are not equal, for positive numbers
939 // return 1 if x is less than y. 0 otherwise
940 res = ((sig_n_prime.w[1] > 0) || (sig_x < sig_n_prime.w[0]));
945 #if DECIMAL_CALL_BY_REFERENCE
947 bid64_radix (int *pres, UINT64 * px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
951 bid64_radix (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {