Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/52038 )

Change subject: arch: Add a virtually backed PCState == operator.
......................................................................

arch: Add a virtually backed PCState == operator.

Define a == operator and an equals() virtual method for the PCStateBase
class which it calls. The equals method will compare the owning PCState
instance with another instance of the same PCState class.

Change-Id: Ia704f1bc9e1217ce191671fe574c226ee1b73278
---
M src/arch/generic/pcstate.hh
M src/arch/arm/pcstate.hh
2 files changed, 44 insertions(+), 51 deletions(-)



diff --git a/src/arch/arm/pcstate.hh b/src/arch/arm/pcstate.hh
index d2f3cef..b1d0b74 100644
--- a/src/arch/arm/pcstate.hh
+++ b/src/arch/arm/pcstate.hh
@@ -376,9 +376,10 @@
     }

     bool
-    operator == (const PCState &opc) const
+    equals(const PCStateBase &other) const override
     {
-        return Base::operator == (opc) &&
+        auto &opc = other.as<PCState>();
+        return Base::equals(other) &&
             flags == opc.flags && nextFlags == opc.nextFlags &&
             _itstate == opc._itstate &&
             _nextItstate == opc._nextItstate &&
@@ -387,12 +388,6 @@
             _stepped == opc._stepped;
     }

-    bool
-    operator != (const PCState &opc) const
-    {
-        return !(*this == opc);
-    }
-
     void
     serialize(CheckpointOut &cp) const override
     {
diff --git a/src/arch/generic/pcstate.hh b/src/arch/generic/pcstate.hh
index 12a9ef1..5e9d7ae 100644
--- a/src/arch/generic/pcstate.hh
+++ b/src/arch/generic/pcstate.hh
@@ -80,6 +80,12 @@

     virtual PCStateBase *clone() const = 0;

+    virtual bool
+    equals(const PCStateBase &other) const
+    {
+        return _pc == other._pc && _upc == other._upc;
+    }
+
     /**
      * Returns the memory address of the instruction this PC points to.
      *
@@ -117,6 +123,18 @@
     }
 };

+static inline bool
+operator==(const PCStateBase &a, const PCStateBase &b)
+{
+    return a.equals(b);
+}
+
+static inline bool
+operator!=(const PCStateBase &a, const PCStateBase &b)
+{
+    return !a.equals(b);
+}
+
 namespace GenericISA
 {

@@ -175,15 +193,11 @@
     void set(Addr val);

     bool
-    operator == (const PCStateCommon &opc) const
+    equals(const PCStateBase &other) const override
     {
-        return _pc == opc._pc && _npc == opc._npc;
-    }
-
-    bool
-    operator != (const PCStateCommon &opc) const
-    {
-        return !(*this == opc);
+        auto &ps = other.as<PCStateCommon>();
+        return PCStateBase::equals(other) &&
+            _npc == ps._npc && _nupc == ps._nupc;
     }

     void
@@ -315,19 +329,6 @@
         this->upc(0);
         this->nupc(1);
     }
-
-    bool
-    operator == (const UPCState<InstWidth> &opc) const
-    {
-        return this->pc() == opc.pc() && this->npc() == opc.npc() &&
-               this->upc() == opc.upc() && this->nupc() == opc.nupc();
-    }
-
-    bool
-    operator != (const UPCState<InstWidth> &opc) const
-    {
-        return !(*this == opc);
-    }
 };

 template <int InstWidth>
@@ -390,17 +391,10 @@
     }

     bool
-    operator == (const DelaySlotPCState<InstWidth> &opc) const
+    equals(const PCStateBase &other) const override
     {
-        return this->_pc == opc._pc &&
-               this->_npc == opc._npc &&
-               this->_nnpc == opc._nnpc;
-    }
-
-    bool
-    operator != (const DelaySlotPCState<InstWidth> &opc) const
-    {
-        return !(*this == opc);
+        auto &ps = other.as<DelaySlotPCState<InstWidth>>();
+        return Base::equals(other) && ps._nnpc == this->_nnpc;
     }

     void
@@ -478,19 +472,10 @@
     }

     bool
-    operator == (const DelaySlotUPCState<InstWidth> &opc) const
+    equals(const PCStateBase &other) const override
     {
-        return this->_pc == opc._pc &&
-               this->_npc == opc._npc &&
-               this->_nnpc == opc._nnpc &&
-               this->_upc == opc._upc &&
-               this->_nupc == opc._nupc;
-    }
-
-    bool
-    operator != (const DelaySlotUPCState<InstWidth> &opc) const
-    {
-        return !(*this == opc);
+        auto &ps = other.as<DelaySlotUPCState<InstWidth>>();
+        return Base::equals(other) && ps._nnpc == this->_nnpc;
     }
 };


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/52038
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ia704f1bc9e1217ce191671fe574c226ee1b73278
Gerrit-Change-Number: 52038
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to