mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-28 14:36:34 +00:00
Implement operators |=, &=, and ^= for SmallBitVector, and remove the
restriction in BitVector for |= and ^= that the operand must be the same length. llvm-svn: 95768
This commit is contained in:
parent
d2035fb242
commit
2dd0d36f14
@ -307,15 +307,17 @@ public:
|
||||
}
|
||||
|
||||
BitVector &operator|=(const BitVector &RHS) {
|
||||
assert(Size == RHS.Size && "Illegal operation!");
|
||||
for (unsigned i = 0; i < NumBitWords(size()); ++i)
|
||||
if (size() < RHS.size())
|
||||
resize(RHS.size());
|
||||
for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; ++i)
|
||||
Bits[i] |= RHS.Bits[i];
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitVector &operator^=(const BitVector &RHS) {
|
||||
assert(Size == RHS.Size && "Illegal operation!");
|
||||
for (unsigned i = 0; i < NumBitWords(size()); ++i)
|
||||
if (size() < RHS.size())
|
||||
resize(RHS.size());
|
||||
for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; ++i)
|
||||
Bits[i] ^= RHS.Bits[i];
|
||||
return *this;
|
||||
}
|
||||
|
@ -310,11 +310,47 @@ public:
|
||||
}
|
||||
|
||||
// Intersection, union, disjoint union.
|
||||
BitVector &operator&=(const SmallBitVector &RHS); // TODO: implement
|
||||
SmallBitVector &operator&=(const SmallBitVector &RHS) {
|
||||
resize(std::max(size(), RHS.size()));
|
||||
if (isSmall())
|
||||
setSmallBits(getSmallBits() & RHS.getSmallBits());
|
||||
else if (!RHS.isSmall())
|
||||
X.getPointer()->operator&=(*RHS.X.getPointer());
|
||||
else {
|
||||
SmallBitVector Copy = RHS;
|
||||
Copy.resize(size());
|
||||
X.getPointer()->operator&=(*Copy.X.getPointer());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitVector &operator|=(const SmallBitVector &RHS); // TODO: implement
|
||||
SmallBitVector &operator|=(const SmallBitVector &RHS) {
|
||||
resize(std::max(size(), RHS.size()));
|
||||
if (isSmall())
|
||||
setSmallBits(getSmallBits() | RHS.getSmallBits());
|
||||
else if (!RHS.isSmall())
|
||||
X.getPointer()->operator|=(*RHS.X.getPointer());
|
||||
else {
|
||||
SmallBitVector Copy = RHS;
|
||||
Copy.resize(size());
|
||||
X.getPointer()->operator|=(*Copy.X.getPointer());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
BitVector &operator^=(const SmallBitVector &RHS); // TODO: implement
|
||||
SmallBitVector &operator^=(const SmallBitVector &RHS) {
|
||||
resize(std::max(size(), RHS.size()));
|
||||
if (isSmall())
|
||||
setSmallBits(getSmallBits() ^ RHS.getSmallBits());
|
||||
else if (!RHS.isSmall())
|
||||
X.getPointer()->operator^=(*RHS.X.getPointer());
|
||||
else {
|
||||
SmallBitVector Copy = RHS;
|
||||
Copy.resize(size());
|
||||
X.getPointer()->operator^=(*Copy.X.getPointer());
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Assignment operator.
|
||||
const SmallBitVector &operator=(const SmallBitVector &RHS) {
|
||||
|
@ -138,5 +138,45 @@ TEST(BitVectorTest, TrivialOperation) {
|
||||
EXPECT_TRUE(Vec.empty());
|
||||
}
|
||||
|
||||
TEST(BitVectorTest, CompoundAssignment) {
|
||||
BitVector A;
|
||||
A.resize(10);
|
||||
A.set(4);
|
||||
A.set(7);
|
||||
|
||||
BitVector B;
|
||||
B.resize(50);
|
||||
B.set(5);
|
||||
B.set(18);
|
||||
|
||||
A |= B;
|
||||
EXPECT_TRUE(A.test(4));
|
||||
EXPECT_TRUE(A.test(5));
|
||||
EXPECT_TRUE(A.test(7));
|
||||
EXPECT_TRUE(A.test(18));
|
||||
EXPECT_EQ(A.count(), 4);
|
||||
EXPECT_EQ(A.size(), 50);
|
||||
|
||||
B.resize(10);
|
||||
B.set();
|
||||
B.reset(2);
|
||||
B.reset(7);
|
||||
A &= B;
|
||||
EXPECT_FALSE(A.test(2));
|
||||
EXPECT_FALSE(A.test(7));
|
||||
EXPECT_EQ(A.size(), 50);
|
||||
EXPECT_EQ(A.count(), 2);
|
||||
|
||||
B.resize(100);
|
||||
B.set();
|
||||
|
||||
A ^= B;
|
||||
EXPECT_TRUE(A.test(2));
|
||||
EXPECT_TRUE(A.test(7));
|
||||
EXPECT_EQ(A.size(), 100);
|
||||
EXPECT_EQ(A.count(), 98);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -137,4 +137,43 @@ TEST(SmallBitVectorTest, TrivialOperation) {
|
||||
EXPECT_TRUE(Vec.empty());
|
||||
}
|
||||
|
||||
TEST(SmallBitVectorTest, CompoundAssignment) {
|
||||
SmallBitVector A;
|
||||
A.resize(10);
|
||||
A.set(4);
|
||||
A.set(7);
|
||||
|
||||
SmallBitVector B;
|
||||
B.resize(50);
|
||||
B.set(5);
|
||||
B.set(18);
|
||||
|
||||
A |= B;
|
||||
EXPECT_TRUE(A.test(4));
|
||||
EXPECT_TRUE(A.test(5));
|
||||
EXPECT_TRUE(A.test(7));
|
||||
EXPECT_TRUE(A.test(18));
|
||||
EXPECT_EQ(A.count(), 4);
|
||||
EXPECT_EQ(A.size(), 50);
|
||||
|
||||
B.resize(10);
|
||||
B.set();
|
||||
B.reset(2);
|
||||
B.reset(7);
|
||||
A &= B;
|
||||
EXPECT_FALSE(A.test(2));
|
||||
EXPECT_FALSE(A.test(7));
|
||||
EXPECT_EQ(A.size(), 50);
|
||||
EXPECT_EQ(A.count(), 2);
|
||||
|
||||
B.resize(100);
|
||||
B.set();
|
||||
|
||||
A ^= B;
|
||||
EXPECT_TRUE(A.test(2));
|
||||
EXPECT_TRUE(A.test(7));
|
||||
EXPECT_EQ(A.size(), 100);
|
||||
EXPECT_EQ(A.count(), 98);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user