summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/ADT/APInt.h18
-rw-r--r--llvm/lib/Support/APInt.cpp9
2 files changed, 18 insertions, 9 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index ef9c66d2d70..0482e3a44bd 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/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/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index e9716e3b1e8..c558ddd8216 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/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)
OpenPOWER on IntegriCloud