src/Samples/SampleBPred.h

説明を見る。
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 //
00033 // This is a sample class to demonstrate how to implement 
00034 // a branch predictor module.
00035 // You can activate this class by defining USE_SAMPLE_BPRED in this file.
00036 //
00037 
00038 #ifndef SAMPLES_SAMPLE_BPRED_H
00039 #define SAMPLES_SAMPLE_BPRED_H
00040 
00041 // USE_SAMPLE_BPRED is referred in this file, 'User/UserResourceMap.h' 
00042 // and  'User/UserInit.h'.
00043 //#define USE_SAMPLE_BPRED 1
00044 
00045 
00046 #include "Sim/Foundation/Resource/ResourceNode.h"
00047 #include "Sim/Predictor/BPred/DirPredIF.h"
00048 
00049 // All Onikiri classes are placed in a 'Onikiri' namespace.
00050 namespace Onikiri
00051 {
00052     class Core;
00053 
00054     class SampleAlwaysHitBrDirPredictor : 
00055         public PhysicalResourceNode,
00056         public DirPredIF
00057     {
00058     public:
00059 
00060         SampleAlwaysHitBrDirPredictor() : 
00061             m_enableCount( false ),
00062             m_numPredicted( 0 ),
00063             m_core( 0 )
00064         {
00065         }
00066 
00067         virtual ~SampleAlwaysHitBrDirPredictor()
00068         {
00069         }
00070 
00071         //
00072         // --- PhysicalResourceNode
00073         // Initialize and Finalize must be implemented.
00074         //
00075         virtual void Initialize( InitPhase phase )
00076         {
00077             if( phase == INIT_PRE_CONNECTION ){
00078 
00079                 // After constructing and before object connection.
00080                 // LoadParam() must be called in this phase or later.
00081                 LoadParam();
00082 
00083             }
00084             else if ( phase == INIT_POST_CONNECTION ){
00085 
00086                 // After connection
00087                 if( m_core == NULL ){
00088                     THROW_RUNTIME_ERROR( "'m_core' is not connected correctly." );
00089                 }
00090 
00091             }
00092         }
00093         virtual void Finalize()
00094         {
00095             ReleaseParam();
00096         }
00097 
00098         // Parameter & resource map.
00099         // These contents in this map are bound to XML in SampleDefaultParam.h.
00100         BEGIN_PARAM_MAP("")
00101             BEGIN_PARAM_PATH( GetParamPath() )
00102                 PARAM_ENTRY( "@EnableCount", m_enableCount )
00103             END_PARAM_PATH()
00104             BEGIN_PARAM_PATH( GetResultPath() )
00105                 PARAM_ENTRY( "@NumPredicted", m_numPredicted )
00106             END_PARAM_PATH()
00107         END_PARAM_MAP()
00108 
00109         BEGIN_RESOURCE_MAP()
00110             RESOURCE_ENTRY( Core, "core", m_core )
00111         END_RESOURCE_MAP()
00112 
00113         //
00114         // --- DirPredIF
00115         //
00116         virtual bool Predict(  OpIterator op, PC pc )
00117         {
00118             if( m_enableCount ){
00119                 m_numPredicted++;
00120             }
00121 
00122             return true;    // Always predicted to hit.
00123         }
00124         virtual void Finished( OpIterator op ){}
00125         virtual void Retired(  OpIterator op ){}
00126 
00127 
00128 
00129     private:
00130         bool  m_enableCount;
00131         s64   m_numPredicted;
00132         Core* m_core;
00133     };
00134 
00135 
00136 #ifdef USE_SAMPLE_BPRED
00137 
00138     //
00139     // Default parameters and connections for SampleAlwaysHitBrDirPredictor.
00140     // This XML overwrite XML in DefaultParam.xml.
00141     //
00142 
00143     static const char g_sampleBPredDefaultParam[] = "   \n\
00144                                                     \n\
00145     <?xml version='1.0' encoding='UTF-8'?>          \n\
00146     <Session>                                       \n\
00147                                                     \n\
00148       <Simulator>                                   \n\
00149         <Configurations>                            \n\
00150           <DefaultConfiguration>                    \n\
00151                                                     \n\
00152             <Structure>                             \n\
00153               <Copy>                                \n\
00154                                                     \n\
00155                 <SampleAlwaysHitBrDirPredictor      \n\
00156                   Count = 'CoreCount'               \n\
00157                   Name  = 'sampleBPred'             \n\
00158                 >                                   \n\
00159                   <Core Name = 'core' />            \n\
00160                 </SampleAlwaysHitBrDirPredictor>    \n\
00161                                                     \n\
00162                 <BPred Name = 'bPred'>              \n\
00163                   <Connection Name='sampleBPred' To='dirPred'/> \n\
00164                 </BPred>                            \n\
00165                                                     \n\
00166               </Copy>                               \n\
00167             </Structure>                            \n\
00168                                                     \n\
00169             <Parameter>                             \n\
00170                                                     \n\
00171               <SampleAlwaysHitBrDirPredictor        \n\
00172                 EnableCount = '1'                   \n\
00173                 Name  = 'sampleBPred'               \n\
00174               >                                     \n\
00175               </SampleAlwaysHitBrDirPredictor>      \n\
00176                                                     \n\
00177             </Parameter>                            \n\
00178           </DefaultConfiguration>                   \n\
00179         </Configurations>                           \n\
00180       </Simulator>                                  \n\
00181                                                     \n\
00182     </Session>                                      \n\
00183                                                     \n\
00184                                                     \n\
00185     ";
00186 #endif // #ifdef USE_SAMPLE_BPRED
00187 
00188 }   // namespace Onikiri
00189 
00190 
00191 #endif// #ifndef SAMPLES_SAMPLE_BPRED_H

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