Optimize angle::BitSetIterator.
Adds a new custom bitset template to handle packing as many bits as
possible into a single variable. Intelligently select the right class
depending on platform features and bit sizes.
For now, always use a packed 64-bit set on 64-bit, instead of using
a 32-bit set for smaller bitsets.
BUG=angleproject:1814
Change-Id: I3ffef815c15515555833f6fc9302d8a4eee5423b
Reviewed-on: https://chromium-review.googlesource.com/471827
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/common/bitset_utils_unittest.cpp b/src/common/bitset_utils_unittest.cpp
index 61eff56..e176c70 100644
--- a/src/common/bitset_utils_unittest.cpp
+++ b/src/common/bitset_utils_unittest.cpp
@@ -18,25 +18,25 @@
class BitSetIteratorTest : public testing::Test
{
protected:
- std::bitset<40> mStateBits;
+ BitSet<40> mStateBits;
};
// Simple iterator test.
TEST_F(BitSetIteratorTest, Iterator)
{
- std::set<unsigned long> originalValues;
+ std::set<size_t> originalValues;
originalValues.insert(2);
originalValues.insert(6);
originalValues.insert(8);
originalValues.insert(35);
- for (unsigned long value : originalValues)
+ for (size_t value : originalValues)
{
mStateBits.set(value);
}
- std::set<unsigned long> readValues;
- for (unsigned long bit : IterateBitSet(mStateBits))
+ std::set<size_t> readValues;
+ for (size_t bit : mStateBits)
{
EXPECT_EQ(1u, originalValues.count(bit));
EXPECT_EQ(0u, readValues.count(bit));
@@ -52,7 +52,7 @@
// We don't use the FAIL gtest macro here since it returns immediately,
// causing an unreachable code warning in MSVS
bool sawBit = false;
- for (unsigned long bit : IterateBitSet(mStateBits))
+ for (size_t bit : mStateBits)
{
sawBit = true;
UNUSED_VARIABLE(bit);
@@ -63,7 +63,7 @@
// Test iterating a result of combining two bitsets.
TEST_F(BitSetIteratorTest, NonLValueBitset)
{
- std::bitset<40> otherBits;
+ BitSet<40> otherBits;
mStateBits.set(1);
mStateBits.set(2);
@@ -75,9 +75,10 @@
otherBits.set(3);
otherBits.set(5);
- std::set<unsigned long> seenBits;
+ std::set<size_t> seenBits;
- for (unsigned long bit : IterateBitSet(mStateBits & otherBits))
+ angle::BitSet<40> maskedBits = (mStateBits & otherBits);
+ for (size_t bit : maskedBits)
{
EXPECT_EQ(0u, seenBits.count(bit));
seenBits.insert(bit);