diff options
author | Dan Gohman <gohman@apple.com> | 2008-02-13 21:11:05 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2008-02-13 21:11:05 +0000 |
commit | 42dd77f20702d5ca1e0f3882ad74e7a02fc9589c (patch) | |
tree | cf6d98a99a0f295b59c917372e31fc8511a4598e /lib/Support/APInt.cpp | |
parent | b5cfaaedbea10d8fcf5ca23be7955ca0f4fd5c9c (diff) |
Add countTrailingOnes member functions to APInt.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47086 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/APInt.cpp')
-rw-r--r-- | lib/Support/APInt.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 88f32810d6..c8482e9c71 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -813,6 +813,18 @@ uint32_t APInt::countTrailingZeros() const { return std::min(Count, BitWidth); } +uint32_t APInt::countTrailingOnes() const { + if (isSingleWord()) + return std::min(uint32_t(CountTrailingOnes_64(VAL)), BitWidth); + uint32_t Count = 0; + uint32_t i = 0; + for (; i < getNumWords() && pVal[i] == -1; ++i) + Count += APINT_BITS_PER_WORD; + if (i < getNumWords()) + Count += CountTrailingOnes_64(pVal[i]); + return std::min(Count, BitWidth); +} + uint32_t APInt::countPopulation() const { if (isSingleWord()) return CountPopulation_64(VAL); |