diff options
Diffstat (limited to 'llvm/lib/Support/APFloat.cpp')
-rw-r--r-- | llvm/lib/Support/APFloat.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp index 7abca83..c9ecd5a 100644 --- a/llvm/lib/Support/APFloat.cpp +++ b/llvm/lib/Support/APFloat.cpp @@ -1288,6 +1288,23 @@ IEEEFloat::compareAbsoluteValue(const IEEEFloat &rhs) const { return cmpEqual; } +/* Set the least significant BITS bits of a bignum, clear the + rest. */ +static void tcSetLeastSignificantBits(APInt::WordType *dst, unsigned parts, + unsigned bits) { + unsigned i = 0; + while (bits > APInt::APINT_BITS_PER_WORD) { + dst[i++] = ~(APInt::WordType)0; + bits -= APInt::APINT_BITS_PER_WORD; + } + + if (bits) + dst[i++] = ~(APInt::WordType)0 >> (APInt::APINT_BITS_PER_WORD - bits); + + while (i < parts) + dst[i++] = 0; +} + /* Handle overflow. Sign is preserved. We either become infinity or the largest finite number. */ IEEEFloat::opStatus IEEEFloat::handleOverflow(roundingMode rounding_mode) { @@ -1303,8 +1320,8 @@ IEEEFloat::opStatus IEEEFloat::handleOverflow(roundingMode rounding_mode) { /* Otherwise we become the largest finite number. */ category = fcNormal; exponent = semantics->maxExponent; - APInt::tcSetLeastSignificantBits(significandParts(), partCount(), - semantics->precision); + tcSetLeastSignificantBits(significandParts(), partCount(), + semantics->precision); return opInexact; } @@ -2412,7 +2429,7 @@ IEEEFloat::convertToInteger(MutableArrayRef<integerPart> parts, else bits = width - isSigned; - APInt::tcSetLeastSignificantBits(parts.data(), dstPartsCount, bits); + tcSetLeastSignificantBits(parts.data(), dstPartsCount, bits); if (sign && isSigned) APInt::tcShiftLeft(parts.data(), dstPartsCount, width - 1); } |