Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions llvm/include/llvm/ADT/Bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ namespace llvm {
/// initialization.
template <unsigned NumBits>
class Bitset {
typedef uintptr_t BitWord;
using BitWord = uintptr_t;

enum { BITWORD_SIZE = (unsigned)sizeof(BitWord) * CHAR_BIT };
static constexpr unsigned BitwordBits = sizeof(BitWord) * CHAR_BIT;

static_assert(BITWORD_SIZE == 64 || BITWORD_SIZE == 32,
static_assert(BitwordBits == 64 || BitwordBits == 32,
"Unsupported word size");

static constexpr unsigned NumWords =
(NumBits + BITWORD_SIZE - 1) / BITWORD_SIZE;
(NumBits + BitwordBits - 1) / BitwordBits;

protected:
using StorageType = std::array<BitWord, NumWords>;
Expand All @@ -60,23 +60,23 @@ class Bitset {
}

constexpr Bitset &set(unsigned I) {
Bits[I / BITWORD_SIZE] |= BitWord(1) << (I % BITWORD_SIZE);
Bits[I / BitwordBits] |= BitWord(1) << (I % BitwordBits);
return *this;
}

constexpr Bitset &reset(unsigned I) {
Bits[I / BITWORD_SIZE] &= ~(BitWord(1) << (I % BITWORD_SIZE));
Bits[I / BitwordBits] &= ~(BitWord(1) << (I % BitwordBits));
return *this;
}

constexpr Bitset &flip(unsigned I) {
Bits[I / BITWORD_SIZE] ^= BitWord(1) << (I % BITWORD_SIZE);
Bits[I / BitwordBits] ^= BitWord(1) << (I % BitwordBits);
return *this;
}

constexpr bool operator[](unsigned I) const {
BitWord Mask = BitWord(1) << (I % BITWORD_SIZE);
return (Bits[I / BITWORD_SIZE] & Mask) != 0;
BitWord Mask = BitWord(1) << (I % BitwordBits);
return (Bits[I / BitwordBits] & Mask) != 0;
}

constexpr bool test(unsigned I) const { return (*this)[I]; }
Expand Down