src/Sim/Predictor/BPred/BTB.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 #include "Sim/Predictor/BPred/BTB.h"
00034 #include "Sim/Foundation/SimPC.h"
00035 #include "Sim/Op/Op.h"
00036 
00037 using namespace Onikiri;
00038 using namespace std;
00039 
00040 BTB::BTB()
00041 {
00042     m_numEntryBits  = 0;
00043     m_numWays       = 0;
00044 
00045     m_numPred       = 0;
00046     m_numTableHit   = 0;
00047     m_numTableMiss  = 0;
00048     m_numUpdate     = 0;
00049     m_numEntries    = 0;
00050     m_numHit        = 0;
00051     m_numMiss       = 0;
00052     m_table         = 0;
00053 }
00054 
00055 BTB::~BTB()
00056 {
00057     if(m_table != 0)
00058         delete m_table;
00059 
00060     m_numEntries    = (1 << m_numEntryBits); // entry count
00061     ReleaseParam();
00062 }
00063 
00064 void BTB::Initialize(InitPhase phase)
00065 {
00066     if(phase == INIT_PRE_CONNECTION){
00067         LoadParam();
00068         m_table = 
00069             new SetAssocTableType( HasherType(m_numEntryBits), m_numWays);
00070     }
00071 }
00072 
00073 // lookup BTB
00074 BTBPredict BTB::Predict(const PC& pc)
00075 {
00076     BTBPredict pred = {pc, pc, BT_NON ,false};
00077     ++m_numPred;
00078 
00079     // BTBPredict::hit is determined by a result of reading the table.
00080     // Cannot use a result of reading the table.
00081     pred.hit = m_table->read( pc.address, &pred ) != m_table->end();
00082     if( pred.hit ){
00083         m_numTableHit++;
00084     }
00085     else{
00086         m_numTableMiss++;
00087     }
00088 
00089     return pred;
00090 }
00091 
00092 // update BTB
00093 void BTB::Update(const OpIterator& op, const BTBPredict& predict)
00094 {
00095     if(!op->GetTaken())
00096         return;
00097 
00098 
00099     const OpClass& opClass = op->GetOpClass();
00100     bool conditinal = opClass.IsConditionalBranch();
00101     BranchTypeUtility util;
00102 
00103     // Branch result
00104     BTBPredict result;
00105     result.predIndexPC = predict.predIndexPC;
00106     result.hit         = true;
00107     result.target      = op->GetTakenPC();
00108     result.dirPredict  = conditinal;
00109     result.type        = util.OpClassToBranchType( opClass );
00110 
00111     ASSERT( result.type != BT_NON, "BTB must be updated by branch op." );
00112 
00113     //
00114     // Update table if 'op' is branch and branch is taken.
00115     // (Unconditional branch is always 'taken'.
00116     //
00117     m_table->write(result.predIndexPC.address, result);
00118     ++m_numUpdate;
00119 
00120     // 
00121     // BTB hit rate calculated from :
00122     // total : count of updating BTB
00123     // hit   : count of predicting correct target address
00124     //
00125     if(predict.hit && result.target == predict.target)
00126         ++m_numHit;
00127     else
00128         ++m_numMiss;
00129     
00130 }

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