ir/value: Add member function to check whether or not all bits of a contained value are set

This is useful when we wish to know if a contained value is something
like 0xFFFFFFFF, as this helps perform constant folding. For example the
operation: x & 0xFFFFFFFF can be folded to just x in the 32-bit case.
This commit is contained in:
Lioncash 2018-10-01 18:35:31 -04:00 committed by MerryMage
parent 0ea99b7d59
commit f40fcda1f6
2 changed files with 28 additions and 0 deletions

View file

@ -174,4 +174,24 @@ u64 Value::GetImmediateAsU64() const {
}
}
bool Value::HasAllBitsSet() const {
ASSERT(IsImmediate());
switch (GetType()) {
case IR::Type::U1:
return GetU1();
case IR::Type::U8:
return GetU8() == 0xFF;
case IR::Type::U16:
return GetU16() == 0xFFFF;
case IR::Type::U32:
return GetU32() == 0xFFFFFFFF;
case IR::Type::U64:
return GetU64() == 0xFFFFFFFFFFFFFFFF;
default:
ASSERT_MSG(false, "HasAllBitsSet called on an incompatible Value type.");
return false;
}
}
} // namespace Dynarmic::IR

View file

@ -74,6 +74,14 @@ public:
*/
u64 GetImmediateAsU64() const;
/**
* Determines whether or not the contained constant value has all bits set.
*
* @pre The value contains either a U1, U8, U16, U32, or U64 value.
* Breaking this precondition will cause an assertion to be invoked.
*/
bool HasAllBitsSet() const;
private:
Type type;