diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-01-17 01:24:32 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-01-17 01:24:32 +0000 |
commit | ff5bad078782b6472d6cd0974bf08fe3473050e6 (patch) | |
tree | 092e54aeef010151749729a892e0950d00751e13 /unittests/ADT/BitVectorTest.cpp | |
parent | e02a17c4efb843b8627f3d819c62f88a7f2fb457 (diff) |
Add portable bit mask operations to BitVector.
BitVector uses the native word size for its internal representation.
That doesn't work well for literal bit masks in source code.
This patch adds BitVector operations to efficiently apply literal bit
masks specified as arrays of uint32_t. Since each array entry always
holds exactly 32 bits, these portable bit masks can be source code
literals, probably produced by TableGen.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148272 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ADT/BitVectorTest.cpp')
-rw-r--r-- | unittests/ADT/BitVectorTest.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/unittests/ADT/BitVectorTest.cpp b/unittests/ADT/BitVectorTest.cpp index fa663121a8..f733e13fdf 100644 --- a/unittests/ADT/BitVectorTest.cpp +++ b/unittests/ADT/BitVectorTest.cpp @@ -196,6 +196,52 @@ TEST(BitVectorTest, ProxyIndex) { EXPECT_TRUE(Vec.none()); } +TEST(BitVectorTest, PortableBitMask) { + BitVector A; + const uint32_t Mask1[] = { 0x80000000, 6, 5 }; + + A.resize(10); + A.setBitsInMask(Mask1, 3); + EXPECT_EQ(10u, A.size()); + EXPECT_FALSE(A.test(0)); + + A.resize(32); + A.setBitsInMask(Mask1, 3); + EXPECT_FALSE(A.test(0)); + EXPECT_TRUE(A.test(31)); + EXPECT_EQ(1u, A.count()); + + A.resize(33); + A.setBitsInMask(Mask1, 1); + EXPECT_EQ(1u, A.count()); + A.setBitsInMask(Mask1, 2); + EXPECT_EQ(1u, A.count()); + + A.resize(34); + A.setBitsInMask(Mask1, 2); + EXPECT_EQ(2u, A.count()); + + A.resize(65); + A.setBitsInMask(Mask1, 3); + EXPECT_EQ(4u, A.count()); + + A.setBitsNotInMask(Mask1, 1); + EXPECT_EQ(32u+3u, A.count()); + + A.setBitsNotInMask(Mask1, 3); + EXPECT_EQ(65u, A.count()); + + A.resize(96); + EXPECT_EQ(65u, A.count()); + + A.clear(); + A.resize(128); + A.setBitsNotInMask(Mask1, 3); + EXPECT_EQ(96u-5u, A.count()); + + A.clearBitsNotInMask(Mask1, 1); + EXPECT_EQ(64-4u, A.count()); +} } #endif |