From e56ffc1e69e628eb1d9794b03d9b8a963e98eb7d Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sun, 29 Sep 2019 20:26:57 +0300 Subject: [PATCH] Implement optimized operator~ for se_t<> --- rpcs3/util/endian.hpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/rpcs3/util/endian.hpp b/rpcs3/util/endian.hpp index 6bd873be00..e826856cfd 100644 --- a/rpcs3/util/endian.hpp +++ b/rpcs3/util/endian.hpp @@ -143,6 +143,20 @@ namespace stx } } + static constexpr auto int_or_enum() + { + if constexpr (std::is_enum_v>) + { + return std::underlying_type_t>{}; + } + else + { + return simple_t{}; + } + } + + using under = decltype(int_or_enum()); + public: se_t() = default; @@ -194,6 +208,19 @@ namespace stx } #endif + auto operator~() const noexcept + { + if constexpr ((std::is_integral_v || std::is_enum_v) && std::is_convertible_v) + { + // Return se_t of integral type if possible. Promotion to int is omitted on purpose (a compromise). + return std::bit_cast>(static_cast(~std::bit_cast(m_data))); + } + else + { + return ~value(); + } + } + template bool operator==(const T2& rhs) const noexcept { @@ -205,12 +232,11 @@ namespace stx { if constexpr (std::is_enum_v && std::is_convertible_v && std::is_convertible_v) { - using under = std::underlying_type_t; return std::bit_cast(m_data) == std::bit_cast(static_cast>(rhs)); } else { - return std::bit_cast(m_data) == std::bit_cast(static_cast(rhs)); + return std::bit_cast(m_data) == std::bit_cast(static_cast>(rhs)); } } }