From 0583d401e3e9a77aee3b841f954d494c0a96faaf Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 4 Oct 2018 05:18:22 -0400 Subject: [PATCH] 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. --- src/frontend/ir/value.cpp | 10 +++++++++- src/frontend/ir/value.h | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/frontend/ir/value.cpp b/src/frontend/ir/value.cpp index c3742227..6d5dbecb 100644 --- a/src/frontend/ir/value.cpp +++ b/src/frontend/ir/value.cpp @@ -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 diff --git a/src/frontend/ir/value.h b/src/frontend/ir/value.h index cd3bbf07..5beaf9e8 100644 --- a/src/frontend/ir/value.h +++ b/src/frontend/ir/value.h @@ -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. *