diff options
| author | 2020-12-04 23:46:37 -0800 | |
|---|---|---|
| committer | 2020-12-06 00:27:13 -0800 | |
| commit | d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e (patch) | |
| tree | fe882c1a6727fe5fdc10e3cb21bb63651224c8f0 /src | |
| parent | hle: kernel: Use C++ style comments in KScheduler, etc. (diff) | |
| download | yuzu-d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e.tar.gz yuzu-d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e.tar.xz yuzu-d2c0c94f0b76fbae9dd5a7b7cb81b9b53db8be0e.zip | |
common: BitSet: Various style fixes based on code review feedback.
Diffstat (limited to 'src')
| -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 @@ | |||
| 16 | 16 | ||
| 17 | #pragma once | 17 | #pragma once |
| 18 | 18 | ||
| 19 | #include <array> | ||
| 20 | #include <bit> | ||
| 21 | |||
| 19 | #include "common/alignment.h" | 22 | #include "common/alignment.h" |
| 20 | #include "common/bit_util.h" | 23 | #include "common/bit_util.h" |
| 21 | #include "common/common_types.h" | 24 | #include "common/common_types.h" |
| @@ -24,33 +27,11 @@ namespace Common { | |||
| 24 | 27 | ||
| 25 | namespace impl { | 28 | namespace impl { |
| 26 | 29 | ||
| 27 | #define BITSIZEOF(x) (sizeof(x) * CHAR_BIT) | ||
| 28 | |||
| 29 | template <typename Storage, size_t N> | 30 | template <typename Storage, size_t N> |
| 30 | class BitSet { | 31 | class BitSet { |
| 31 | private: | ||
| 32 | static_assert(std::is_integral<Storage>::value); | ||
| 33 | static_assert(std::is_unsigned<Storage>::value); | ||
| 34 | static_assert(sizeof(Storage) <= sizeof(u64)); | ||
| 35 | |||
| 36 | static constexpr size_t FlagsPerWord = BITSIZEOF(Storage); | ||
| 37 | static constexpr size_t NumWords = AlignUp(N, FlagsPerWord) / FlagsPerWord; | ||
| 38 | |||
| 39 | static constexpr auto CountLeadingZeroImpl(Storage word) { | ||
| 40 | return CountLeadingZeroes64(static_cast<unsigned long long>(word)) - | ||
| 41 | (BITSIZEOF(unsigned long long) - FlagsPerWord); | ||
| 42 | } | ||
| 43 | |||
| 44 | static constexpr Storage GetBitMask(size_t bit) { | ||
| 45 | return Storage(1) << (FlagsPerWord - 1 - bit); | ||
| 46 | } | ||
| 47 | |||
| 48 | private: | ||
| 49 | Storage words[NumWords]; | ||
| 50 | 32 | ||
| 51 | public: | 33 | public: |
| 52 | constexpr BitSet() : words() { /* ... */ | 34 | constexpr BitSet() = default; |
| 53 | } | ||
| 54 | 35 | ||
| 55 | constexpr void SetBit(size_t i) { | 36 | constexpr void SetBit(size_t i) { |
| 56 | this->words[i / FlagsPerWord] |= GetBitMask(i % FlagsPerWord); | 37 | this->words[i / FlagsPerWord] |= GetBitMask(i % FlagsPerWord); |
| @@ -81,6 +62,24 @@ public: | |||
| 81 | } | 62 | } |
| 82 | return FlagsPerWord * NumWords; | 63 | return FlagsPerWord * NumWords; |
| 83 | } | 64 | } |
| 65 | |||
| 66 | private: | ||
| 67 | static_assert(std::is_unsigned_v<Storage>); | ||
| 68 | static_assert(sizeof(Storage) <= sizeof(u64)); | ||
| 69 | |||
| 70 | static constexpr size_t FlagsPerWord = BitSize<Storage>(); | ||
| 71 | static constexpr size_t NumWords = AlignUp(N, FlagsPerWord) / FlagsPerWord; | ||
| 72 | |||
| 73 | static constexpr auto CountLeadingZeroImpl(Storage word) { | ||
| 74 | return std::countl_zero(static_cast<unsigned long long>(word)) - | ||
| 75 | (BitSize<unsigned long long>() - FlagsPerWord); | ||
| 76 | } | ||
| 77 | |||
| 78 | static constexpr Storage GetBitMask(size_t bit) { | ||
| 79 | return Storage(1) << (FlagsPerWord - 1 - bit); | ||
| 80 | } | ||
| 81 | |||
| 82 | std::array<Storage, NumWords> words{}; | ||
| 84 | }; | 83 | }; |
| 85 | 84 | ||
| 86 | } // namespace impl | 85 | } // namespace impl |