1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 02:32:36 +01:00

bs_t<>: fix/cleanup some operators

This commit is contained in:
Nekotekina 2021-04-17 15:39:13 +03:00
parent 896db3806d
commit 9d4fcbf946
4 changed files with 56 additions and 91 deletions

View File

@ -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 <typename T, typename = decltype(T::__bitset_enum_max)>
constexpr bs_t<T> operator +(T bit)
{
return bit;
return bs_t<T>(bit);
}
// Binary '+' operator: bitset union
template <typename T, typename = decltype(T::__bitset_enum_max)>
constexpr bs_t<T> operator +(T lhs, T rhs)
template <typename T, typename U, typename = decltype(T::__bitset_enum_max)>
constexpr std::enable_if_t<std::is_constructible_v<bs_t<T>, U>, bs_t<T>> operator +(T lhs, const U& rhs)
{
return bs_t<T>(lhs) + bs_t<T>(rhs);
}
// Binary '+' operator: bitset union
template <typename U, typename T, typename = decltype(T::__bitset_enum_max)>
constexpr std::enable_if_t<(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>), bs_t<T>> operator +(const U& lhs, T rhs)
{
return bs_t<T>(lhs) + bs_t<T>(rhs);
}
// Binary '-' operator: bitset difference
template <typename T, typename = decltype(T::__bitset_enum_max)>
constexpr bs_t<T> operator -(T lhs, T rhs)
template <typename T, typename U, typename = decltype(T::__bitset_enum_max)>
constexpr std::enable_if_t<std::is_constructible_v<bs_t<T>, U>, bs_t<T>> operator -(T lhs, const U& rhs)
{
return bs_t<T>(lhs) - bs_t<T>(rhs);
}
// Binary '-' operator: bitset difference
template <typename U, typename T, typename = decltype(T::__bitset_enum_max)>
constexpr std::enable_if_t<(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>), bs_t<T>> operator -(const U& lhs, T rhs)
{
return bs_t<T>(lhs) - bs_t<T>(rhs);
}
// Binary '&' operator: bitset intersection
template <typename T, typename = decltype(T::__bitset_enum_max)>
constexpr bs_t<T> operator &(T lhs, T rhs)
template <typename T, typename U, typename = decltype(T::__bitset_enum_max)>
constexpr std::enable_if_t<std::is_constructible_v<bs_t<T>, U>, bs_t<T>> operator &(T lhs, const U& rhs)
{
return bs_t<T>(lhs) & bs_t<T>(rhs);
}
// Binary '&' operator: bitset intersection
template <typename U, typename T, typename = decltype(T::__bitset_enum_max)>
constexpr std::enable_if_t<(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>), bs_t<T>> operator &(const U& lhs, T rhs)
{
return bs_t<T>(lhs) & bs_t<T>(rhs);
}
// Binary '^' operator: bitset symmetric difference
template <typename T, typename = decltype(T::__bitset_enum_max)>
constexpr bs_t<T> operator ^(T lhs, T rhs)
template <typename T, typename U, typename = decltype(T::__bitset_enum_max)>
constexpr std::enable_if_t<std::is_constructible_v<bs_t<T>, U>, bs_t<T>> operator ^(T lhs, const U& rhs)
{
return bs_t<T>(lhs) ^ bs_t<T>(rhs);
}
// Binary '^' operator: bitset symmetric difference
template <typename U, typename T, typename = decltype(T::__bitset_enum_max)>
constexpr std::enable_if_t<(std::is_constructible_v<bs_t<T>, U> && !std::is_enum_v<U>), bs_t<T>> operator ^(const U& lhs, T rhs)
{
return bs_t<T>(lhs) ^ bs_t<T>(rhs);
}
@ -237,6 +260,8 @@ public:
{
}
using base::operator bs_t;
explicit operator bool() const
{
return static_cast<bool>(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<under>::bts(m_data.m_data, static_cast<uint>(static_cast<under>(rhs)));

View File

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

View File

@ -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<u64>::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);

View File

@ -100,7 +100,7 @@ error_code _sys_interrupt_thread_establish(ppu_thread& ppu, vm::ptr<u32> 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;