From f40fcda1f6b6842117f02b6cd252a8e150635aa7 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 1 Oct 2018 18:35:31 -0400 Subject: [PATCH] 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. --- src/frontend/ir/value.cpp | 20 ++++++++++++++++++++ src/frontend/ir/value.h | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/src/frontend/ir/value.cpp b/src/frontend/ir/value.cpp index d5ba2c62..a7ef2e65 100644 --- a/src/frontend/ir/value.cpp +++ b/src/frontend/ir/value.cpp @@ -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 diff --git a/src/frontend/ir/value.h b/src/frontend/ir/value.h index 4984ebdd..80f5970c 100644 --- a/src/frontend/ir/value.h +++ b/src/frontend/ir/value.h @@ -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;