bpred_unit.hh revision 1062
1 2#ifndef __BPRED_UNIT_HH__ 3#define __BPRED_UNIT_HH__ 4 5// For Addr type. 6#include "arch/alpha/isa_traits.hh" 7#include "base/statistics.hh" 8#include "cpu/inst_seq.hh" 9 10#include "cpu/beta_cpu/2bit_local_pred.hh" 11#include "cpu/beta_cpu/tournament_pred.hh" 12#include "cpu/beta_cpu/btb.hh" 13#include "cpu/beta_cpu/ras.hh" 14 15#include <list> 16 17/** 18 * Basically a wrapper class to hold both the branch predictor 19 * and the BTB. Right now I'm unsure of the implementation; it would 20 * be nicer to have something closer to the CPUPolicy or the Impl where 21 * this is just typedefs, but it forces the upper level stages to be 22 * aware of the constructors of the BP and the BTB. The nicer thing 23 * to do is have this templated on the Impl, accept the usual Params 24 * object, and be able to call the constructors on the BP and BTB. 25 */ 26template<class Impl> 27class TwobitBPredUnit 28{ 29 public: 30 typedef typename Impl::Params Params; 31 typedef typename Impl::DynInstPtr DynInstPtr; 32 33 TwobitBPredUnit(Params ¶ms); 34 35 void regStats(); 36 37 bool predict(DynInstPtr &inst, Addr &PC); 38 39 void squash(const InstSeqNum &squashed_sn, const Addr &corr_target, 40 bool actually_taken); 41 42 void squash(const InstSeqNum &squashed_sn); 43 44 void update(const InstSeqNum &done_sn); 45 46 bool BPLookup(Addr &inst_PC) 47 { return BP.lookup(inst_PC); } 48 49 unsigned BPReadGlobalHist() 50 { return 0; } 51 52 bool BTBValid(Addr &inst_PC) 53 { return BTB.valid(inst_PC); } 54 55 Addr BTBLookup(Addr &inst_PC) 56 { return BTB.lookup(inst_PC); } 57 58 // Will want to include global history. 59 void BPUpdate(Addr &inst_PC, unsigned global_history, bool taken) 60 { BP.update(inst_PC, taken); } 61 62 void BTBUpdate(Addr &inst_PC, Addr &target_PC) 63 { BTB.update(inst_PC, target_PC); } 64 65 private: 66 struct PredictorHistory { 67 PredictorHistory(const InstSeqNum &seq_num, const Addr &inst_PC, 68 const bool pred_taken) 69 : seqNum(seq_num), PC(inst_PC), predTaken(pred_taken), 70 globalHistory(0), usedRAS(0), wasCall(0), RASIndex(0), 71 RASTarget(0) 72 { } 73 74 InstSeqNum seqNum; 75 76 Addr PC; 77 78 bool predTaken; 79 80 unsigned globalHistory; 81 82 bool usedRAS; 83 84 bool wasCall; 85 86 unsigned RASIndex; 87 88 Addr RASTarget; 89 }; 90 91 std::list<PredictorHistory> predHist; 92 93 DefaultBP BP; 94 95 DefaultBTB BTB; 96 97 ReturnAddrStack RAS; 98 99 Stats::Scalar<> lookups; 100 Stats::Scalar<> condPredicted; 101 Stats::Scalar<> condIncorrect; 102 Stats::Scalar<> BTBLookups; 103 Stats::Scalar<> BTBHits; 104 Stats::Scalar<> BTBCorrect; 105 Stats::Scalar<> usedRAS; 106 Stats::Scalar<> RASIncorrect; 107}; 108 109#endif // __BPRED_UNIT_HH__ 110