From b915364c16e8bc24adbf788f6aec385220cd6e33 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 18 Sep 2018 20:37:45 -0400 Subject: [PATCH] A64/imm: Add full range of comparison operators to Imm template Makes the comparison interface consistent by providing all of the relevant members. This also modifies the comparison operators to take the Imm instance by value, as it's really only a u32 under the covers, and it's cheaper to shuffle around a u32 than a 64-bit pointer address. --- src/frontend/A64/imm.h | 74 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/src/frontend/A64/imm.h b/src/frontend/A64/imm.h index 9b33ab2e..eff6c397 100644 --- a/src/frontend/A64/imm.h +++ b/src/frontend/A64/imm.h @@ -51,12 +51,28 @@ public: return static_cast(Common::Bits(value)); } - bool operator==(const Imm& other) const { + bool operator==(Imm other) const { return value == other.value; } - bool operator!=(const Imm& other) const { - return value != other.value; + bool operator!=(Imm other) const { + return !operator==(other); + } + + bool operator<(Imm other) const { + return value < other.value; + } + + bool operator<=(Imm other) const { + return value <= other.value; + } + + bool operator>(Imm other) const { + return value > other.value; + } + + bool operator>=(Imm other) const { + return value >= other.value; } private: @@ -67,23 +83,63 @@ private: }; template -bool operator==(u32 a, const Imm& b) { +bool operator==(u32 a, Imm b) { return Imm{a} == b; } template -bool operator==(const Imm& a, u32 b) { +bool operator==(Imm a, u32 b) { return Imm{b} == a; } template -bool operator!=(u32 a, const Imm& b) { - return Imm{a} != b; +bool operator!=(u32 a, Imm b) { + return !operator==(a, b); } template -bool operator!=(const Imm& a, u32 b) { - return Imm{b} != a; +bool operator!=(Imm a, u32 b) { + return !operator==(a, b); +} + +template +bool operator<(u32 a, Imm b) { + return Imm{a} < b; +} + +template +bool operator<(Imm a, u32 b) { + return a < Imm{b}; +} + +template +bool operator<=(u32 a, Imm b) { + return !operator<(b, a); +} + +template +bool operator<=(Imm a, u32 b) { + return !operator<(b, a); +} + +template +bool operator>(u32 a, Imm b) { + return operator<(b, a); +} + +template +bool operator>(Imm a, u32 b) { + return operator<(b, a); +} + +template +bool operator>=(u32 a, Imm b) { + return !operator<(a, b); +} + +template +bool operator>=(Imm a, u32 b) { + return !operator<(a, b); } /**