From: Craig Topper Date: Wed, 20 Sep 2017 18:49:31 +0000 (+0000) Subject: [APInt] Use getActiveBits() to implement logBase2 and ceilLogBase2. NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=686e2d6ca3c8af84017a74c53b5059504b73feea;p=llvm [APInt] Use getActiveBits() to implement logBase2 and ceilLogBase2. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313793 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index a1cce6e5fe1..c81363cc16b 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -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.