00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <pch.h>
00033
00034 #include "Sim/Predictor/BPred/GShare.h"
00035
00036 #include "Sim/Dumper/Dumper.h"
00037 #include "Sim/ISAInfo.h"
00038 #include "Sim/Thread/Thread.h"
00039 #include "Sim/Core/Core.h"
00040 #include "Sim/Op/Op.h"
00041
00042 #include "Sim/Predictor/BPred/BTB.h"
00043 #include "Sim/Predictor/BPred/PHT.h"
00044 #include "Sim/Predictor/BPred/GlobalHistory.h"
00045
00046 using namespace Onikiri;
00047
00048 GShare::GShare()
00049 {
00050 m_core = 0;
00051 m_pht = 0;
00052
00053 m_globalHistoryBits = 0;
00054 m_pthIndexBits = 0;
00055
00056 m_numPred = 0;
00057 m_numHit = 0;
00058 m_numMiss = 0;
00059 m_numRetire = 0;
00060
00061 }
00062
00063 GShare::~GShare()
00064 {
00065 ReleaseParam();
00066 }
00067
00068 void GShare::Initialize(InitPhase phase)
00069 {
00070 if(phase == INIT_PRE_CONNECTION){
00071 LoadParam();
00072 }
00073 else if(phase == INIT_POST_CONNECTION){
00074
00075 CheckNodeInitialized( "core", m_core);
00076 CheckNodeInitialized( "globalHistory", m_globalHistory);
00077 CheckNodeInitialized( "pht", m_pht);
00078
00079
00080 m_predTable.Resize( *m_core->GetOpArray() );
00081
00082 m_pthIndexBits = m_pht->GetIndexBitSize();
00083 if(m_pthIndexBits < m_globalHistoryBits){
00084 THROW_RUNTIME_ERROR("PHT size is less than global history size.");
00085 }
00086 }
00087 }
00088
00089
00090 bool GShare::Predict(OpIterator op, PC predIndexPC)
00091 {
00092 ASSERT(
00093 op->GetTID() == predIndexPC.tid,
00094 "The tread ids of the op and current pc are different."
00095 );
00096
00097 ++m_numPred;
00098 int localTID = op->GetLocalTID();
00099 int phtIndex = GetPHTIndex( localTID, predIndexPC );
00100 bool taken = m_pht->Predict(phtIndex);
00101 m_globalHistory[localTID]->Predicted(taken);
00102
00103 PredInfo& info = m_predTable[op];
00104
00105
00106 info.phtIndex = phtIndex;
00107
00108
00109 info.direction = taken;
00110
00111 return taken;
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121 void GShare::Finished(OpIterator op)
00122 {
00123 PredInfo& info = m_predTable[op];
00124 bool taken = op->GetTaken();
00125 m_pht->Update(info.phtIndex, taken);
00126
00127
00128
00129
00130 if(info.direction != taken){
00131 m_globalHistory[op->GetLocalTID()]->SetLeastSignificantBit(taken);
00132 }
00133 }
00134
00135
00136 void GShare::Retired(OpIterator op)
00137 {
00138 bool taken = op->GetTaken();
00139
00140
00141 m_globalHistory[op->GetLocalTID()]->Retired( taken );
00142
00143
00144 if(m_predTable[op].direction == taken){
00145 ++m_numHit;
00146 }
00147 else{
00148 ++m_numMiss;
00149 }
00150
00151 ++m_numRetire;
00152 }
00153
00154
00155 int GShare::GetPHTIndex(int localThreadID, const PC& pc)
00156 {
00157
00158 u64 p = pc.address >> SimISAInfo::INSTRUCTION_WORD_BYTE_SHIFT;
00159
00160
00161 if(m_addrXORConvolute){
00162 p = shttl::xor_convolute(p, m_pthIndexBits);
00163 }
00164 else{
00165 p = p & shttl::mask(0, m_pthIndexBits);
00166 }
00167
00168 int pos = m_pthIndexBits - m_globalHistoryBits;
00169 u64 mask = shttl::mask(0, m_globalHistoryBits);
00170 u64 global = (m_globalHistory[localThreadID]->GetHistory() & mask) << pos;
00171 return (int)( p ^ global );
00172 }