]> granicus.if.org Git - llvm/commitdiff
[APInt] Move the single word cases of countTrailingZeros and countLeadingOnes inline...
authorCraig Topper <craig.topper@intel.com>
Fri, 23 Jun 2017 20:28:45 +0000 (20:28 +0000)
committerCraig Topper <craig.topper@intel.com>
Fri, 23 Jun 2017 20:28:45 +0000 (20:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306153 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/APInt.h
lib/Support/APInt.cpp

index ef9c66d2d700bfe744fc0989792fdc643a823f5e..0482e3a44bd1f8f7660ccab870678eff3ff56a5e 100644 (file)
@@ -213,6 +213,12 @@ private:
   /// out-of-line slow case for countLeadingZeros
   unsigned countLeadingZerosSlowCase() const LLVM_READONLY;
 
+  /// out-of-line slow case for countLeadingOnes.
+  unsigned countLeadingOnesSlowCase() const LLVM_READONLY;
+
+  /// out-of-line slow case for countTrailingZeros.
+  unsigned countTrailingZerosSlowCase() const LLVM_READONLY;
+
   /// out-of-line slow case for countTrailingOnes
   unsigned countTrailingOnesSlowCase() const LLVM_READONLY;
 
@@ -1574,7 +1580,11 @@ public:
   ///
   /// \returns 0 if the high order bit is not set, otherwise returns the number
   /// of 1 bits from the most significant to the least
-  unsigned countLeadingOnes() const LLVM_READONLY;
+  unsigned countLeadingOnes() const {
+    if (isSingleWord())
+      return llvm::countLeadingOnes(U.VAL << (APINT_BITS_PER_WORD - BitWidth));
+    return countLeadingOnesSlowCase();
+  }
 
   /// Computes the number of leading bits of this APInt that are equal to its
   /// sign bit.
@@ -1590,7 +1600,11 @@ public:
   ///
   /// \returns BitWidth if the value is zero, otherwise returns the number of
   /// zeros from the least significant bit to the first one bit.
-  unsigned countTrailingZeros() const LLVM_READONLY;
+  unsigned countTrailingZeros() const {
+    if (isSingleWord())
+      return std::min(unsigned(llvm::countTrailingZeros(U.VAL)), BitWidth);
+    return countTrailingZerosSlowCase();
+  }
 
   /// \brief Count the number of trailing one bits.
   ///
index e9716e3b1e872b3d34df9b5dc352018e76dbb4f2..c558ddd82161d68c3dfe37ab3cb89276c8bc5890 100644 (file)
@@ -546,10 +546,7 @@ unsigned APInt::countLeadingZerosSlowCase() const {
   return Count;
 }
 
-unsigned APInt::countLeadingOnes() const {
-  if (isSingleWord())
-    return llvm::countLeadingOnes(U.VAL << (APINT_BITS_PER_WORD - BitWidth));
-
+unsigned APInt::countLeadingOnesSlowCase() const {
   unsigned highWordBits = BitWidth % APINT_BITS_PER_WORD;
   unsigned shift;
   if (!highWordBits) {
@@ -573,9 +570,7 @@ unsigned APInt::countLeadingOnes() const {
   return Count;
 }
 
-unsigned APInt::countTrailingZeros() const {
-  if (isSingleWord())
-    return std::min(unsigned(llvm::countTrailingZeros(U.VAL)), BitWidth);
+unsigned APInt::countTrailingZerosSlowCase() const {
   unsigned Count = 0;
   unsigned i = 0;
   for (; i < getNumWords() && U.pVal[i] == 0; ++i)