frontend/A32/types: Use helper function in operator+ overload

Allows deduplicating an assert and a cast.
This commit is contained in:
Lioncash 2019-05-02 00:03:12 -04:00 committed by MerryMage
parent 796bb8a7f7
commit 511613c736

View file

@ -92,16 +92,14 @@ inline size_t RegNumber(ExtReg reg) {
}
inline Reg operator+(Reg reg, size_t number) {
ASSERT(reg != Reg::INVALID_REG);
size_t new_reg = static_cast<size_t>(reg) + number;
const size_t new_reg = RegNumber(reg) + number;
ASSERT(new_reg <= 15);
return static_cast<Reg>(new_reg);
}
inline ExtReg operator+(ExtReg reg, size_t number) {
ExtReg new_reg = static_cast<ExtReg>(static_cast<size_t>(reg) + number);
const auto new_reg = static_cast<ExtReg>(static_cast<size_t>(reg) + number);
ASSERT((IsSingleExtReg(reg) && IsSingleExtReg(new_reg)) ||
(IsDoubleExtReg(reg) && IsDoubleExtReg(new_reg)));