diff options
| author | Dan Gohman <djg@cray.com> | 2008-02-13 21:11:05 +0000 |
|---|---|---|
| committer | Dan Gohman <djg@cray.com> | 2008-02-13 21:11:05 +0000 |
| commit | f550d41ede2d857f4805b6c43326892b9f92c875 (patch) | |
| tree | cf6d98a99a0f295b59c917372e31fc8511a4598e /lib/Support | |
| parent | af60e487e80051d4c1fbbd76ede74f08e83e789c (diff) | |
| download | external_llvm-f550d41ede2d857f4805b6c43326892b9f92c875.zip external_llvm-f550d41ede2d857f4805b6c43326892b9f92c875.tar.gz external_llvm-f550d41ede2d857f4805b6c43326892b9f92c875.tar.bz2 | |
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')
| -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 88f3281..c8482e9 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); |
