[llvm] r313793 - [APInt] Use getActiveBits() to implement logBase2 and ceilLogBase2. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 20 11:49:31 PDT 2017


Author: ctopper
Date: Wed Sep 20 11:49:31 2017
New Revision: 313793

URL: http://llvm.org/viewvc/llvm-project?rev=313793&view=rev
Log:
[APInt] Use getActiveBits() to implement logBase2 and ceilLogBase2. NFC

Modified:
    llvm/trunk/include/llvm/ADT/APInt.h

Modified: llvm/trunk/include/llvm/ADT/APInt.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APInt.h?rev=313793&r1=313792&r2=313793&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h (original)
+++ llvm/trunk/include/llvm/ADT/APInt.h Wed Sep 20 11:49:31 2017
@@ -1724,13 +1724,13 @@ public:
   /// @{
 
   /// \returns the floor log base 2 of this APInt.
-  unsigned logBase2() const { return BitWidth - 1 - countLeadingZeros(); }
+  unsigned logBase2() const { return getActiveBits() -  1; }
 
   /// \returns the ceil log base 2 of this APInt.
   unsigned ceilLogBase2() const {
     APInt temp(*this);
     --temp;
-    return BitWidth - temp.countLeadingZeros();
+    return temp.getActiveBits();
   }
 
   /// \returns the nearest log base 2 of this APInt. Ties round up.




More information about the llvm-commits mailing list