diff --git a/include/biscuit/registers.hpp b/include/biscuit/registers.hpp index b6df4a1..0fed6a8 100644 --- a/include/biscuit/registers.hpp +++ b/include/biscuit/registers.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -23,6 +24,9 @@ class Register { return m_index; } + friend constexpr bool operator==(Register, Register) = default; + friend constexpr auto operator<=>(Register, Register) = default; + protected: constexpr Register(uint32_t index) noexcept : m_index{index} {} @@ -37,12 +41,8 @@ class GPR final : public Register { constexpr GPR() noexcept : Register{0} {} constexpr explicit GPR(uint32_t index) noexcept : Register{index} {} - friend constexpr bool operator==(GPR lhs, GPR rhs) noexcept { - return lhs.Index() == rhs.Index(); - } - friend constexpr bool operator!=(GPR lhs, GPR rhs) noexcept { - return !operator==(lhs, rhs); - } + friend constexpr bool operator==(GPR, GPR) = default; + friend constexpr auto operator<=>(GPR, GPR) = default; }; /// Floating point register. @@ -51,12 +51,8 @@ class FPR final : public Register { constexpr FPR() noexcept : Register{0} {} constexpr explicit FPR(uint32_t index) noexcept : Register{index} {} - friend constexpr bool operator==(FPR lhs, FPR rhs) noexcept { - return lhs.Index() == rhs.Index(); - } - friend constexpr bool operator!=(FPR lhs, FPR rhs) noexcept { - return !operator==(lhs, rhs); - } + friend constexpr bool operator==(FPR, FPR) = default; + friend constexpr auto operator<=>(FPR, FPR) = default; }; /// Vector register. @@ -65,12 +61,8 @@ class Vec final : public Register { constexpr Vec() noexcept : Register{0} {} constexpr explicit Vec(uint32_t index) noexcept : Register{index} {} - friend constexpr bool operator==(Vec lhs, Vec rhs) noexcept { - return lhs.Index() == rhs.Index(); - } - friend constexpr bool operator!=(Vec lhs, Vec rhs) noexcept { - return !operator==(lhs, rhs); - } + friend constexpr bool operator==(Vec, Vec) = default; + friend constexpr auto operator<=>(Vec, Vec) = default; }; // General-purpose Registers @@ -309,7 +301,7 @@ class PushPopList final { // Aside from ra, it's only valid for s0-s11 to show up the register list ranges. [[nodiscard]] static constexpr bool IsSRegister(const GPR& gpr) { - return gpr == s0 || gpr == s1 || (gpr.Index() >= s2.Index() && gpr.Index() <= s11.Index()); + return gpr == s0 || gpr == s1 || (gpr >= s2 && gpr <= s11); } uint32_t m_bitmask = 0; diff --git a/src/assembler_compressed.cpp b/src/assembler_compressed.cpp index ccbb361..43332dd 100644 --- a/src/assembler_compressed.cpp +++ b/src/assembler_compressed.cpp @@ -131,7 +131,7 @@ void EmitCMJTType(CodeBuffer& buffer, uint32_t funct6, uint32_t index, uint32_t void EmitCMMVType(CodeBuffer& buffer, uint32_t funct6, GPR r1s, uint32_t funct2, GPR r2s, uint32_t op) { const auto is_valid_s_register = [](GPR reg) { - return reg == s0 || reg == s1 || (reg.Index() >= s2.Index() && reg.Index() <= s7.Index()); + return reg == s0 || reg == s1 || (reg >= s2 && reg <= s7); }; BISCUIT_ASSERT(r1s != r2s);