diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Support/APInt.cpp | 40 | 
1 files changed, 40 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 61e503bc3a9..07cb057b489 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -1876,6 +1876,17 @@ APInt APInt::udiv(const APInt& RHS) const {    return Quotient;  } +APInt APInt::sdiv(const APInt &RHS) const { +  if (isNegative()) { +    if (RHS.isNegative()) +      return (-(*this)).udiv(-RHS); +    return -((-(*this)).udiv(RHS)); +  } +  if (RHS.isNegative()) +    return -(this->udiv(-RHS)); +  return this->udiv(RHS); +} +  APInt APInt::urem(const APInt& RHS) const {    assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");    if (isSingleWord()) { @@ -1913,6 +1924,17 @@ APInt APInt::urem(const APInt& RHS) const {    return Remainder;  } +APInt APInt::srem(const APInt &RHS) const { +  if (isNegative()) { +    if (RHS.isNegative()) +      return -((-(*this)).urem(-RHS)); +    return -((-(*this)).urem(RHS)); +  } +  if (RHS.isNegative()) +    return this->urem(-RHS); +  return this->urem(RHS); +} +  void APInt::udivrem(const APInt &LHS, const APInt &RHS,                      APInt &Quotient, APInt &Remainder) {    // Get some size facts about the dividend and divisor @@ -1953,6 +1975,24 @@ void APInt::udivrem(const APInt &LHS, const APInt &RHS,    divide(LHS, lhsWords, RHS, rhsWords, &Quotient, &Remainder);  } +void APInt::sdivrem(const APInt &LHS, const APInt &RHS, +                    APInt &Quotient, APInt &Remainder) { +  if (LHS.isNegative()) { +    if (RHS.isNegative()) +      APInt::udivrem(-LHS, -RHS, Quotient, Remainder); +    else { +      APInt::udivrem(-LHS, RHS, Quotient, Remainder); +      Quotient = -Quotient; +    } +    Remainder = -Remainder; +  } else if (RHS.isNegative()) { +    APInt::udivrem(LHS, -RHS, Quotient, Remainder); +    Quotient = -Quotient; +  } else { +    APInt::udivrem(LHS, RHS, Quotient, Remainder); +  } +} +  APInt APInt::sadd_ov(const APInt &RHS, bool &Overflow) const {    APInt Res = *this+RHS;    Overflow = isNonNegative() == RHS.isNonNegative() &&  | 

