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 <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Earl Ou <shunhsingou@google.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
This commit is contained in:
Gabe Black
2021-10-08 17:49:51 -07:00
parent 8b496a1a12
commit e3a79d40f4
2 changed files with 28 additions and 55 deletions

View File

@@ -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<PCState>();
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
{

View File

@@ -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<PCStateCommon>();
return PCStateBase::equals(other) &&
_npc == ps._npc && _nupc == ps._nupc;
}
void
@@ -312,19 +326,6 @@ class UPCState : public SimplePCState<InstWidth>
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>
@@ -387,17 +388,10 @@ class DelaySlotPCState : public SimplePCState<InstWidth>
}
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
@@ -473,22 +467,6 @@ class DelaySlotUPCState : public DelaySlotPCState<InstWidth>
this->_upc = 0;
this->_nupc = 1;
}
bool
operator == (const DelaySlotUPCState<InstWidth> &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<InstWidth> &opc) const
{
return !(*this == opc);
}
};
template <int InstWidth>