// the word size (64).
return *this;
- // Mask out the hight bits.
+ // Mask out the high bits.
uint64_t mask = ~uint64_t(0ULL) >> (APINT_BITS_PER_WORD - wordBits);
if (isSingleWord())
VAL &= mask;
return this->urem(RHS);
}
- /// Sometimes it is convenient to divide two APInt values and obtain both
- /// the quotient and remainder. This function does both operations in the
- /// same computation making it a little more efficient.
+ /// Sometimes it is convenient to divide two APInt values and obtain both the
+ /// quotient and remainder. This function does both operations in the same
+ /// computation making it a little more efficient. The pair of input arguments
+ /// may overlap with the pair of output arguments. It is safe to call
+ /// udivrem(X, Y, X, Y), for example.
/// @brief Dual division/remainder interface.
static void udivrem(const APInt &LHS, const APInt &RHS,
APInt &Quotient, APInt &Remainder);
return *this;
}
+ /// @returns the multiplicative inverse for a given modulo.
+ APInt multiplicativeInverse(const APInt& modulo) const;
+
/// @}
/// @name Building-block Operations for APInt and APFloat
/// @{
/// @returns true if the argument APInt value is a sequence of ones
/// starting at the least significant bit with the remainder zero.
inline bool isMask(uint32_t numBits, const APInt& APIVal) {
- return APIVal.getBoolValue() && ((APIVal + APInt(numBits,1)) & APIVal) == 0;
+ return numBits <= APIVal.getBitWidth() &&
+ APIVal == APInt::getLowBitsSet(APIVal.getBitWidth(), numBits);
}
/// @returns true if the argument APInt value contains a sequence of ones
}
/// GreatestCommonDivisor - This function returns the greatest common
-/// divisor of the two APInt values using Enclid's algorithm.
+/// divisor of the two APInt values using Euclid's algorithm.
/// @returns the greatest common divisor of Val1 and Val2
/// @brief Compute GCD of two APInt values.
APInt GreatestCommonDivisor(const APInt& Val1, const APInt& Val2);