diff options
author | bunnei <bunneidev@gmail.com> | 2020-12-05 08:46:37 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2020-12-06 09:27:13 +0100 |
commit | d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e (patch) | |
tree | fe882c1a6727fe5fdc10e3cb21bb63651224c8f0 /src/common | |
parent | hle: kernel: Use C++ style comments in KScheduler, etc. (diff) | |
download | yuzu-d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e.tar yuzu-d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e.tar.gz yuzu-d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e.tar.bz2 yuzu-d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e.tar.lz yuzu-d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e.tar.xz yuzu-d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e.tar.zst yuzu-d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e.zip |
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/bit_set.h | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/src/common/bit_set.h b/src/common/bit_set.h index 4f966de40..9235ad412 100644 --- a/src/common/bit_set.h +++ b/src/common/bit_set.h @@ -16,6 +16,9 @@ #pragma once +#include <array> +#include <bit> + #include "common/alignment.h" #include "common/bit_util.h" #include "common/common_types.h" @@ -24,33 +27,11 @@ namespace Common { namespace impl { -#define BITSIZEOF(x) (sizeof(x) * CHAR_BIT) - template <typename Storage, size_t N> class BitSet { -private: - static_assert(std::is_integral<Storage>::value); - static_assert(std::is_unsigned<Storage>::value); - static_assert(sizeof(Storage) <= sizeof(u64)); - - static constexpr size_t FlagsPerWord = BITSIZEOF(Storage); - static constexpr size_t NumWords = AlignUp(N, FlagsPerWord) / FlagsPerWord; - - static constexpr auto CountLeadingZeroImpl(Storage word) { - return CountLeadingZeroes64(static_cast<unsigned long long>(word)) - - (BITSIZEOF(unsigned long long) - FlagsPerWord); - } - - static constexpr Storage GetBitMask(size_t bit) { - return Storage(1) << (FlagsPerWord - 1 - bit); - } - -private: - Storage words[NumWords]; public: - constexpr BitSet() : words() { /* ... */ - } + constexpr BitSet() = default; constexpr void SetBit(size_t i) { this->words[i / FlagsPerWord] |= GetBitMask(i % FlagsPerWord); @@ -81,6 +62,24 @@ public: } return FlagsPerWord * NumWords; } + +private: + static_assert(std::is_unsigned_v<Storage>); + static_assert(sizeof(Storage) <= sizeof(u64)); + + static constexpr size_t FlagsPerWord = BitSize<Storage>(); + static constexpr size_t NumWords = AlignUp(N, FlagsPerWord) / FlagsPerWord; + + static constexpr auto CountLeadingZeroImpl(Storage word) { + return std::countl_zero(static_cast<unsigned long long>(word)) - + (BitSize<unsigned long long>() - FlagsPerWord); + } + + static constexpr Storage GetBitMask(size_t bit) { + return Storage(1) << (FlagsPerWord - 1 - bit); + } + + std::array<Storage, NumWords> words{}; }; } // namespace impl |