diff options
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 54 |
1 files changed, 16 insertions, 38 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 66eee99c6ec..8c921ce7948 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -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); } |