First step to fix PR2088. Implement routine to compute the
[oota-llvm.git] / include / llvm / ADT / APInt.h
index 628f860cbab9d663e96263a6aee39e2cd3a6f8f7..c98ff18d1017ee9d5ba91f5da2ed1b9ee59c4757 100644 (file)
@@ -130,7 +130,7 @@ class APInt {
       // 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;
@@ -668,9 +668,11 @@ public:
     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);
@@ -1107,6 +1109,9 @@ public:
     return *this;
   }
 
+  /// @returns the multiplicative inverse for a given modulo.
+  APInt multiplicativeInverse(const APInt& modulo) const;
+
   /// @}
   /// @name Building-block Operations for APInt and APFloat
   /// @{
@@ -1280,7 +1285,8 @@ inline bool isSignedIntN(uint32_t N, const APInt& APIVal) {
 /// @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
@@ -1300,7 +1306,7 @@ inline uint32_t logBase2(const APInt& APIVal) {
 }
 
 /// 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);