[llvm-commits] [llvm] r156760 - in /llvm/trunk: include/llvm/ADT/BitVector.h unittests/ADT/BitVectorTest.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Mon May 14 08:01:19 PDT 2012
Author: stoklund
Date: Mon May 14 10:01:19 2012
New Revision: 156760
URL: http://llvm.org/viewvc/llvm-project?rev=156760&view=rev
Log:
Add BitVector::anyCommon().
The existing operation (A & B).any() is very slow.
Modified:
llvm/trunk/include/llvm/ADT/BitVector.h
llvm/trunk/unittests/ADT/BitVectorTest.cpp
Modified: llvm/trunk/include/llvm/ADT/BitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/BitVector.h?rev=156760&r1=156759&r2=156760&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/BitVector.h (original)
+++ llvm/trunk/include/llvm/ADT/BitVector.h Mon May 14 10:01:19 2012
@@ -272,6 +272,16 @@
return (*this)[Idx];
}
+ /// Test if any common bits are set.
+ bool anyCommon(const BitVector &RHS) const {
+ unsigned ThisWords = NumBitWords(size());
+ unsigned RHSWords = NumBitWords(RHS.size());
+ for (unsigned i = 0, e = std::min(ThisWords, RHSWords); i != e; ++i)
+ if (Bits[i] & RHS.Bits[i])
+ return true;
+ return false;
+ }
+
// Comparison operators.
bool operator==(const BitVector &RHS) const {
unsigned ThisWords = NumBitWords(size());
Modified: llvm/trunk/unittests/ADT/BitVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/BitVectorTest.cpp?rev=156760&r1=156759&r2=156760&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/BitVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/BitVectorTest.cpp Mon May 14 10:01:19 2012
@@ -242,6 +242,34 @@
A.clearBitsNotInMask(Mask1, 1);
EXPECT_EQ(64-4u, A.count());
}
-}
+TEST(BitVectorTest, BinOps) {
+ BitVector A;
+ BitVector B;
+
+ A.resize(65);
+ EXPECT_FALSE(A.anyCommon(B));
+ EXPECT_FALSE(B.anyCommon(B));
+
+ B.resize(64);
+ A.set(64);
+ EXPECT_FALSE(A.anyCommon(B));
+ EXPECT_FALSE(B.anyCommon(A));
+
+ B.set(63);
+ EXPECT_FALSE(A.anyCommon(B));
+ EXPECT_FALSE(B.anyCommon(A));
+
+ A.set(63);
+ EXPECT_TRUE(A.anyCommon(B));
+ EXPECT_TRUE(B.anyCommon(A));
+
+ B.resize(70);
+ B.set(64);
+ B.reset(63);
+ A.resize(64);
+ EXPECT_FALSE(A.anyCommon(B));
+ EXPECT_FALSE(B.anyCommon(A));
+}
+}
#endif
More information about the llvm-commits
mailing list