Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/52037 )
Change subject: arch: Promote the PC and microPC to the PCStateBase class.
......................................................................
arch: Promote the PC and microPC to the PCStateBase class.
Also move up the accessors for them. By putting the storage in the base
class, we can keep the accessors non-virtual and keep their overhead
low. Subclasses will be free to set those values to whatever they want
with no overhead, just as if they were natively part of that class.
Change-Id: I58e058def174e0bf591c0a9f050c23f61e9d8823
---
M src/arch/generic/pcstate.hh
1 file changed, 112 insertions(+), 112 deletions(-)
diff --git a/src/arch/generic/pcstate.hh b/src/arch/generic/pcstate.hh
index c48e93d..12a9ef1 100644
--- a/src/arch/generic/pcstate.hh
+++ b/src/arch/generic/pcstate.hh
@@ -50,8 +50,17 @@
namespace gem5
{
+// The guaranteed interface.
class PCStateBase : public Serializable
{
+ protected:
+ Addr _pc = 0;
+ MicroPC _upc = 0;
+
+ PCStateBase(const PCStateBase &other) : _pc(other._pc),
_upc(other._upc) {}
+ PCStateBase &operator=(const PCStateBase &other) = default;
+ PCStateBase() {}
+
public:
virtual ~PCStateBase() = default;
@@ -70,33 +79,11 @@
}
virtual PCStateBase *clone() const = 0;
-};
-namespace GenericISA
-{
-
-// The guaranteed interface.
-class PCStateCommon : public PCStateBase
-{
- protected:
- Addr _pc = 0;
- Addr _npc = 0;
-
- MicroPC _upc = 0;
- MicroPC _nupc = 1;
-
- PCStateCommon(const PCStateCommon &other) :
- _pc(other._pc), _npc(other._npc), _upc(other._upc),
_nupc(other._nupc)
- {}
- PCStateCommon &operator=(const PCStateCommon &other) = default;
- PCStateCommon() {}
- explicit PCStateCommon(Addr val) { set(val); }
-
- public:
/**
- * Returns the memory address the bytes of this instruction came from.
+ * Returns the memory address of the instruction this PC points to.
*
- * @return Memory address of the current instruction's encoding.
+ * @return Memory address of the instruction this PC points to.
*/
Addr
instAddr() const
@@ -105,17 +92,6 @@
}
/**
- * Returns the memory address the bytes of the next instruction came
from.
- *
- * @return Memory address of the next instruction's encoding.
- */
- Addr
- nextInstAddr() const
- {
- return _npc;
- }
-
- /**
* Returns the current micropc.
*
* @return The current micropc.
@@ -126,6 +102,62 @@
return _upc;
}
+ void
+ serialize(CheckpointOut &cp) const override
+ {
+ SERIALIZE_SCALAR(_pc);
+ SERIALIZE_SCALAR(_upc);
+ }
+
+ void
+ unserialize(CheckpointIn &cp) override
+ {
+ UNSERIALIZE_SCALAR(_pc);
+ UNSERIALIZE_SCALAR(_upc);
+ }
+};
+
+namespace GenericISA
+{
+
+class PCStateCommon : public PCStateBase
+{
+ protected:
+ Addr _npc = 0;
+
+ MicroPC _nupc = 1;
+
+ PCStateCommon(const PCStateCommon &other) : PCStateBase(other),
+ _npc(other._npc), _nupc(other._nupc)
+ {}
+ PCStateCommon &operator=(const PCStateCommon &other) = default;
+ PCStateCommon() {}
+ explicit PCStateCommon(Addr val) { set(val); }
+
+ public:
+ Addr pc() const { return _pc; }
+ void pc(Addr val) { _pc = val; }
+
+ Addr npc() const { return _npc; }
+ void npc(Addr val) { _npc = val; }
+
+ MicroPC upc() const { return _upc; }
+ void upc(MicroPC val) { _upc = val; }
+
+ MicroPC nupc() const { return _nupc; }
+ void nupc(MicroPC val) { _nupc = val; }
+
+ /**
+ * Returns the memory address the bytes of the next instruction came
from.
+ *
+ * @return Memory address of the next instruction's encoding.
+ */
+ Addr
+ nextInstAddr() const
+ {
+ return _npc;
+ }
+
// Reset the macroop's upc without advancing the regular pc.
void
uReset()
@@ -157,18 +189,16 @@
void
serialize(CheckpointOut &cp) const override
{
- SERIALIZE_SCALAR(_pc);
+ PCStateBase::serialize(cp);
SERIALIZE_SCALAR(_npc);
- SERIALIZE_SCALAR(_upc);
SERIALIZE_SCALAR(_nupc);
}
void
unserialize(CheckpointIn &cp) override
{
- UNSERIALIZE_SCALAR(_pc);
+ PCStateBase::unserialize(cp);
UNSERIALIZE_SCALAR(_npc);
- UNSERIALIZE_SCALAR(_upc);
UNSERIALIZE_SCALAR(_nupc);
}
};
@@ -194,23 +224,17 @@
return new SimplePCState<InstWidth>(*this);
}
- Addr pc() const { return _pc; }
- void pc(Addr val) { _pc = val; }
-
- Addr npc() const { return _npc; }
- void npc(Addr val) { _npc = val; }
-
void
set(Addr val)
{
- pc(val);
- npc(val + InstWidth);
+ this->pc(val);
+ this->npc(val + InstWidth);
};
void
setNPC(Addr val)
{
- npc(val);
+ this->npc(val);
}
SimplePCState(const SimplePCState &other) : Base(other) {}
@@ -228,8 +252,8 @@
void
advance()
{
- _pc = _npc;
- _npc += InstWidth;
+ this->_pc = this->_npc;
+ this->_npc += InstWidth;
}
};
@@ -255,18 +279,12 @@
return new UPCState<InstWidth>(*this);
}
- MicroPC upc() const { return this->_upc; }
- void upc(MicroPC val) { this->_upc = val; }
-
- MicroPC nupc() const { return this->_nupc; }
- void nupc(MicroPC val) { this->_nupc = val; }
-
void
set(Addr val)
{
Base::set(val);
- upc(0);
- nupc(1);
+ this->upc(0);
+ this->nupc(1);
}
UPCState(const UPCState &other) : Base(other) {}
@@ -285,8 +303,8 @@
void
uAdvance()
{
- upc(nupc());
- nupc(nupc() + 1);
+ this->upc(this->nupc());
+ this->nupc(this->nupc() + 1);
}
// End the macroop by resetting the upc and advancing the regular pc.
@@ -294,8 +312,8 @@
uEnd()
{
this->advance();
- upc(0);
- nupc(1);
+ this->upc(0);
+ this->nupc(1);
}
bool
@@ -366,17 +384,17 @@
void
advance()
{
- Base::_pc = Base::_npc;
- Base::_npc = _nnpc;
- _nnpc += InstWidth;
+ this->_pc = this->_npc;
+ this->_npc = this->_nnpc;
+ this->_nnpc += InstWidth;
}
bool
operator == (const DelaySlotPCState<InstWidth> &opc) const
{
- return Base::_pc == opc._pc &&
- Base::_npc == opc._npc &&
- _nnpc == opc._nnpc;
+ return this->_pc == opc._pc &&
+ this->_npc == opc._npc &&
+ this->_nnpc == opc._nnpc;
}
bool
@@ -416,9 +434,6 @@
protected:
typedef DelaySlotPCState<InstWidth> Base;
- MicroPC _upc;
- MicroPC _nupc;
-
public:
PCStateBase *
clone() const override
@@ -426,29 +441,15 @@
return new DelaySlotUPCState<InstWidth>(*this);
}
- MicroPC upc() const { return _upc; }
- void upc(MicroPC val) { _upc = val; }
-
- MicroPC nupc() const { return _nupc; }
- void nupc(MicroPC val) { _nupc = val; }
-
- MicroPC
- microPC() const
- {
- return _upc;
- }
-
void
set(Addr val)
{
Base::set(val);
- upc(0);
- nupc(1);
+ this->upc(0);
+ this->nupc(1);
}
- DelaySlotUPCState(const DelaySlotUPCState &other) :
- Base(other), _upc(other._upc), _nupc(other._nupc)
- {}
+ DelaySlotUPCState(const DelaySlotUPCState &other) : Base(other) {}
DelaySlotUPCState &operator=(const DelaySlotUPCState &other) = default;
DelaySlotUPCState() {}
explicit DelaySlotUPCState(Addr val) { set(val); }
@@ -463,8 +464,8 @@
void
uAdvance()
{
- _upc = _nupc;
- _nupc++;
+ this->_upc = this->_nupc;
+ this->_nupc++;
}
// End the macroop by resetting the upc and advancing the regular pc.
@@ -472,17 +473,18 @@
uEnd()
{
this->advance();
- _upc = 0;
- _nupc = 1;
+ this->_upc = 0;
+ this->_nupc = 1;
}
bool
operator == (const DelaySlotUPCState<InstWidth> &opc) const
{
- return Base::_pc == opc._pc &&
- Base::_npc == opc._npc &&
- Base::_nnpc == opc._nnpc &&
- _upc == opc._upc && _nupc == opc._nupc;
+ return this->_pc == opc._pc &&
+ this->_npc == opc._npc &&
+ this->_nnpc == opc._nnpc &&
+ this->_upc == opc._upc &&
+ this->_nupc == opc._nupc;
}
bool
@@ -490,22 +492,6 @@
{
return !(*this == opc);
}
-
- void
- serialize(CheckpointOut &cp) const override
- {
- Base::serialize(cp);
- SERIALIZE_SCALAR(_upc);
- SERIALIZE_SCALAR(_nupc);
- }
-
- void
- unserialize(CheckpointIn &cp) override
- {
- Base::unserialize(cp);
- UNSERIALIZE_SCALAR(_upc);
- UNSERIALIZE_SCALAR(_nupc);
- }
};
template <int InstWidth>
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/52037
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: I58e058def174e0bf591c0a9f050c23f61e9d8823
Gerrit-Change-Number: 52037
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