[llvm-commits] CVS: llvm/include/llvm/ADT/APInt.h

Reid Spencer reid at x10sys.com
Tue Feb 27 13:59:47 PST 2007



Changes in directory llvm/include/llvm/ADT:

APInt.h updated: 1.26 -> 1.27
---
Log message:

Implement countLeadingOnes() and getMinSignedBits(). This helps to minimize
the bit width of negative numbers by computing the minimum bit width for a
negative value. E.g. 0x1800000000000000 could be just 0x8000000000000000


---
Diffs of the changes:  (+14 -1)

 APInt.h |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletion(-)


Index: llvm/include/llvm/ADT/APInt.h
diff -u llvm/include/llvm/ADT/APInt.h:1.26 llvm/include/llvm/ADT/APInt.h:1.27
--- llvm/include/llvm/ADT/APInt.h:1.26	Tue Feb 27 14:24:31 2007
+++ llvm/include/llvm/ADT/APInt.h	Tue Feb 27 15:59:26 2007
@@ -446,6 +446,12 @@
     return BitWidth - countLeadingZeros();
   }
 
+  inline uint32_t getMinSignedBits() const {
+    if (isNegative())
+      return BitWidth - countLeadingOnes() + 1;
+    return getActiveBits();
+  }
+
   /// This method attempts to return the value of this APInt as a zero extended
   /// uint64_t. The bitwidth must be <= 64 or the value must fit within a
   /// uint64_t. Otherwise an assertion will result.
@@ -587,9 +593,16 @@
   /// @returns getNumWords() * APINT_BITS_PER_WORD if the value is zero.
   /// @returns the number of zeros from the most significant bit to the first
   /// one bits.
-  /// @brief Count the number of trailing one bits.
+  /// @brief Count the number of leading one bits.
   uint32_t countLeadingZeros() const;
 
+  /// countLeadingOnes - This function counts the number of contiguous 1 bits
+  /// in the high order bits. The count stops when the first 0 bit is reached.
+  /// @returns 0 if the high order bit is not set
+  /// @returns the number of 1 bits from the most significant to the least
+  /// @brief Count the number of leading one bits.
+  uint32_t countLeadingOnes() const;
+
   /// countTrailingZeros - This function is an APInt version of the 
   /// countTrailingZoers_{32,64} functions in MathExtras.h. It counts 
   /// the number of zeros from the least significant bit to the first one bit.






More information about the llvm-commits mailing list