summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/BitVector.h
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-03-02 02:31:37 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-03-02 02:31:37 +0000
commit0eca22af62c1e1500b1a937ccdec6d5ffe6ecd8a (patch)
tree5a3b44d808c424a9bf19cf10dc58abadaf3bccb0 /include/llvm/ADT/BitVector.h
parent9bf94a4a9f1087dd1d418af59e8f76e9a85f655e (diff)
downloadllvm-0eca22af62c1e1500b1a937ccdec6d5ffe6ecd8a.tar.gz
llvm-0eca22af62c1e1500b1a937ccdec6d5ffe6ecd8a.tar.bz2
llvm-0eca22af62c1e1500b1a937ccdec6d5ffe6ecd8a.tar.xz
Make it 64-bit safe.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34829 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/BitVector.h')
-rw-r--r--include/llvm/ADT/BitVector.h32
1 files changed, 25 insertions, 7 deletions
diff --git a/include/llvm/ADT/BitVector.h b/include/llvm/ADT/BitVector.h
index 269621313f..2b0e127265 100644
--- a/include/llvm/ADT/BitVector.h
+++ b/include/llvm/ADT/BitVector.h
@@ -120,8 +120,14 @@ public:
/// of the bits are set.
int find_first() const {
for (unsigned i = 0; i < NumBitWords(size()); ++i)
- if (Bits[i] != 0)
- return i * BITS_PER_WORD + CountTrailingZeros_32(Bits[i]);
+ if (Bits[i] != 0) {
+ if (sizeof(BitWord) == 4)
+ return i * BITS_PER_WORD + CountTrailingZeros_32(Bits[i]);
+ else if (sizeof(BitWord) == 8)
+ return i * BITS_PER_WORD + CountTrailingZeros_64(Bits[i]);
+ else
+ assert(0 && "Unsupported!");
+ }
return -1;
}
@@ -136,15 +142,27 @@ public:
unsigned BitPos = Prev % BITS_PER_WORD;
BitWord Copy = Bits[WordPos];
// Mask off previous bits.
- Copy &= ~0 << BitPos;
+ Copy &= ~0L << BitPos;
- if (Copy != 0)
- return WordPos * BITS_PER_WORD + CountTrailingZeros_32(Copy);
+ if (Copy != 0) {
+ if (sizeof(BitWord) == 4)
+ return WordPos * BITS_PER_WORD + CountTrailingZeros_32(Copy);
+ else if (sizeof(BitWord) == 8)
+ return WordPos * BITS_PER_WORD + CountTrailingZeros_64(Copy);
+ else
+ assert(0 && "Unsupported!");
+ }
// Check subsequent words.
for (unsigned i = WordPos+1; i < NumBitWords(size()); ++i)
- if (Bits[i] != 0)
- return i * BITS_PER_WORD + CountTrailingZeros_32(Bits[i]);
+ if (Bits[i] != 0) {
+ if (sizeof(BitWord) == 4)
+ return i * BITS_PER_WORD + CountTrailingZeros_32(Bits[i]);
+ else if (sizeof(BitWord) == 8)
+ return i * BITS_PER_WORD + CountTrailingZeros_64(Bits[i]);
+ else
+ assert(0 && "Unsupported!");
+ }
return -1;
}