Move bit_set to new file

This commit is contained in:
Megamouse 2026-05-14 13:48:10 +02:00
parent 53180b8141
commit 5f00b87a44
12 changed files with 226 additions and 158 deletions

View File

@ -1,6 +1,7 @@
#include "stdafx.h"
#include "Emu/System.h"
#include "Emu/Cell/PPUModule.h"
#include "util/bit_set.hpp"
#include "cellPamf.h"

View File

@ -7,6 +7,7 @@
#include "Utilities/File.h"
#include "Emu/VFS.h"
#include "Emu/IdManager.h"
#include "util/bit_set.hpp"
#include "cellRtc.h"

View File

@ -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 <vector>

View File

@ -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"

View File

@ -1,6 +1,7 @@
#pragma once
#include "util/atomic.hpp"
#include "util/bit_set.hpp"
#include <util/types.hpp>
namespace rsx

View File

@ -1,6 +1,7 @@
#pragma once
#include "program_util.h"
#include "util/bit_set.hpp"
#include <vector>
#include <set>

View File

@ -780,9 +780,11 @@
<ClInclude Include="Emu\system_config_types.h" />
<ClInclude Include="Emu\vfs_config.h" />
<ClInclude Include="Loader\disc.h" />
<ClInclude Include="Loader\iso_cache.h" />
<ClInclude Include="Loader\iso_validation.h" />
<ClInclude Include="Loader\mself.hpp" />
<ClInclude Include="util\atomic.hpp" />
<ClInclude Include="util\bit_set.hpp" />
<ClInclude Include="util\bless.hpp" />
<ClInclude Include="util\pair.hpp" />
<ClInclude Include="util\tuple.hpp" />

View File

@ -1438,6 +1438,33 @@
<ClCompile Include="..\Utilities\stereo_config.cpp">
<Filter>Utilities</Filter>
</ClCompile>
<ClCompile Include="Emu\Cell\Modules\libavcdec.cpp">
<Filter>Emu\Cell\Modules</Filter>
</ClCompile>
<ClCompile Include="Emu\Cell\Modules\libdivx311dec.cpp">
<Filter>Emu\Cell\Modules</Filter>
</ClCompile>
<ClCompile Include="Emu\Cell\Modules\libdivxdec.cpp">
<Filter>Emu\Cell\Modules</Filter>
</ClCompile>
<ClCompile Include="Emu\Cell\Modules\libmvcdec.cpp">
<Filter>Emu\Cell\Modules</Filter>
</ClCompile>
<ClCompile Include="Emu\Cell\Modules\libsjvtd.cpp">
<Filter>Emu\Cell\Modules</Filter>
</ClCompile>
<ClCompile Include="Emu\Cell\Modules\libsmvd2.cpp">
<Filter>Emu\Cell\Modules</Filter>
</ClCompile>
<ClCompile Include="Emu\Cell\Modules\libsmvd4.cpp">
<Filter>Emu\Cell\Modules</Filter>
</ClCompile>
<ClCompile Include="Emu\Cell\Modules\libsvc1d.cpp">
<Filter>Emu\Cell\Modules</Filter>
</ClCompile>
<ClCompile Include="Loader\iso_cache.cpp">
<Filter>Loader</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Crypto\aes.h">
@ -2887,6 +2914,36 @@
<ClInclude Include="..\Utilities\stereo_config.h">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="util\bit_set.hpp">
<Filter>Utilities</Filter>
</ClInclude>
<ClInclude Include="Emu\Cell\Modules\libavcdec.h">
<Filter>Emu\Cell\Modules</Filter>
</ClInclude>
<ClInclude Include="Emu\Cell\Modules\libdivx311dec.h">
<Filter>Emu\Cell\Modules</Filter>
</ClInclude>
<ClInclude Include="Emu\Cell\Modules\libdivxdec.h">
<Filter>Emu\Cell\Modules</Filter>
</ClInclude>
<ClInclude Include="Emu\Cell\Modules\libmvcdec.h">
<Filter>Emu\Cell\Modules</Filter>
</ClInclude>
<ClInclude Include="Emu\Cell\Modules\libsjvtd.h">
<Filter>Emu\Cell\Modules</Filter>
</ClInclude>
<ClInclude Include="Emu\Cell\Modules\libsmvd2.h">
<Filter>Emu\Cell\Modules</Filter>
</ClInclude>
<ClInclude Include="Emu\Cell\Modules\libsmvd4.h">
<Filter>Emu\Cell\Modules</Filter>
</ClInclude>
<ClInclude Include="Emu\Cell\Modules\libsvc1d.h">
<Filter>Emu\Cell\Modules</Filter>
</ClInclude>
<ClInclude Include="Loader\iso_cache.h">
<Filter>Loader</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Emu\RSX\Program\GLSLSnippets\GPUDeswizzle.glsl">

View File

@ -1,7 +1,7 @@
#pragma once
#include "find_dialog.h"
#include "util/types.hpp"
#include "util/bit_set.hpp"
#include <QPlainTextEdit>
#include <QDropEvent>

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h>
#include "util/types.hpp"
#include "util/bit_set.hpp"
namespace utils
{

159
rpcs3/util/bit_set.hpp Normal file
View File

@ -0,0 +1,159 @@
#pragma once
#include "types.hpp"
#include <bitset>
// Exception friendly std::bitset
template <usz Bits>
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 <typename T> requires std::convertible_to<T, usz>
location_index(T&& pos, std::source_location src_loc = std::source_location::current())
: index(static_cast<usz>(std::forward<T>(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<Bits>&& set) noexcept : m_bitset(set) {}
std::bitset<Bits> m_bitset;
};

View File

@ -11,7 +11,6 @@
#include <compare>
#include <memory>
#include <bit>
#include <bitset>
#include <string>
#include <source_location>
#include <new>
@ -1065,161 +1064,6 @@ template <typename CT, typename T> requires requires (CT&& x, T&& y) { x.count(y
return found->second;
}
// Exception friendly std::bitset
template <usz Bits>
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 <typename T> requires std::convertible_to<T, usz>
location_index(T&& pos, std::source_location src_loc = std::source_location::current())
: index(static_cast<usz>(std::forward<T>(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<Bits>&& set) noexcept : m_bitset(set) {}
std::bitset<Bits> m_bitset;
};
// Simplified hash algorithm. May be used in std::unordered_(map|set).
template <typename T, usz Shift = 0>
struct value_hash