From: Craig Topper Date: Fri, 23 Jun 2017 20:28:45 +0000 (+0000) Subject: [APInt] Move the single word cases of countTrailingZeros and countLeadingOnes inline... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7584e452e62e9ec9aaaa551224560cbf6ddba9ea;p=llvm [APInt] Move the single word cases of countTrailingZeros and countLeadingOnes inline for consistency with countTrailingOnes and countLeadingZeros. NFCI git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306153 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index ef9c66d2d70..0482e3a44bd 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -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. /// diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index e9716e3b1e8..c558ddd8216 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -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)