From 5f00b87a44e09ef37127cb6833ecc2d8fc43b322 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Thu, 14 May 2026 13:48:10 +0200 Subject: [PATCH] Move bit_set to new file --- rpcs3/Emu/Cell/Modules/cellPamf.cpp | 1 + rpcs3/Emu/Cell/Modules/cellSsl.cpp | 1 + rpcs3/Emu/Cell/SPURecompiler.h | 1 + rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp | 1 + rpcs3/Emu/RSX/Common/bitfield.hpp | 1 + rpcs3/Emu/RSX/Program/RSXVertexProgram.h | 1 + rpcs3/emucore.vcxproj | 2 + rpcs3/emucore.vcxproj.filters | 57 ++++++++ rpcs3/rpcs3qt/log_viewer.h | 2 +- rpcs3/tests/test_bit_set.cpp | 2 +- rpcs3/util/bit_set.hpp | 159 +++++++++++++++++++++++ rpcs3/util/types.hpp | 156 ---------------------- 12 files changed, 226 insertions(+), 158 deletions(-) create mode 100644 rpcs3/util/bit_set.hpp diff --git a/rpcs3/Emu/Cell/Modules/cellPamf.cpp b/rpcs3/Emu/Cell/Modules/cellPamf.cpp index 42ce5b331c..314b646a1f 100644 --- a/rpcs3/Emu/Cell/Modules/cellPamf.cpp +++ b/rpcs3/Emu/Cell/Modules/cellPamf.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "Emu/System.h" #include "Emu/Cell/PPUModule.h" +#include "util/bit_set.hpp" #include "cellPamf.h" diff --git a/rpcs3/Emu/Cell/Modules/cellSsl.cpp b/rpcs3/Emu/Cell/Modules/cellSsl.cpp index 7c0aa6d9aa..7de808bd25 100644 --- a/rpcs3/Emu/Cell/Modules/cellSsl.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSsl.cpp @@ -7,6 +7,7 @@ #include "Utilities/File.h" #include "Emu/VFS.h" #include "Emu/IdManager.h" +#include "util/bit_set.hpp" #include "cellRtc.h" diff --git a/rpcs3/Emu/Cell/SPURecompiler.h b/rpcs3/Emu/Cell/SPURecompiler.h index 08cdc42b02..307cd74a91 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.h +++ b/rpcs3/Emu/Cell/SPURecompiler.h @@ -3,6 +3,7 @@ #include "Utilities/File.h" #include "Utilities/lockless.h" #include "Utilities/address_range.h" +#include "util/bit_set.hpp" #include "SPUThread.h" #include "SPUAnalyser.h" #include diff --git a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp index ebcbd74f8b..c5204b295c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.cpp @@ -4,6 +4,7 @@ #include "Emu/System.h" #include "Emu/system_config.h" #include "Emu//Audio/audio_utils.h" +#include "util/bit_set.hpp" #include "util/video_provider.h" #include "sys_rsxaudio.h" diff --git a/rpcs3/Emu/RSX/Common/bitfield.hpp b/rpcs3/Emu/RSX/Common/bitfield.hpp index 4ffc07a537..f0e7f704b3 100644 --- a/rpcs3/Emu/RSX/Common/bitfield.hpp +++ b/rpcs3/Emu/RSX/Common/bitfield.hpp @@ -1,6 +1,7 @@ #pragma once #include "util/atomic.hpp" +#include "util/bit_set.hpp" #include namespace rsx diff --git a/rpcs3/Emu/RSX/Program/RSXVertexProgram.h b/rpcs3/Emu/RSX/Program/RSXVertexProgram.h index c3834e4f93..26fbd98731 100644 --- a/rpcs3/Emu/RSX/Program/RSXVertexProgram.h +++ b/rpcs3/Emu/RSX/Program/RSXVertexProgram.h @@ -1,6 +1,7 @@ #pragma once #include "program_util.h" +#include "util/bit_set.hpp" #include #include diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index 31ef781d93..6adcd8d917 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -780,9 +780,11 @@ + + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index 17ed08a3f6..80c6359e69 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -1438,6 +1438,33 @@ Utilities + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Loader + @@ -2887,6 +2914,36 @@ Utilities + + Utilities + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Emu\Cell\Modules + + + Loader + diff --git a/rpcs3/rpcs3qt/log_viewer.h b/rpcs3/rpcs3qt/log_viewer.h index 443c89eb78..fef2d3198f 100644 --- a/rpcs3/rpcs3qt/log_viewer.h +++ b/rpcs3/rpcs3qt/log_viewer.h @@ -1,7 +1,7 @@ #pragma once #include "find_dialog.h" -#include "util/types.hpp" +#include "util/bit_set.hpp" #include #include diff --git a/rpcs3/tests/test_bit_set.cpp b/rpcs3/tests/test_bit_set.cpp index d2058b4877..5122c28089 100644 --- a/rpcs3/tests/test_bit_set.cpp +++ b/rpcs3/tests/test_bit_set.cpp @@ -1,6 +1,6 @@ #include -#include "util/types.hpp" +#include "util/bit_set.hpp" namespace utils { diff --git a/rpcs3/util/bit_set.hpp b/rpcs3/util/bit_set.hpp new file mode 100644 index 0000000000..2fa3921630 --- /dev/null +++ b/rpcs3/util/bit_set.hpp @@ -0,0 +1,159 @@ +#pragma once + +#include "types.hpp" +#include + +// Exception friendly std::bitset +template +struct bit_set +{ +public: + constexpr bit_set() noexcept : m_bitset() {} + constexpr bit_set(usz val) noexcept : m_bitset(val) {} + + [[nodiscard]] bool test(usz pos, std::source_location src_loc = std::source_location::current()) const + { + if (pos >= Bits) [[unlikely]] + fmt::raw_range_error(src_loc, format_object_simplified(pos), Bits); + + return m_bitset[pos]; + } + + [[nodiscard]] bool test_unsafe(usz pos) const + { + return m_bitset[pos]; + } + + bit_set& set(usz pos, bool val = true, std::source_location src_loc = std::source_location::current()) + { + if (pos >= Bits) [[unlikely]] + fmt::raw_range_error(src_loc, format_object_simplified(pos), Bits); + + m_bitset[pos] = val; + return *this; + } + + bit_set& set_unsafe(usz pos, bool val = true) + { + m_bitset[pos] = val; + return *this; + } + + bit_set& reset(usz pos, std::source_location src_loc = std::source_location::current()) + { + if (pos >= Bits) [[unlikely]] + fmt::raw_range_error(src_loc, format_object_simplified(pos), Bits); + + m_bitset[pos] = false; + return *this; + } + + bit_set& reset_unsafe(usz pos) + { + m_bitset.reset(pos); + return *this; + } + + constexpr bit_set& reset() noexcept + { + m_bitset.reset(); + return *this; + } + + [[nodiscard]] constexpr unsigned long to_ulong() const noexcept requires(Bits <= 32) + { + return m_bitset.to_ulong(); + } + + [[nodiscard]] constexpr unsigned long long to_ullong() const noexcept requires(Bits <= 64) + { + return m_bitset.to_ullong(); + } + + [[nodiscard]] constexpr bool any() const noexcept + { + return m_bitset.any(); + } + + [[nodiscard]] constexpr bool none() const noexcept + { + return m_bitset.none(); + } + + [[nodiscard]] constexpr bool all() const noexcept + { + return m_bitset.all(); + } + + [[nodiscard]] constexpr usz count() const noexcept + { + return m_bitset.count(); + } + + [[nodiscard]] constexpr usz size() const noexcept + { + return Bits; + } + + // Helps us getting the source location when using the [] operator + struct location_index + { + template requires std::convertible_to + location_index(T&& pos, std::source_location src_loc = std::source_location::current()) + : index(static_cast(std::forward(pos))), loc(src_loc) + {} + + usz index; + std::source_location loc; + }; + + [[nodiscard]] constexpr bool operator[](location_index index) const + { + return test(index.index, index.loc); + } + + constexpr bit_set& operator&=(const bit_set& r) noexcept + { + m_bitset &= r.m_bitset; + return *this; + } + + constexpr bit_set& operator|=(const bit_set& r) noexcept + { + m_bitset |= r.m_bitset; + return *this; + } + + constexpr bit_set& operator^=(const bit_set& r) noexcept + { + m_bitset ^= r.m_bitset; + return *this; + } + + constexpr bit_set& operator<<=(usz pos) noexcept + { + m_bitset <<= pos; + return *this; + } + + constexpr bit_set& operator>>=(usz pos) noexcept + { + m_bitset >>= pos; + return *this; + } + + [[nodiscard]] constexpr bit_set operator<<(const usz pos) const noexcept + { + return m_bitset << pos; + } + + [[nodiscard]] constexpr bit_set operator>>(const usz pos) const noexcept + { + return m_bitset >> pos; + } + +private: + constexpr bit_set(std::bitset&& set) noexcept : m_bitset(set) {} + + std::bitset m_bitset; +}; diff --git a/rpcs3/util/types.hpp b/rpcs3/util/types.hpp index cd73f925d0..a1a07bac69 100644 --- a/rpcs3/util/types.hpp +++ b/rpcs3/util/types.hpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -1065,161 +1064,6 @@ template requires requires (CT&& x, T&& y) { x.count(y return found->second; } -// Exception friendly std::bitset -template -struct bit_set -{ -public: - constexpr bit_set() noexcept : m_bitset() {} - constexpr bit_set(usz val) noexcept : m_bitset(val) {} - - [[nodiscard]] bool test(usz pos, std::source_location src_loc = std::source_location::current()) const - { - if (pos >= Bits) [[unlikely]] - fmt::raw_range_error(src_loc, format_object_simplified(pos), Bits); - - return m_bitset[pos]; - } - - [[nodiscard]] bool test_unsafe(usz pos) const - { - return m_bitset[pos]; - } - - bit_set& set(usz pos, bool val = true, std::source_location src_loc = std::source_location::current()) - { - if (pos >= Bits) [[unlikely]] - fmt::raw_range_error(src_loc, format_object_simplified(pos), Bits); - - m_bitset[pos] = val; - return *this; - } - - bit_set& set_unsafe(usz pos, bool val = true) - { - m_bitset[pos] = val; - return *this; - } - - bit_set& reset(usz pos, std::source_location src_loc = std::source_location::current()) - { - if (pos >= Bits) [[unlikely]] - fmt::raw_range_error(src_loc, format_object_simplified(pos), Bits); - - m_bitset[pos] = false; - return *this; - } - - bit_set& reset_unsafe(usz pos) - { - m_bitset.reset(pos); - return *this; - } - - constexpr bit_set& reset() noexcept - { - m_bitset.reset(); - return *this; - } - - [[nodiscard]] constexpr unsigned long to_ulong() const noexcept requires(Bits <= 32) - { - return m_bitset.to_ulong(); - } - - [[nodiscard]] constexpr unsigned long long to_ullong() const noexcept requires(Bits <= 64) - { - return m_bitset.to_ullong(); - } - - [[nodiscard]] constexpr bool any() const noexcept - { - return m_bitset.any(); - } - - [[nodiscard]] constexpr bool none() const noexcept - { - return m_bitset.none(); - } - - [[nodiscard]] constexpr bool all() const noexcept - { - return m_bitset.all(); - } - - [[nodiscard]] constexpr usz count() const noexcept - { - return m_bitset.count(); - } - - [[nodiscard]] constexpr usz size() const noexcept - { - return Bits; - } - - // Helps us getting the source location when using the [] operator - struct location_index - { - template requires std::convertible_to - location_index(T&& pos, std::source_location src_loc = std::source_location::current()) - : index(static_cast(std::forward(pos))), loc(src_loc) - {} - - usz index; - std::source_location loc; - }; - - [[nodiscard]] constexpr bool operator[](location_index index) const - { - return test(index.index, index.loc); - } - - constexpr bit_set& operator&=(const bit_set& r) noexcept - { - m_bitset &= r.m_bitset; - return *this; - } - - constexpr bit_set& operator|=(const bit_set& r) noexcept - { - m_bitset |= r.m_bitset; - return *this; - } - - constexpr bit_set& operator^=(const bit_set& r) noexcept - { - m_bitset ^= r.m_bitset; - return *this; - } - - constexpr bit_set& operator<<=(usz pos) noexcept - { - m_bitset <<= pos; - return *this; - } - - constexpr bit_set& operator>>=(usz pos) noexcept - { - m_bitset >>= pos; - return *this; - } - - [[nodiscard]] constexpr bit_set operator<<(const usz pos) const noexcept - { - return m_bitset << pos; - } - - [[nodiscard]] constexpr bit_set operator>>(const usz pos) const noexcept - { - return m_bitset >> pos; - } - -private: - constexpr bit_set(std::bitset&& set) noexcept : m_bitset(set) {} - - std::bitset m_bitset; -}; - // Simplified hash algorithm. May be used in std::unordered_(map|set). template struct value_hash