Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace simple_type with std::common_type #10121

Merged
merged 1 commit into from
Apr 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Utilities/BitField.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ template<typename T, uint N>
struct bf_base
{
using type = T;
using vtype = simple_t<type>;
using vtype = std::common_type_t<type>;
using utype = typename std::make_unsigned<vtype>::type;

// Datatype bitsize
Expand Down Expand Up @@ -262,7 +262,7 @@ struct ff_t : bf_base<T, N>
template<typename T, uint I, uint N>
struct fmt_unveil<bf_t<T, I, N>, void>
{
using type = typename fmt_unveil<simple_t<T>>::type;
using type = typename fmt_unveil<std::common_type_t<T>>::type;

static inline auto get(const bf_t<T, I, N>& bf)
{
Expand All @@ -273,7 +273,7 @@ struct fmt_unveil<bf_t<T, I, N>, void>
template<typename F, typename... Fields>
struct fmt_unveil<cf_t<F, Fields...>, void>
{
using type = typename fmt_unveil<simple_t<typename F::type>>::type;
using type = typename fmt_unveil<std::common_type_t<typename F::type>>::type;

static inline auto get(const cf_t<F, Fields...>& cf)
{
Expand All @@ -284,7 +284,7 @@ struct fmt_unveil<cf_t<F, Fields...>, void>
template<typename T, T V, uint N>
struct fmt_unveil<ff_t<T, V, N>, void>
{
using type = typename fmt_unveil<simple_t<T>>::type;
using type = typename fmt_unveil<std::common_type_t<T>>::type;

static inline auto get(const ff_t<T, V, N>& ff)
{
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/PPUThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct cmd64
u32 arg2;
};

template <typename T, typename T2 = simple_t<T>>
template <typename T, typename T2 = std::common_type_t<T>>
cmd64(const T& value)
: m_data(std::bit_cast<u64, T2>(value))
{
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Memory/vm_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace vm
return vm::cast(m_addr);
}

operator simple_t<T>() const
operator std::common_type_t<T>() const
{
return get_ref();
}
Expand All @@ -64,7 +64,7 @@ namespace vm
return get_ref() = right.get_ref();
}

T& operator =(const simple_t<T>& right) const
T& operator =(const std::common_type_t<T>& right) const
{
return get_ref() = right;
}
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/RSX/GCM.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ struct any32
{
u32 m_data;

template <typename T, typename T2 = simple_t<T>>
template <typename T, typename T2 = std::common_type_t<T>>
any32(const T& value)
: m_data(std::bit_cast<u32, T2>(value))
{
Expand Down
25 changes: 17 additions & 8 deletions rpcs3/util/atomic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,9 +1119,6 @@ class atomic_t

atomic_t& operator =(const atomic_t&) = delete;

// Define simple type
using simple_type = simple_t<T>;

constexpr atomic_t(const type& value) noexcept
: m_data(value)
{
Expand Down Expand Up @@ -1229,7 +1226,7 @@ class atomic_t
}

// Atomically read data
operator simple_type() const
operator std::common_type_t<T>() const
{
return atomic_storage<type>::load(m_data);
}
Expand Down Expand Up @@ -1517,7 +1514,7 @@ class atomic_t
}

// Conditionally decrement
bool try_dec(simple_type greater_than)
bool try_dec(std::common_type_t<T> greater_than)
{
type _new, old = atomic_storage<type>::load(m_data);

Expand All @@ -1540,7 +1537,7 @@ class atomic_t
}

// Conditionally increment
bool try_inc(simple_type less_than)
bool try_inc(std::common_type_t<T> less_than)
{
type _new, old = atomic_storage<type>::load(m_data);

Expand Down Expand Up @@ -1628,8 +1625,6 @@ class atomic_t<bool, Align> : private atomic_t<uchar, Align>
public:
static constexpr usz align = Align;

using simple_type = bool;

atomic_t() noexcept = default;

atomic_t(const atomic_t&) = delete;
Expand All @@ -1646,6 +1641,9 @@ class atomic_t<bool, Align> : private atomic_t<uchar, Align>
return base::load() != 0;
}

// Override implicit conversion from the parent type
explicit operator uchar() const = delete;

operator bool() const noexcept
{
return base::load() != 0;
Expand Down Expand Up @@ -1710,6 +1708,17 @@ class atomic_t<bool, Align> : private atomic_t<uchar, Align>
}
};

// Specializations

template <typename T, usz Align, typename T2, usz Align2>
struct std::common_type<atomic_t<T, Align>, atomic_t<T2, Align2>> : std::common_type<T, T2> {};

template <typename T, usz Align, typename T2>
struct std::common_type<atomic_t<T, Align>, T2> : std::common_type<T, std::common_type_t<T2>> {};

template <typename T, typename T2, usz Align2>
struct std::common_type<T, atomic_t<T2, Align2>> : std::common_type<std::common_type_t<T>, T2> {};

namespace atomic_wait
{
template <usz Align>
Expand Down
17 changes: 13 additions & 4 deletions rpcs3/util/endian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ namespace stx
return *this;
}

using simple_type = simple_t<T>;

constexpr operator type() const noexcept
{
return value();
Expand Down Expand Up @@ -265,7 +263,7 @@ namespace stx
template <typename T2, typename = decltype(+std::declval<const T2&>())>
constexpr bool operator==(const T2& rhs) const noexcept
{
using R = simple_t<T2>;
using R = std::common_type_t<T2>;

if constexpr ((std::is_integral_v<T> || std::is_enum_v<T>) && (std::is_integral_v<R> || std::is_enum_v<R>))
{
Expand Down Expand Up @@ -300,7 +298,7 @@ namespace stx
template <typename T2>
static constexpr bool check_args_for_bitwise_op()
{
using R = simple_t<T2>;
using R = std::common_type_t<T2>;

if constexpr ((std::is_integral_v<T> || std::is_enum_v<T>) && (std::is_integral_v<R> || std::is_enum_v<R>))
{
Expand Down Expand Up @@ -473,6 +471,17 @@ namespace stx
};
}

// Specializations

template <typename T, bool Swap, usz Align, typename T2, bool Swap2, usz Align2>
struct std::common_type<stx::se_t<T, Swap, Align>, stx::se_t<T2, Swap2, Align2>> : std::common_type<T, T2> {};

template <typename T, bool Swap, usz Align, typename T2>
struct std::common_type<stx::se_t<T, Swap, Align>, T2> : std::common_type<T, std::common_type_t<T2>> {};

template <typename T, typename T2, bool Swap2, usz Align2>
struct std::common_type<T, stx::se_t<T2, Swap2, Align2>> : std::common_type<std::common_type_t<T>, T2> {};

#ifndef _MSC_VER
#pragma GCC diagnostic pop
#endif
32 changes: 8 additions & 24 deletions rpcs3/util/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,6 @@ using atomic_be_t = atomic_t<be_t<T>, Align>;
template <typename T, usz Align = alignof(T)>
using atomic_le_t = atomic_t<le_t<T>, Align>;

// Extract T::simple_type if available, remove cv qualifiers
template <typename T, typename = void>
struct simple_type_helper
{
using type = typename std::remove_cv<T>::type;
};

template <typename T>
struct simple_type_helper<T, std::void_t<typename T::simple_type>>
{
using type = typename T::simple_type;
};

template <typename T>
using simple_t = typename simple_type_helper<T>::type;

// Bool type equivalent
class b8
{
Expand Down Expand Up @@ -524,7 +508,7 @@ constexpr inline struct umax_helper
{
constexpr umax_helper() noexcept = default;

template <typename T, typename S = simple_t<T>, typename = std::enable_if_t<std::is_unsigned_v<S>>>
template <typename T, typename S = std::common_type_t<T>, typename = std::enable_if_t<std::is_unsigned_v<S>>>
constexpr bool operator==(const T& rhs) const
{
return rhs == static_cast<S>(-1);
Expand All @@ -533,24 +517,24 @@ constexpr inline struct umax_helper
#if __cpp_impl_three_way_comparison >= 201711 && !__INTELLISENSE__
#else
template <typename T>
friend constexpr std::enable_if_t<std::is_unsigned_v<simple_t<T>>, bool> operator==(const T& lhs, const umax_helper&)
friend constexpr std::enable_if_t<std::is_unsigned_v<std::common_type_t<T>>, bool> operator==(const T& lhs, const umax_helper&)
{
return lhs == static_cast<simple_t<T>>(-1);
return lhs == static_cast<std::common_type_t<T>>(-1);
}
#endif

#if __cpp_impl_three_way_comparison >= 201711
#else
template <typename T, typename S = simple_t<T>, typename = std::enable_if_t<std::is_unsigned_v<S>>>
template <typename T, typename S = std::common_type_t<T>, typename = std::enable_if_t<std::is_unsigned_v<S>>>
constexpr bool operator!=(const T& rhs) const
{
return rhs != static_cast<S>(-1);
}

template <typename T>
friend constexpr std::enable_if_t<std::is_unsigned_v<simple_t<T>>, bool> operator!=(const T& lhs, const umax_helper&)
friend constexpr std::enable_if_t<std::is_unsigned_v<std::common_type_t<T>>, bool> operator!=(const T& lhs, const umax_helper&)
{
return lhs != static_cast<simple_t<T>>(-1);
return lhs != static_cast<std::common_type_t<T>>(-1);
}
#endif
} umax;
Expand Down Expand Up @@ -784,8 +768,8 @@ struct narrow_impl<From, To, std::enable_if_t<std::is_signed<From>::value && std

// Simple type enabled (TODO: allow for To as well)
template <typename From, typename To>
struct narrow_impl<From, To, std::void_t<typename From::simple_type>>
: narrow_impl<simple_t<From>, To>
struct narrow_impl<From, To, std::enable_if_t<!std::is_same_v<std::common_type_t<From>, From>>>
: narrow_impl<std::common_type_t<From>, To>
{
};

Expand Down