mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-23 17:24:48 +00:00
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
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user