summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-02-13 21:11:05 +0000
committerDan Gohman <gohman@apple.com>2008-02-13 21:11:05 +0000
commit8b4fa9dc0a32131c048deef5561c2fdff8e25d4c (patch)
tree05e550dcda78222f3feff5a0b37b36b7a0e4f0ff /llvm/lib/Support
parent5d6c211b89fe178ad1e437f2d3058debf308c393 (diff)
downloadbcm5719-llvm-8b4fa9dc0a32131c048deef5561c2fdff8e25d4c.tar.gz
bcm5719-llvm-8b4fa9dc0a32131c048deef5561c2fdff8e25d4c.zip
Add countTrailingOnes member functions to APInt.
llvm-svn: 47086
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/APInt.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 88f32810d67..c8482e9c719 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/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);
OpenPOWER on IntegriCloud