Changes in directory llvm/lib/Support:
APInt.cpp updated: 1.50 -> 1.51 --- Log message: Simplify and document RoundDoubleToAPInt. --- Diffs of the changes: (+15 -3) APInt.cpp | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) Index: llvm/lib/Support/APInt.cpp diff -u llvm/lib/Support/APInt.cpp:1.50 llvm/lib/Support/APInt.cpp:1.51 --- llvm/lib/Support/APInt.cpp:1.50 Mon Feb 26 17:38:21 2007 +++ llvm/lib/Support/APInt.cpp Mon Feb 26 19:28:10 2007 @@ -803,15 +803,27 @@ uint64_t I; } T; T.D = Double; + + // Get the sign bit from the highest order bit bool isNeg = T.I >> 63; + + // Get the 11-bit exponent and adjust for the 1023 bit bias int64_t exp = ((T.I >> 52) & 0x7ff) - 1023; + + // If the exponent is negative, the value is < 0 so just return 0. if (exp < 0) - return APInt(64ull, 0u); - uint64_t mantissa = ((T.I << 12) >> 12) | (1ULL << 52); + return APInt(64u, 0u); + + // Extract the mantissa by clearing the top 12 bits (sign + exponent). + uint64_t mantissa = (T.I & (~0ULL >> 12)) | 1ULL << 52; + + // If the exponent doesn't shift all bits out of the mantissa if (exp < 52) return isNeg ? -APInt(64u, mantissa >> (52 - exp)) : APInt(64u, mantissa >> (52 - exp)); - APInt Tmp(exp + 1, mantissa); + + // Otherwise, we have to shift the mantissa bits up to the right location + APInt Tmp(exp+1, mantissa); Tmp = Tmp.shl(exp - 52); return isNeg ? -Tmp : Tmp; } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits