aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/APFloat.cpp
diff options
context:
space:
mode:
authorChris Lattner <clattner@nondot.org>2021-09-08 17:36:43 -0700
committerChris Lattner <clattner@nondot.org>2021-09-08 18:17:07 -0700
commit9e46dd965abd5f52ae00c28cc4f23ec5706e7ba2 (patch)
tree3657439c3dfc7ebe4c6f51b1733e33ee74224744 /llvm/lib/Support/APFloat.cpp
parent22a64d4a143d0d549cc762e1a19260078d1836c2 (diff)
downloadllvm-9e46dd965abd5f52ae00c28cc4f23ec5706e7ba2.zip
llvm-9e46dd965abd5f52ae00c28cc4f23ec5706e7ba2.tar.gz
llvm-9e46dd965abd5f52ae00c28cc4f23ec5706e7ba2.tar.bz2
[APInt.h] Reduce the APInt header file interface a bit. NFC
This moves one mid-size function out of line, inlines the trivial tcAnd/tcOr/tcXor/tcComplement methods into their only caller, and moves the magic/umagic functions into SelectionDAG since they are implementation details of its algorithm. This also removes the unit tests for magic, but these are already tested in the divide lowering logic for various targets. This also upgrades some C style comments to C++. Differential Revision: https://reviews.llvm.org/D109476
Diffstat (limited to 'llvm/lib/Support/APFloat.cpp')
-rw-r--r--llvm/lib/Support/APFloat.cpp23
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);
}