[llvm-commits] [llvm] r102712 - in /llvm/trunk: include/llvm/ADT/SmallBitVector.h unittests/ADT/SmallBitVectorTest.cpp
Benjamin Kramer
benny.kra at googlemail.com
Fri Apr 30 06:40:28 PDT 2010
Author: d0k
Date: Fri Apr 30 08:40:27 2010
New Revision: 102712
URL: http://llvm.org/viewvc/llvm-project?rev=102712&view=rev
Log:
SmallBitVector: Rework find_first/find_next and tweak test to test them (at least on 64 bit platforms).
Modified:
llvm/trunk/include/llvm/ADT/SmallBitVector.h
llvm/trunk/unittests/ADT/SmallBitVectorTest.cpp
Modified: llvm/trunk/include/llvm/ADT/SmallBitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallBitVector.h?rev=102712&r1=102711&r2=102712&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallBitVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallBitVector.h Fri Apr 30 08:40:27 2010
@@ -199,13 +199,12 @@
int find_first() const {
if (isSmall()) {
uintptr_t Bits = getSmallBits();
- if (sizeof(uintptr_t) * CHAR_BIT == 32) {
- size_t FirstBit = CountTrailingZeros_32(Bits);
- return FirstBit == 32 ? -1 : FirstBit;
- } else if (sizeof(uintptr_t) * CHAR_BIT == 64) {
- size_t FirstBit = CountTrailingZeros_64(Bits);
- return FirstBit == 64 ? -1 : FirstBit;
- }
+ if (Bits == 0)
+ return -1;
+ if (sizeof(uintptr_t) * CHAR_BIT == 32)
+ return CountTrailingZeros_32(Bits);
+ if (sizeof(uintptr_t) * CHAR_BIT == 64)
+ return CountTrailingZeros_64(Bits);
assert(0 && "Unsupported!");
}
return getPointer()->find_first();
@@ -218,13 +217,12 @@
uintptr_t Bits = getSmallBits();
// Mask off previous bits.
Bits &= ~uintptr_t(0) << (Prev + 1);
- if (sizeof(uintptr_t) * CHAR_BIT == 32) {
- size_t FirstBit = CountTrailingZeros_32(Bits);
- return FirstBit == 32 ? -1 : FirstBit;
- } else if (sizeof(uintptr_t) * CHAR_BIT == 64) {
- size_t FirstBit = CountTrailingZeros_64(Bits);
- return FirstBit == 64 ? -1 : FirstBit;
- }
+ if (Bits == 0 || Prev + 1 >= getSmallSize())
+ return -1;
+ if (sizeof(uintptr_t) * CHAR_BIT == 32)
+ return CountTrailingZeros_32(Bits);
+ if (sizeof(uintptr_t) * CHAR_BIT == 64)
+ return CountTrailingZeros_64(Bits);
assert(0 && "Unsupported!");
}
return getPointer()->find_next(Prev);
Modified: llvm/trunk/unittests/ADT/SmallBitVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/SmallBitVectorTest.cpp?rev=102712&r1=102711&r2=102712&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/SmallBitVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/SmallBitVectorTest.cpp Fri Apr 30 08:40:27 2010
@@ -55,7 +55,7 @@
Vec.resize(26, true);
Vec.resize(29, false);
Vec.resize(33, true);
- Vec.resize(61, false);
+ Vec.resize(57, false);
unsigned Count = 0;
for (unsigned i = Vec.find_first(); i != -1u; i = Vec.find_next(i)) {
++Count;
@@ -66,7 +66,8 @@
EXPECT_EQ(Count, 23u);
EXPECT_FALSE(Vec[0]);
EXPECT_TRUE(Vec[32]);
- EXPECT_FALSE(Vec[60]);
+ EXPECT_FALSE(Vec[56]);
+ Vec.resize(61, false);
SmallBitVector Copy = Vec;
SmallBitVector Alt(3, false);
More information about the llvm-commits
mailing list