ir/value: Add IsSignedImmediate() and IsUnsignedImmediate() functions to Value's interface

This allows testing against arbitrary values while also simultaneously
eliminating the need to check IsImmediate() all the time in expressions.
This commit is contained in:
Lioncash 2018-10-04 05:18:22 -04:00 committed by MerryMage
parent e3258e8525
commit 0583d401e3
2 changed files with 31 additions and 1 deletions

View file

@ -194,6 +194,14 @@ u64 Value::GetImmediateAsU64() const {
}
}
bool Value::IsSignedImmediate(s64 value) const {
return IsImmediate() && GetImmediateAsS64() == value;
}
bool Value::IsUnsignedImmediate(u64 value) const {
return IsImmediate() && GetImmediateAsU64() == value;
}
bool Value::HasAllBitsSet() const {
ASSERT(IsImmediate());
@ -215,7 +223,7 @@ bool Value::HasAllBitsSet() const {
}
bool Value::IsZero() const {
return IsImmediate() && GetImmediateAsU64() == 0;
return IsUnsignedImmediate(0);
}
} // namespace Dynarmic::IR

View file

@ -82,6 +82,28 @@ public:
*/
u64 GetImmediateAsU64() const;
/**
* Determines whether or not the contained value matches the provided signed one.
*
* Note that this function will always return false if the contained
* value is not a a constant value. In other words, if IsImmediate()
* would return false on an instance, then so will this function.
*
* @param value The value to check against the contained value.
*/
bool IsSignedImmediate(s64 value) const;
/**
* Determines whether or not the contained value matches the provided unsigned one.
*
* Note that this function will always return false if the contained
* value is not a a constant value. In other words, if IsImmediate()
* would return false on an instance, then so will this function.
*
* @param value The value to check against the contained value.
*/
bool IsUnsignedImmediate(u64 value) const;
/**
* Determines whether or not the contained constant value has all bits set.
*