[llvm] r186123 - Sync SmallBitVector with BitVector. Add unit tests for the missing methods.
Benjamin Kramer
benny.kra at googlemail.com
Thu Jul 11 14:59:16 PDT 2013
Author: d0k
Date: Thu Jul 11 16:59:16 2013
New Revision: 186123
URL: http://llvm.org/viewvc/llvm-project?rev=186123&view=rev
Log:
Sync SmallBitVector with BitVector. Add unit tests for the missing methods.
Modified:
llvm/trunk/include/llvm/ADT/SmallBitVector.h
llvm/trunk/unittests/ADT/BitVectorTest.cpp
Modified: llvm/trunk/include/llvm/ADT/SmallBitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallBitVector.h?rev=186123&r1=186122&r2=186123&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallBitVector.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallBitVector.h Thu Jul 11 16:59:16 2013
@@ -426,6 +426,40 @@ public:
return *this;
}
+ /// reset - Reset bits that are set in RHS. Same as *this &= ~RHS.
+ SmallBitVector &reset(const SmallBitVector &RHS) {
+ if (isSmall() && RHS.isSmall())
+ setSmallBits(getSmallBits() & ~RHS.getSmallBits());
+ else if (!isSmall() && !RHS.isSmall())
+ getPointer()->reset(*RHS.getPointer());
+ else
+ for (unsigned i = 0, e = std::min(size(), RHS.size()); i != e; ++i)
+ if (RHS.test(i))
+ reset(i);
+
+ return *this;
+ }
+
+ /// test - Check if (This - RHS) is zero.
+ /// This is the same as reset(RHS) and any().
+ bool test(const SmallBitVector &RHS) const {
+ if (isSmall() && RHS.isSmall())
+ return (getSmallBits() & ~RHS.getSmallBits()) != 0;
+ if (!isSmall() && !RHS.isSmall())
+ return getPointer()->test(*RHS.getPointer());
+
+ unsigned i, e;
+ for (i = 0, e = std::min(size(), RHS.size()); i != e; ++i)
+ if (test(i) && !RHS.test(i))
+ return true;
+
+ for (e = size(); i != e; ++i)
+ if (test(i))
+ return true;
+
+ return false;
+ }
+
SmallBitVector &operator|=(const SmallBitVector &RHS) {
resize(std::max(size(), RHS.size()));
if (isSmall())
Modified: llvm/trunk/unittests/ADT/BitVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/BitVectorTest.cpp?rev=186123&r1=186122&r2=186123&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/BitVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/BitVectorTest.cpp Thu Jul 11 16:59:16 2013
@@ -357,5 +357,41 @@ TYPED_TEST(BitVectorTest, RangeOps) {
EXPECT_TRUE( E.test(32));
EXPECT_FALSE(E.test(33));
}
+
+TYPED_TEST(BitVectorTest, CompoundTestReset) {
+ TypeParam A(50, true);
+ TypeParam B(50, false);
+
+ TypeParam C(100, true);
+ TypeParam D(100, false);
+
+ EXPECT_FALSE(A.test(A));
+ EXPECT_TRUE(A.test(B));
+ EXPECT_FALSE(A.test(C));
+ EXPECT_TRUE(A.test(D));
+ EXPECT_FALSE(B.test(A));
+ EXPECT_FALSE(B.test(B));
+ EXPECT_FALSE(B.test(C));
+ EXPECT_FALSE(B.test(D));
+ EXPECT_TRUE(C.test(A));
+ EXPECT_TRUE(C.test(B));
+ EXPECT_FALSE(C.test(C));
+ EXPECT_TRUE(C.test(D));
+
+ A.reset(B);
+ A.reset(D);
+ EXPECT_TRUE(A.all());
+ A.reset(A);
+ EXPECT_TRUE(A.none());
+ A.set();
+ A.reset(C);
+ EXPECT_TRUE(A.none());
+ A.set();
+
+ C.reset(A);
+ EXPECT_EQ(50, C.find_first());
+ C.reset(C);
+ EXPECT_TRUE(C.none());
+}
}
#endif
More information about the llvm-commits
mailing list