mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 02:33:33 +00:00
Implement operators |=, &=, and ^= for SmallBitVector, and remove the
restriction in BitVector for |= and ^= that the operand must be the same length. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95768 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5d5a1e13a1
commit
e7962c9897
@ -307,15 +307,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
BitVector &operator|=(const BitVector &RHS) {
|
BitVector &operator|=(const BitVector &RHS) {
|
||||||
assert(Size == RHS.Size && "Illegal operation!");
|
if (size() < RHS.size())
|
||||||
for (unsigned i = 0; i < NumBitWords(size()); ++i)
|
resize(RHS.size());
|
||||||
|
for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; ++i)
|
||||||
Bits[i] |= RHS.Bits[i];
|
Bits[i] |= RHS.Bits[i];
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
BitVector &operator^=(const BitVector &RHS) {
|
BitVector &operator^=(const BitVector &RHS) {
|
||||||
assert(Size == RHS.Size && "Illegal operation!");
|
if (size() < RHS.size())
|
||||||
for (unsigned i = 0; i < NumBitWords(size()); ++i)
|
resize(RHS.size());
|
||||||
|
for (size_t i = 0, e = NumBitWords(RHS.size()); i != e; ++i)
|
||||||
Bits[i] ^= RHS.Bits[i];
|
Bits[i] ^= RHS.Bits[i];
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -310,11 +310,47 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Intersection, union, disjoint union.
|
// 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.
|
// Assignment operator.
|
||||||
const SmallBitVector &operator=(const SmallBitVector &RHS) {
|
const SmallBitVector &operator=(const SmallBitVector &RHS) {
|
||||||
|
@ -138,5 +138,45 @@ TEST(BitVectorTest, TrivialOperation) {
|
|||||||
EXPECT_TRUE(Vec.empty());
|
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
|
#endif
|
||||||
|
@ -137,4 +137,43 @@ TEST(SmallBitVectorTest, TrivialOperation) {
|
|||||||
EXPECT_TRUE(Vec.empty());
|
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…
x
Reference in New Issue
Block a user