src/Sim/Predictor/BPred/GShare.cpp

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
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(); // m_jBitSize, m_kBitSize
00072     }
00073     else if(phase == INIT_POST_CONNECTION){
00074         // o`FbN
00075         CheckNodeInitialized( "core", m_core);
00076         CheckNodeInitialized( "globalHistory", m_globalHistory);
00077         CheckNodeInitialized( "pht", m_pht);
00078 
00079         // table 
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     // XV pht index o
00106     info.phtIndex  = phtIndex;
00107 
00108     // Hit/MissA\o
00109     info.direction = taken;
00110 
00111     return taken;
00112 }
00113 
00114 //
00115 // タs
00116 // タs\
00117 // A\
00118 //
00119 // opタsPHTUpdates
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     // \MissIGlobalHistoryrbgX
00128     // GShare::Finished`FbN|Cg
00129     // Irbg~Xrbg
00130     if(info.direction != taken){
00131         m_globalHistory[op->GetLocalTID()]->SetLeastSignificantBit(taken);
00132     }
00133 }
00134 
00135 // opretire
00136 void GShare::Retired(OpIterator op)
00137 {
00138     bool taken = op->GetTaken();
00139 
00140     // CheckpointGlobalHistoryCommitupdate
00141     m_globalHistory[op->GetLocalTID()]->Retired( taken ); 
00142 
00143     // \Hit/Miss
00144     if(m_predTable[op].direction == taken){
00145         ++m_numHit;
00146     } 
00147     else{
00148         ++m_numMiss;
00149     }
00150 
00151     ++m_numRetire;
00152 }
00153 
00154 // PCPHTCfbNX
00155 int GShare::GetPHTIndex(int localThreadID, const PC& pc)
00156 {
00157     // pc rbgフ
00158     u64 p = pc.address >> SimISAInfo::INSTRUCTION_WORD_BYTE_SHIFT;
00159 
00160     // p  jBit + kBit o
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 }

Onikiri2に対してTue Jun 18 14:34:25 2013に生成されました。  doxygen 1.4.7