diff --git a/Utilities/bit_set.h b/Utilities/bit_set.h index 3fd3ef2270..28e3099ddd 100644 --- a/Utilities/bit_set.h +++ b/Utilities/bit_set.h @@ -112,39 +112,34 @@ public: return *this; } - constexpr bs_t operator +(bs_t rhs) const + friend constexpr bs_t operator +(bs_t lhs, bs_t rhs) { - return bs_t(0, m_data | rhs.m_data); + return bs_t(0, lhs.m_data | rhs.m_data); } - constexpr bs_t operator -(bs_t rhs) const + friend constexpr bs_t operator -(bs_t lhs, bs_t rhs) { - return bs_t(0, m_data & ~rhs.m_data); + return bs_t(0, lhs.m_data & ~rhs.m_data); } - constexpr bs_t operator &(bs_t rhs) const + friend constexpr bs_t operator &(bs_t lhs, bs_t rhs) { - return bs_t(0, m_data & rhs.m_data); + return bs_t(0, lhs.m_data & rhs.m_data); } - constexpr bs_t operator ^(bs_t rhs) const + friend constexpr bs_t operator ^(bs_t lhs, bs_t rhs) { - return bs_t(0, m_data ^ rhs.m_data); + return bs_t(0, lhs.m_data ^ rhs.m_data); } - constexpr bool operator ==(bs_t rhs) const + friend constexpr bool operator ==(bs_t lhs, bs_t rhs) { - return m_data == rhs.m_data; + return lhs.m_data == rhs.m_data; } - constexpr bool operator !=(bs_t rhs) const + friend constexpr bool operator !=(bs_t lhs, bs_t rhs) { - return m_data != rhs.m_data; - } - - constexpr bool test(bs_t rhs) const - { - return (m_data & rhs.m_data) != 0; + return lhs.m_data != rhs.m_data; } constexpr bool test_and_set(T bit) @@ -173,33 +168,61 @@ public: template constexpr bs_t operator +(T bit) { - return bit; + return bs_t(bit); } // Binary '+' operator: bitset union -template -constexpr bs_t operator +(T lhs, T rhs) +template +constexpr std::enable_if_t, U>, bs_t> operator +(T lhs, const U& rhs) +{ + return bs_t(lhs) + bs_t(rhs); +} + +// Binary '+' operator: bitset union +template +constexpr std::enable_if_t<(std::is_constructible_v, U> && !std::is_enum_v), bs_t> operator +(const U& lhs, T rhs) { return bs_t(lhs) + bs_t(rhs); } // Binary '-' operator: bitset difference -template -constexpr bs_t operator -(T lhs, T rhs) +template +constexpr std::enable_if_t, U>, bs_t> operator -(T lhs, const U& rhs) +{ + return bs_t(lhs) - bs_t(rhs); +} + +// Binary '-' operator: bitset difference +template +constexpr std::enable_if_t<(std::is_constructible_v, U> && !std::is_enum_v), bs_t> operator -(const U& lhs, T rhs) { return bs_t(lhs) - bs_t(rhs); } // Binary '&' operator: bitset intersection -template -constexpr bs_t operator &(T lhs, T rhs) +template +constexpr std::enable_if_t, U>, bs_t> operator &(T lhs, const U& rhs) +{ + return bs_t(lhs) & bs_t(rhs); +} + +// Binary '&' operator: bitset intersection +template +constexpr std::enable_if_t<(std::is_constructible_v, U> && !std::is_enum_v), bs_t> operator &(const U& lhs, T rhs) { return bs_t(lhs) & bs_t(rhs); } // Binary '^' operator: bitset symmetric difference -template -constexpr bs_t operator ^(T lhs, T rhs) +template +constexpr std::enable_if_t, U>, bs_t> operator ^(T lhs, const U& rhs) +{ + return bs_t(lhs) ^ bs_t(rhs); +} + +// Binary '^' operator: bitset symmetric difference +template +constexpr std::enable_if_t<(std::is_constructible_v, U> && !std::is_enum_v), bs_t> operator ^(const U& lhs, T rhs) { return bs_t(lhs) ^ bs_t(rhs); } @@ -237,6 +260,8 @@ public: { } + using base::operator bs_t; + explicit operator bool() const { return static_cast(base::load()); @@ -316,66 +341,6 @@ public: auto or_fetch(const bs_t&) = delete; auto operator |=(const bs_t&) = delete; - bs_t operator +(bs_t rhs) const - { - return bs_t(0, base::load().m_data | rhs.m_data); - } - - bs_t operator -(bs_t rhs) const - { - return bs_t(0, base::load().m_data & ~rhs.m_data); - } - - bs_t operator &(bs_t rhs) const - { - return bs_t(0, base::load().m_data & rhs.m_data); - } - - bs_t operator ^(bs_t rhs) const - { - return bs_t(0, base::load().m_data ^ rhs.m_data); - } - - bs_t operator ==(bs_t rhs) const - { - return base::load().m_data == rhs.m_data; - } - - bs_t operator !=(bs_t rhs) const - { - return base::load().m_data != rhs.m_data; - } - - friend bs_t operator +(bs_t lhs, const atomic_bs_t& rhs) - { - return bs_t(0, lhs.m_data | rhs.load().m_data); - } - - friend bs_t operator -(bs_t lhs, const atomic_bs_t& rhs) - { - return bs_t(0, lhs.m_data & ~rhs.load().m_data); - } - - friend bs_t operator &(bs_t lhs, const atomic_bs_t& rhs) - { - return bs_t(0, lhs.m_data & rhs.load().m_data); - } - - friend bs_t operator ^(bs_t lhs, const atomic_bs_t& rhs) - { - return bs_t(0, lhs.m_data ^ rhs.load().m_data); - } - - friend bs_t operator ==(bs_t lhs, const atomic_bs_t& rhs) - { - return lhs.m_data == rhs.load().m_data; - } - - friend bs_t operator !=(bs_t lhs, const atomic_bs_t& rhs) - { - return lhs.m_data != rhs.load().m_data; - } - bool test_and_set(T rhs) { return atomic_storage::bts(m_data.m_data, static_cast(static_cast(rhs))); diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index bef6eda407..402ce81745 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -469,7 +469,7 @@ void cpu_thread::operator()() cpu_thread* _cpu = get_current_cpu_thread(); // Wait flag isn't set asynchronously so this should be thread-safe - if (progress == 0 && !(_cpu->state & cpu_flag::wait)) + if (progress == 0 && cpu_flag::wait - _cpu->state) { // Operation just started and syscall is imminent _cpu->state += cpu_flag::wait + cpu_flag::temp; @@ -491,7 +491,7 @@ void cpu_thread::operator()() cpu_thread* _cpu = get_current_cpu_thread(); - if (progress == 0 && !(_cpu->state & cpu_flag::wait)) + if (progress == 0 && cpu_flag::wait - _cpu->state) { _cpu->state += cpu_flag::wait + cpu_flag::temp; wait_set = true; diff --git a/rpcs3/Emu/Cell/SPURecompiler.cpp b/rpcs3/Emu/Cell/SPURecompiler.cpp index 0fd6584168..d4f1620ee9 100644 --- a/rpcs3/Emu/Cell/SPURecompiler.cpp +++ b/rpcs3/Emu/Cell/SPURecompiler.cpp @@ -4376,7 +4376,7 @@ public: elements = 16; dwords = 8; } - else if (true) + else if (true) { stride = 32; elements = 8; @@ -9080,7 +9080,7 @@ struct spu_llvm { const u64 name = atomic_storage::load(spu.block_hash); - if (auto state = +spu.state; !::is_paused(state) && !::is_stopped(state) && !(state & cpu_flag::wait)) + if (auto state = +spu.state; !::is_paused(state) && !::is_stopped(state) && cpu_flag::wait - state) { const auto found = std::as_const(samples).find(name); diff --git a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp index a44e849415..ef5572afdb 100644 --- a/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_interrupt.cpp @@ -100,7 +100,7 @@ error_code _sys_interrupt_thread_establish(ppu_thread& ppu, vm::ptr ih, u32 } // If interrupt thread is running, it's already established on another interrupt tag - if (!(it->state & cpu_flag::stop)) + if (cpu_flag::stop - it->state) { error = CELL_EAGAIN; return result;