mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
BitVector: Do the right thing in all() when Size is a multiple of BITWORD_SIZE.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183525 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -138,16 +138,15 @@ public:
|
|||||||
|
|
||||||
/// all - Returns true if all bits are set.
|
/// all - Returns true if all bits are set.
|
||||||
bool all() const {
|
bool all() const {
|
||||||
if (empty())
|
for (unsigned i = 0; i < Size / BITWORD_SIZE; ++i)
|
||||||
return true;
|
|
||||||
|
|
||||||
for (unsigned i = 0; i < NumBitWords(size()) - 1; ++i)
|
|
||||||
if (Bits[i] != ~0UL)
|
if (Bits[i] != ~0UL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// For the last word check that the lower bits are ones. The unused bits are
|
// If bits remain check that they are ones. The unused bits are always zero.
|
||||||
// always zero.
|
if (unsigned Remainder = Size % BITWORD_SIZE)
|
||||||
return Bits[NumBitWords(size()) - 1] == ~(~0UL << (Size % BITWORD_SIZE));
|
return Bits[Size / BITWORD_SIZE] == (1UL << Remainder) - 1;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// none - Returns true if none of the bits are set.
|
/// none - Returns true if none of the bits are set.
|
||||||
|
@@ -149,6 +149,22 @@ TYPED_TEST(BitVectorTest, TrivialOperation) {
|
|||||||
EXPECT_FALSE(Vec.none());
|
EXPECT_FALSE(Vec.none());
|
||||||
EXPECT_FALSE(Vec.empty());
|
EXPECT_FALSE(Vec.empty());
|
||||||
|
|
||||||
|
Vec.resize(64);
|
||||||
|
EXPECT_EQ(64U, Vec.count());
|
||||||
|
EXPECT_EQ(64U, Vec.size());
|
||||||
|
EXPECT_TRUE(Vec.any());
|
||||||
|
EXPECT_TRUE(Vec.all());
|
||||||
|
EXPECT_FALSE(Vec.none());
|
||||||
|
EXPECT_FALSE(Vec.empty());
|
||||||
|
|
||||||
|
Vec.flip();
|
||||||
|
EXPECT_EQ(0U, Vec.count());
|
||||||
|
EXPECT_EQ(64U, Vec.size());
|
||||||
|
EXPECT_FALSE(Vec.any());
|
||||||
|
EXPECT_FALSE(Vec.all());
|
||||||
|
EXPECT_TRUE(Vec.none());
|
||||||
|
EXPECT_FALSE(Vec.empty());
|
||||||
|
|
||||||
Inv = TypeParam().flip();
|
Inv = TypeParam().flip();
|
||||||
EXPECT_EQ(0U, Inv.count());
|
EXPECT_EQ(0U, Inv.count());
|
||||||
EXPECT_EQ(0U, Inv.size());
|
EXPECT_EQ(0U, Inv.size());
|
||||||
|
Reference in New Issue
Block a user