fix a comment bug Reid noticed
[oota-llvm.git] / include / llvm / ADT / APInt.h
index 8f3b2f6a6d4421683a3925b2b4d8cbc78e82df83..d9470ee3c80a4d52de4a179141b34371b504afea 100644 (file)
@@ -272,10 +272,21 @@ public:
   /// @returns true if the argument APInt value is a power of two > 0.
   bool isPowerOf2() const; 
 
-  /// This converts the APInt to a boolean valy as a test against zero.
+  /// isSignBit - Return true if this is the value returned by getSignBit.
+  bool isSignBit() const { return isMinSignedValue(); }
+  
+  /// This converts the APInt to a boolean value as a test against zero.
   /// @brief Boolean conversion function. 
   inline bool getBoolValue() const {
-    return countLeadingZeros() != BitWidth;
+    return *this != 0;
+  }
+
+  /// getLimitedValue - If this value is smaller than the specified limit,
+  /// return it, otherwise return the limit value.  This causes the value
+  /// to saturate to the limit.
+  uint64_t getLimitedValue(uint64_t Limit = ~0ULL) const {
+    return (getActiveBits() > 64 || getZExtValue() > Limit) ?
+      Limit :  getZExtValue();
   }
 
   /// @}
@@ -355,7 +366,9 @@ public:
   /// @brief Get a value with high bits set
   static APInt getHighBitsSet(uint32_t numBits, uint32_t hiBitsSet) {
     assert(hiBitsSet <= numBits && "Too many bits to set!");
-    assert(hiBitsSet > 0 && "You must set SOME bits");
+    // Handle a degenerate case, to avoid shifting by word size
+    if (hiBitsSet == 0)
+      return APInt(numBits, 0);
     uint32_t shiftAmt = numBits - hiBitsSet;
     // For small values, return quickly
     if (numBits <= APINT_BITS_PER_WORD)
@@ -369,12 +382,15 @@ public:
   /// @brief Get a value with low bits set
   static APInt getLowBitsSet(uint32_t numBits, uint32_t loBitsSet) {
     assert(loBitsSet <= numBits && "Too many bits to set!");
-    assert(loBitsSet > 0 && "You must set SOME bits");
-    uint32_t shiftAmt = numBits - loBitsSet;
+    // Handle a degenerate case, to avoid shifting by word size
+    if (loBitsSet == 0)
+      return APInt(numBits, 0);
+    if (loBitsSet == APINT_BITS_PER_WORD)
+      return APInt(numBits, -1ULL);
     // For small values, return quickly
-    if (numBits <= APINT_BITS_PER_WORD)
-      return APInt(numBits, ~0ULL >> shiftAmt);
-    return (~APInt(numBits, 0)).lshr(shiftAmt);
+    if (numBits < APINT_BITS_PER_WORD)
+      return APInt(numBits, (1ULL << loBitsSet) - 1);
+    return (~APInt(numBits, 0)).lshr(numBits - loBitsSet);
   }
 
   /// The hash value is computed as the sum of the words and the bit width.
@@ -391,15 +407,6 @@ public:
     return &pVal[0];
   }
 
-  /// @brief Set a sepcific word in the value to a new value.
-  inline void setWordToValue(uint32_t idx, uint64_t Val) {
-    assert(idx < getNumWords() && "Invalid word array index");
-    if (isSingleWord())
-      VAL = Val;
-    else
-      pVal[idx] = Val;
-  }
-
   /// @}
   /// @name Unary Operators
   /// @{
@@ -543,6 +550,10 @@ public:
   APInt operator-(uint64_t RHS) const {
     return (*this) - APInt(BitWidth, RHS);
   }
+  
+  APInt operator<<(unsigned Bits) const {
+    return shl(Bits);
+  }
 
   /// Arithmetic right-shift this APInt by shiftAmt.
   /// @brief Arithmetic right-shift function.
@@ -722,7 +733,7 @@ public:
   /// @brief Sign extend to a new width.
   APInt &sext(uint32_t width);
 
-  /// This operation zero extends the APInt to a new width. Thie high order bits
+  /// This operation zero extends the APInt to a new width. The high order bits
   /// are filled with 0 bits.  It is an error to specify a width that is less 
   /// than or equal to the current width.
   /// @brief Zero extend to a new width.
@@ -738,15 +749,6 @@ public:
   /// @brief Zero extend or truncate to width
   APInt &zextOrTrunc(uint32_t width);
 
-  /// This is a help function for convenience. If the given \p width equals to
-  /// this APInt's BitWidth, just return this APInt, otherwise, just zero 
-  /// extend it.
-  inline APInt &zextOrCopy(uint32_t width) {
-    if (width == BitWidth)
-      return *this;
-    return zext(width);
-  }
-
   /// @}
   /// @name Bit Manipulation Operators
   /// @{