From e3a79d40f40643205f124bd8f2cb2560ebcad9da Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Fri, 8 Oct 2021 17:49:51 -0700 Subject: [PATCH] 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 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/52038 Maintainer: Gabe Black Tested-by: kokoro Reviewed-by: Earl Ou Reviewed-by: Daniel Carvalho --- src/arch/arm/pcstate.hh | 11 ++---- src/arch/generic/pcstate.hh | 72 +++++++++++++------------------------ 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/src/arch/arm/pcstate.hh b/src/arch/arm/pcstate.hh index d2f3cefff2..b1d0b74534 100644 --- a/src/arch/arm/pcstate.hh +++ b/src/arch/arm/pcstate.hh @@ -376,9 +376,10 @@ class PCState : public GenericISA::UPCState<4> } bool - operator == (const PCState &opc) const + equals(const PCStateBase &other) const override { - return Base::operator == (opc) && + auto &opc = other.as(); + return Base::equals(other) && flags == opc.flags && nextFlags == opc.nextFlags && _itstate == opc._itstate && _nextItstate == opc._nextItstate && @@ -387,12 +388,6 @@ class PCState : public GenericISA::UPCState<4> _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 32ee206885..284797d22d 100644 --- a/src/arch/generic/pcstate.hh +++ b/src/arch/generic/pcstate.hh @@ -80,6 +80,12 @@ class PCStateBase : public Serializable 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 @@ class PCStateBase : public Serializable } }; +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 { @@ -172,15 +190,11 @@ class PCStateCommon : public PCStateBase } 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(); + return PCStateBase::equals(other) && + _npc == ps._npc && _nupc == ps._nupc; } void @@ -312,19 +326,6 @@ class UPCState : public SimplePCState this->upc(0); this->nupc(1); } - - bool - operator == (const UPCState &opc) const - { - return this->pc() == opc.pc() && this->npc() == opc.npc() && - this->upc() == opc.upc() && this->nupc() == opc.nupc(); - } - - bool - operator != (const UPCState &opc) const - { - return !(*this == opc); - } }; template @@ -387,17 +388,10 @@ class DelaySlotPCState : public SimplePCState } bool - operator == (const DelaySlotPCState &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 &opc) const - { - return !(*this == opc); + auto &ps = other.as>(); + return Base::equals(other) && ps._nnpc == this->_nnpc; } void @@ -473,22 +467,6 @@ class DelaySlotUPCState : public DelaySlotPCState this->_upc = 0; this->_nupc = 1; } - - bool - operator == (const DelaySlotUPCState &opc) const - { - 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 &opc) const - { - return !(*this == opc); - } }; template