diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:17:04 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-01-02 19:17:04 +0000 |
commit | b915e9e0fc85ba6f398b3fab0db6a81a8913af94 (patch) | |
tree | 98b8f811c7aff2547cab8642daf372d6c59502fb /lib/Support/APInt.cpp | |
parent | 6421cca32f69ac849537a3cff78c352195e99f1b (diff) |
Notes
Diffstat (limited to 'lib/Support/APInt.cpp')
-rw-r--r-- | lib/Support/APInt.cpp | 64 |
1 files changed, 19 insertions, 45 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 66eee99c6ec2..0c0b498f1375 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -22,10 +22,10 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" +#include <climits> #include <cmath> #include <cstdlib> #include <cstring> -#include <limits> using namespace llvm; #define DEBUG_TYPE "apint" @@ -260,6 +260,14 @@ APInt& APInt::operator+=(const APInt& RHS) { return clearUnusedBits(); } +APInt& APInt::operator+=(uint64_t RHS) { + if (isSingleWord()) + VAL += RHS; + else + add_1(pVal, pVal, getNumWords(), RHS); + return clearUnusedBits(); +} + /// Subtracts the integer array y from the integer array x /// @returns returns the borrow out. /// @brief Generalized subtraction of 64-bit integer arrays. @@ -286,6 +294,14 @@ APInt& APInt::operator-=(const APInt& RHS) { return clearUnusedBits(); } +APInt& APInt::operator-=(uint64_t RHS) { + if (isSingleWord()) + VAL -= RHS; + else + sub_1(pVal, getNumWords(), RHS); + return clearUnusedBits(); +} + /// Multiplies an integer array, x, by a uint64_t integer and places the result /// into dest. /// @returns the carry out of the multiplication. @@ -470,44 +486,6 @@ APInt APInt::operator*(const APInt& RHS) const { return Result; } -APInt APInt::operator+(const APInt& RHS) const { - assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); - if (isSingleWord()) - return APInt(BitWidth, VAL + RHS.VAL); - APInt Result(BitWidth, 0); - add(Result.pVal, this->pVal, RHS.pVal, getNumWords()); - Result.clearUnusedBits(); - return Result; -} - -APInt APInt::operator+(uint64_t RHS) const { - if (isSingleWord()) - return APInt(BitWidth, VAL + RHS); - APInt Result(*this); - add_1(Result.pVal, Result.pVal, getNumWords(), RHS); - Result.clearUnusedBits(); - return Result; -} - -APInt APInt::operator-(const APInt& RHS) const { - assert(BitWidth == RHS.BitWidth && "Bit widths must be the same"); - if (isSingleWord()) - return APInt(BitWidth, VAL - RHS.VAL); - APInt Result(BitWidth, 0); - sub(Result.pVal, this->pVal, RHS.pVal, getNumWords()); - Result.clearUnusedBits(); - return Result; -} - -APInt APInt::operator-(uint64_t RHS) const { - if (isSingleWord()) - return APInt(BitWidth, VAL - RHS); - APInt Result(*this); - sub_1(Result.pVal, getNumWords(), RHS); - Result.clearUnusedBits(); - return Result; -} - bool APInt::EqualSlowCase(const APInt& RHS) const { return std::equal(pVal, pVal + getNumWords(), RHS.pVal); } @@ -1064,11 +1042,7 @@ APInt APInt::ashr(unsigned shiftAmt) const { if (isSingleWord()) { if (shiftAmt == BitWidth) return APInt(BitWidth, 0); // undefined - else { - unsigned SignBit = APINT_BITS_PER_WORD - BitWidth; - return APInt(BitWidth, - (((int64_t(VAL) << SignBit) >> SignBit) >> shiftAmt)); - } + return APInt(BitWidth, SignExtend64(VAL, BitWidth) >> shiftAmt); } // If all the bits were shifted out, the result is, technically, undefined. @@ -1521,7 +1495,7 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r, assert(n>1 && "n must be > 1"); // b denotes the base of the number system. In our case b is 2^32. - LLVM_CONSTEXPR uint64_t b = uint64_t(1) << 32; + const uint64_t b = uint64_t(1) << 32; DEBUG(dbgs() << "KnuthDiv: m=" << m << " n=" << n << '\n'); DEBUG(dbgs() << "KnuthDiv: original:"); |