OSDN Git Service

libgcc/
[pf3gnuchains/gcc-fork.git] / libgcc / config / libbid / bid_from_int.c
index f8d1dd2..bebc135 100644 (file)
@@ -34,12 +34,12 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
 
 #if DECIMAL_CALL_BY_REFERENCE
 void
-__bid64_from_int32 (UINT64 * pres,
+bid64_from_int32 (UINT64 * pres,
                  int *px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
   int x = *px;
 #else
 UINT64
-__bid64_from_int32 (int x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
+bid64_from_int32 (int x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
 #endif
   UINT64 res;
 
@@ -47,33 +47,33 @@ __bid64_from_int32 (int x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
   // in the lowest 32bits of the result
   if ((x & SIGNMASK32) == SIGNMASK32) {
     // negative int32
-    x = ~x + 1; // 2's complement of x
-    res = (unsigned int)x | 0xb1c0000000000000ull; 
-        // (exp << 53)) = biased exp. is 0
-  } else { // positive int32
-    res = x | 0x31c0000000000000ull; // (exp << 53)) = biased exp. is 0
+    x = ~x + 1;        // 2's complement of x
+    res = (unsigned int) x | 0xb1c0000000000000ull;
+    // (exp << 53)) = biased exp. is 0
+  } else {     // positive int32
+    res = x | 0x31c0000000000000ull;   // (exp << 53)) = biased exp. is 0
   }
   BID_RETURN (res);
 }
 
 #if DECIMAL_CALL_BY_REFERENCE
 void
-__bid64_from_uint32 (UINT64 * pres, unsigned int *px
+bid64_from_uint32 (UINT64 * pres, unsigned int *px
                   _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
   unsigned int x = *px;
 #else
 UINT64
-__bid64_from_uint32 (unsigned int x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
+bid64_from_uint32 (unsigned int x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
 #endif
   UINT64 res;
 
-  res = x | 0x31c0000000000000ull; // (exp << 53)) = biased exp. is 0
+  res = x | 0x31c0000000000000ull;     // (exp << 53)) = biased exp. is 0
   BID_RETURN (res);
 }
 
 #if DECIMAL_CALL_BY_REFERENCE
 void
-__bid64_from_int64 (UINT64 * pres, SINT64 * px
+bid64_from_int64 (UINT64 * pres, SINT64 * px
                  _RND_MODE_PARAM _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
                  _EXC_INFO_PARAM) {
   SINT64 x = *px;
@@ -82,7 +82,7 @@ __bid64_from_int64 (UINT64 * pres, SINT64 * px
 #endif
 #else
 UINT64
-__bid64_from_int64 (SINT64 x
+bid64_from_int64 (SINT64 x
                  _RND_MODE_PARAM _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
                  _EXC_INFO_PARAM) {
 #endif
@@ -100,29 +100,29 @@ __bid64_from_int64 (SINT64 x
     C = ~((UINT64) x) + 1;
   else
     C = x;
-  if (C <= BID64_SIG_MAX) { // |C| <= 10^16-1 and the result is exact
-    if (C < 0x0020000000000000ull) { // C < 2^53
+  if (C <= BID64_SIG_MAX) {    // |C| <= 10^16-1 and the result is exact
+    if (C < 0x0020000000000000ull) {   // C < 2^53
       res = x_sign | 0x31c0000000000000ull | C;
-    } else { // C >= 2^53
+    } else {   // C >= 2^53
       res =
        x_sign | 0x6c70000000000000ull | (C & 0x0007ffffffffffffull);
     }
-  } else { // |C| >= 10^16 and the result may be inexact 
+  } else {     // |C| >= 10^16 and the result may be inexact 
     // the smallest |C| is 10^16 which has 17 decimal digits
     // the largest |C| is 0x8000000000000000 = 9223372036854775808 w/ 19 digits
-    if (C < 0x16345785d8a0000ull) { // x < 10^17 
+    if (C < 0x16345785d8a0000ull) {    // x < 10^17 
       q = 17;
-      ind = 1; // number of digits to remove for q = 17
-    } else if (C < 0xde0b6b3a7640000ull) { // C < 10^18
+      ind = 1; // number of digits to remove for q = 17
+    } else if (C < 0xde0b6b3a7640000ull) {     // C < 10^18
       q = 18;
-      ind = 2; // number of digits to remove for q = 18 
-    } else { // C < 10^19
+      ind = 2; // number of digits to remove for q = 18 
+    } else {   // C < 10^19
       q = 19;
-      ind = 3; // number of digits to remove for q = 19
+      ind = 3; // number of digits to remove for q = 19
     }
     // overflow and underflow are not possible
     // Note: performace can be improved by inlining this call
-    __bid_round64_2_18 (       // will work for 19 digits too if C fits in 64 bits
+    round64_2_18 (     // will work for 19 digits too if C fits in 64 bits
                   q, ind, C, &res, &incr_exp,
                   &is_midpoint_lt_even, &is_midpoint_gt_even,
                   &is_inexact_lt_midpoint, &is_inexact_gt_midpoint);
@@ -134,35 +134,40 @@ __bid64_from_int64 (SINT64 x
       *pfpsf |= INEXACT_EXCEPTION;
     // general correction from RN to RA, RM, RP, RZ; result uses ind for exp
     if (rnd_mode != ROUNDING_TO_NEAREST) {
-      if ((!x_sign && ((rnd_mode == ROUNDING_UP && is_inexact_lt_midpoint) || 
-          ((rnd_mode == ROUNDING_TIES_AWAY || rnd_mode == ROUNDING_UP) && 
-          is_midpoint_gt_even))) || 
-          (x_sign && ((rnd_mode == ROUNDING_DOWN && is_inexact_lt_midpoint) || 
-          ((rnd_mode == ROUNDING_TIES_AWAY || rnd_mode == ROUNDING_DOWN) && 
-          is_midpoint_gt_even)))) {
+      if ((!x_sign
+          && ((rnd_mode == ROUNDING_UP && is_inexact_lt_midpoint)
+              ||
+              ((rnd_mode == ROUNDING_TIES_AWAY
+                || rnd_mode == ROUNDING_UP) && is_midpoint_gt_even)))
+         || (x_sign
+             && ((rnd_mode == ROUNDING_DOWN && is_inexact_lt_midpoint)
+                 ||
+                 ((rnd_mode == ROUNDING_TIES_AWAY
+                   || rnd_mode == ROUNDING_DOWN)
+                  && is_midpoint_gt_even)))) {
        res = res + 1;
-       if (res == 0x002386f26fc10000ull) { // res = 10^16 => rounding overflow
-         res = 0x00038d7ea4c68000ull; // 10^15
+       if (res == 0x002386f26fc10000ull) {     // res = 10^16 => rounding overflow
+         res = 0x00038d7ea4c68000ull;  // 10^15
          ind = ind + 1;
        }
       } else if ((is_midpoint_lt_even || is_inexact_gt_midpoint) &&
-          ((x_sign && 
-          (rnd_mode == ROUNDING_UP || rnd_mode == ROUNDING_TO_ZERO)) ||
-          (!x_sign && 
-          (rnd_mode == ROUNDING_DOWN || rnd_mode == ROUNDING_TO_ZERO)))) {
+                ((x_sign && (rnd_mode == ROUNDING_UP ||
+                             rnd_mode == ROUNDING_TO_ZERO)) ||
+                 (!x_sign && (rnd_mode == ROUNDING_DOWN ||
+                              rnd_mode == ROUNDING_TO_ZERO)))) {
        res = res - 1;
        // check if we crossed into the lower decade
-       if (res == 0x00038d7ea4c67fffull) { // 10^15 - 1
-         res = 0x002386f26fc0ffffull; // 10^16 - 1
+       if (res == 0x00038d7ea4c67fffull) {     // 10^15 - 1
+         res = 0x002386f26fc0ffffull;  // 10^16 - 1
          ind = ind - 1;
        }
       } else {
-       ; // exact, the result is already correct
+       ;       // exact, the result is already correct
       }
     }
-    if (res < 0x0020000000000000ull) { // res < 2^53
+    if (res < 0x0020000000000000ull) { // res < 2^53
       res = x_sign | (((UINT64) ind + 398) << 53) | res;
-    } else { // res >= 2^53 
+    } else {   // res >= 2^53 
       res =
        x_sign | 0x6000000000000000ull | (((UINT64) ind + 398) << 51) |
        (res & 0x0007ffffffffffffull);
@@ -173,7 +178,7 @@ __bid64_from_int64 (SINT64 x
 
 #if DECIMAL_CALL_BY_REFERENCE
 void
-__bid64_from_uint64 (UINT64 * pres, UINT64 * px
+bid64_from_uint64 (UINT64 * pres, UINT64 * px
                   _RND_MODE_PARAM _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
                   _EXC_INFO_PARAM) {
   UINT64 x = *px;
@@ -182,7 +187,7 @@ __bid64_from_uint64 (UINT64 * pres, UINT64 * px
 #endif
 #else
 UINT64
-__bid64_from_uint64 (UINT64 x
+bid64_from_uint64 (UINT64 x
                   _RND_MODE_PARAM _EXC_FLAGS_PARAM _EXC_MASKS_PARAM
                   _EXC_INFO_PARAM) {
 #endif
@@ -194,42 +199,42 @@ __bid64_from_uint64 (UINT64 x
   int is_midpoint_lt_even = 0, is_midpoint_gt_even = 0;
   int is_inexact_lt_midpoint = 0, is_inexact_gt_midpoint = 0;
 
-  if (x <= BID64_SIG_MAX) { // x <= 10^16-1 and the result is exact
-    if (x < 0x0020000000000000ull) { // x < 2^53
+  if (x <= BID64_SIG_MAX) {    // x <= 10^16-1 and the result is exact
+    if (x < 0x0020000000000000ull) {   // x < 2^53
       res = 0x31c0000000000000ull | x;
-    } else { // x >= 2^53
+    } else {   // x >= 2^53
       res = 0x6c70000000000000ull | (x & 0x0007ffffffffffffull);
     }
-  } else { // x >= 10^16 and the result may be inexact 
+  } else {     // x >= 10^16 and the result may be inexact 
     // the smallest x is 10^16 which has 17 decimal digits
     // the largest x is 0xffffffffffffffff = 18446744073709551615 w/ 20 digits
-    if (x < 0x16345785d8a0000ull) { // x < 10^17 
+    if (x < 0x16345785d8a0000ull) {    // x < 10^17 
       q = 17;
-      ind = 1; // number of digits to remove for q = 17
-    } else if (x < 0xde0b6b3a7640000ull) { // x < 10^18
+      ind = 1; // number of digits to remove for q = 17
+    } else if (x < 0xde0b6b3a7640000ull) {     // x < 10^18
       q = 18;
-      ind = 2; // number of digits to remove for q = 18 
-    } else if (x < 0x8ac7230489e80000ull) { // x < 10^19
+      ind = 2; // number of digits to remove for q = 18 
+    } else if (x < 0x8ac7230489e80000ull) {    // x < 10^19
       q = 19;
-      ind = 3; // number of digits to remove for q = 19
-    } else { // x < 10^20
+      ind = 3; // number of digits to remove for q = 19
+    } else {   // x < 10^20
       q = 20;
-      ind = 4; // number of digits to remove for q = 20
+      ind = 4; // number of digits to remove for q = 20
     }
     // overflow and underflow are not possible
     // Note: performace can be improved by inlining this call
     if (q <= 19) {
-      __bid_round64_2_18 (     // will work for 20 digits too if x fits in 64 bits
+      round64_2_18 (   // will work for 20 digits too if x fits in 64 bits
                     q, ind, x, &res, &incr_exp,
                     &is_midpoint_lt_even, &is_midpoint_gt_even,
                     &is_inexact_lt_midpoint, &is_inexact_gt_midpoint);
-    } else { // q = 20
+    } else {   // q = 20
       x128.w[1] = 0x0;
       x128.w[0] = x;
-      __bid_round128_19_38 (q, ind, x128, &res128, &incr_exp,
+      round128_19_38 (q, ind, x128, &res128, &incr_exp,
                      &is_midpoint_lt_even, &is_midpoint_gt_even,
                      &is_inexact_lt_midpoint, &is_inexact_gt_midpoint);
-      res = res128.w[0]; // res.w[1] is 0
+      res = res128.w[0];       // res.w[1] is 0
     }
     if (incr_exp)
       ind++;
@@ -239,12 +244,12 @@ __bid64_from_uint64 (UINT64 x
       *pfpsf |= INEXACT_EXCEPTION;
     // general correction from RN to RA, RM, RP, RZ; result uses ind for exp
     if (rnd_mode != ROUNDING_TO_NEAREST) {
-      if ((rnd_mode == ROUNDING_UP && is_inexact_lt_midpoint) || 
-          ((rnd_mode == ROUNDING_TIES_AWAY || rnd_mode == ROUNDING_UP) && 
-          is_midpoint_gt_even)) {
+      if ((rnd_mode == ROUNDING_UP && is_inexact_lt_midpoint) ||
+         ((rnd_mode == ROUNDING_TIES_AWAY || rnd_mode == ROUNDING_UP)
+          && is_midpoint_gt_even)) {
        res = res + 1;
-       if (res == 0x002386f26fc10000ull) { // res = 10^16 => rounding overflow
-         res = 0x00038d7ea4c68000ull; // 10^15
+       if (res == 0x002386f26fc10000ull) {     // res = 10^16 => rounding overflow
+         res = 0x00038d7ea4c68000ull;  // 10^15
          ind = ind + 1;
        }
       } else if ((is_midpoint_lt_even || is_inexact_gt_midpoint) &&
@@ -252,17 +257,17 @@ __bid64_from_uint64 (UINT64 x
                  rnd_mode == ROUNDING_TO_ZERO)) {
        res = res - 1;
        // check if we crossed into the lower decade
-       if (res == 0x00038d7ea4c67fffull) { // 10^15 - 1
-         res = 0x002386f26fc0ffffull; // 10^16 - 1
+       if (res == 0x00038d7ea4c67fffull) {     // 10^15 - 1
+         res = 0x002386f26fc0ffffull;  // 10^16 - 1
          ind = ind - 1;
        }
       } else {
-       ; // exact, the result is already correct
+       ;       // exact, the result is already correct
       }
     }
-    if (res < 0x0020000000000000ull) { // res < 2^53
+    if (res < 0x0020000000000000ull) { // res < 2^53
       res = (((UINT64) ind + 398) << 53) | res;
-    } else { // res >= 2^53 
+    } else {   // res >= 2^53 
       res = 0x6000000000000000ull | (((UINT64) ind + 398) << 51) |
        (res & 0x0007ffffffffffffull);
     }
@@ -272,34 +277,34 @@ __bid64_from_uint64 (UINT64 x
 
 #if DECIMAL_CALL_BY_REFERENCE
 void
-__bid128_from_int32 (UINT128 * pres,
+bid128_from_int32 (UINT128 * pres,
                   int *px _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
   int x = *px;
 #else
 UINT128
-__bid128_from_int32 (int x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
+bid128_from_int32 (int x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
 #endif
   UINT128 res;
 
   // if integer is negative, use the absolute value
   if ((x & SIGNMASK32) == SIGNMASK32) {
     res.w[HIGH_128W] = 0xb040000000000000ull;
-    res.w[LOW_128W] = ~((unsigned int)x) + 1; // 2's complement of x
+    res.w[LOW_128W] = ~((unsigned int) x) + 1; // 2's complement of x
   } else {
     res.w[HIGH_128W] = 0x3040000000000000ull;
-    res.w[LOW_128W] = (unsigned int)x;
+    res.w[LOW_128W] = (unsigned int) x;
   }
   BID_RETURN (res);
 }
 
 #if DECIMAL_CALL_BY_REFERENCE
 void
-__bid128_from_uint32 (UINT128 * pres, unsigned int *px
+bid128_from_uint32 (UINT128 * pres, unsigned int *px
                    _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
   unsigned int x = *px;
 #else
 UINT128
-__bid128_from_uint32 (unsigned int x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
+bid128_from_uint32 (unsigned int x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
 #endif
   UINT128 res;
 
@@ -310,12 +315,12 @@ __bid128_from_uint32 (unsigned int x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
 
 #if DECIMAL_CALL_BY_REFERENCE
 void
-__bid128_from_int64 (UINT128 * pres, SINT64 * px
+bid128_from_int64 (UINT128 * pres, SINT64 * px
                   _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
   SINT64 x = *px;
 #else
 UINT128
-__bid128_from_int64 (SINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
+bid128_from_int64 (SINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
 #endif
 
   UINT128 res;
@@ -323,7 +328,7 @@ __bid128_from_int64 (SINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
   // if integer is negative, use the absolute value
   if ((x & SIGNMASK64) == SIGNMASK64) {
     res.w[HIGH_128W] = 0xb040000000000000ull;
-    res.w[LOW_128W] = ~x + 1; // 2's complement of x
+    res.w[LOW_128W] = ~x + 1;  // 2's complement of x
   } else {
     res.w[HIGH_128W] = 0x3040000000000000ull;
     res.w[LOW_128W] = x;
@@ -333,12 +338,12 @@ __bid128_from_int64 (SINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
 
 #if DECIMAL_CALL_BY_REFERENCE
 void
-__bid128_from_uint64 (UINT128 * pres, UINT64 * px
+bid128_from_uint64 (UINT128 * pres, UINT64 * px
                    _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
   UINT64 x = *px;
 #else
 UINT128
-__bid128_from_uint64 (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
+bid128_from_uint64 (UINT64 x _EXC_MASKS_PARAM _EXC_INFO_PARAM) {
 #endif
 
   UINT128 res;