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.
This commit is contained in:
Lioncash 2018-09-18 20:37:45 -04:00 committed by MerryMage
parent 02150bc0b7
commit b915364c16

View file

@ -51,12 +51,28 @@ public:
return static_cast<T>(Common::Bits<begin_bit, end_bit>(value)); return static_cast<T>(Common::Bits<begin_bit, end_bit>(value));
} }
bool operator==(const Imm<bit_size>& other) const { bool operator==(Imm other) const {
return value == other.value; return value == other.value;
} }
bool operator!=(const Imm<bit_size>& other) const { bool operator!=(Imm other) const {
return value != other.value; 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: private:
@ -67,23 +83,63 @@ private:
}; };
template <size_t bit_size> template <size_t bit_size>
bool operator==(u32 a, const Imm<bit_size>& b) { bool operator==(u32 a, Imm<bit_size> b) {
return Imm<bit_size>{a} == b; return Imm<bit_size>{a} == b;
} }
template <size_t bit_size> template <size_t bit_size>
bool operator==(const Imm<bit_size>& a, u32 b) { bool operator==(Imm<bit_size> a, u32 b) {
return Imm<bit_size>{b} == a; return Imm<bit_size>{b} == a;
} }
template <size_t bit_size> template <size_t bit_size>
bool operator!=(u32 a, const Imm<bit_size>& b) { bool operator!=(u32 a, Imm<bit_size> b) {
return Imm<bit_size>{a} != b; return !operator==(a, b);
} }
template <size_t bit_size> template <size_t bit_size>
bool operator!=(const Imm<bit_size>& a, u32 b) { bool operator!=(Imm<bit_size> a, u32 b) {
return Imm<bit_size>{b} != a; return !operator==(a, b);
}
template <size_t bit_size>
bool operator<(u32 a, Imm<bit_size> b) {
return Imm<bit_size>{a} < b;
}
template <size_t bit_size>
bool operator<(Imm<bit_size> a, u32 b) {
return a < Imm<bit_size>{b};
}
template <size_t bit_size>
bool operator<=(u32 a, Imm<bit_size> b) {
return !operator<(b, a);
}
template <size_t bit_size>
bool operator<=(Imm<bit_size> a, u32 b) {
return !operator<(b, a);
}
template <size_t bit_size>
bool operator>(u32 a, Imm<bit_size> b) {
return operator<(b, a);
}
template <size_t bit_size>
bool operator>(Imm<bit_size> a, u32 b) {
return operator<(b, a);
}
template <size_t bit_size>
bool operator>=(u32 a, Imm<bit_size> b) {
return !operator<(a, b);
}
template <size_t bit_size>
bool operator>=(Imm<bit_size> a, u32 b) {
return !operator<(a, b);
} }
/** /**