tournament.hh revision 1684
1#ifndef __CPU_BETA_CPU_TOURNAMENT_PRED_HH__ 2#define __CPU_BETA_CPU_TOURNAMENT_PRED_HH__ 3 4// For Addr type. 5#include "arch/alpha/isa_traits.hh" 6#include "cpu/beta_cpu/sat_counter.hh" 7 8class TournamentBP 9{ 10 public: 11 /** 12 * Default branch predictor constructor. 13 */ 14 TournamentBP(unsigned local_predictor_size, 15 unsigned local_ctr_bits, 16 unsigned local_history_table_size, 17 unsigned local_history_bits, 18 unsigned global_predictor_size, 19 unsigned global_history_bits, 20 unsigned global_ctr_bits, 21 unsigned choice_predictor_size, 22 unsigned choice_ctr_bits, 23 unsigned instShiftAmt); 24 25 /** 26 * Looks up the given address in the branch predictor and returns 27 * a true/false value as to whether it is taken. 28 * @param branch_addr The address of the branch to look up. 29 * @return Whether or not the branch is taken. 30 */ 31 bool lookup(Addr &branch_addr); 32 33 /** 34 * Updates the branch predictor with the actual result of a branch. 35 * @param branch_addr The address of the branch to update. 36 * @param taken Whether or not the branch was taken. 37 */ 38 void update(Addr &branch_addr, unsigned global_history, bool taken); 39 40 inline unsigned readGlobalHist() { return globalHistory; } 41 42 private: 43 44 inline bool getPrediction(uint8_t &count); 45 46 inline unsigned calcLocHistIdx(Addr &branch_addr); 47 48 inline void updateHistoriesTaken(unsigned local_history_idx); 49 50 inline void updateHistoriesNotTaken(unsigned local_history_idx); 51 52 /** Local counters. */ 53 SatCounter *localCtrs; 54 55 /** Size of the local predictor. */ 56 unsigned localPredictorSize; 57 58 /** Number of bits of the local predictor's counters. */ 59 unsigned localCtrBits; 60 61 /** Array of local history table entries. */ 62 unsigned *localHistoryTable; 63 64 /** Size of the local history table. */ 65 unsigned localHistoryTableSize; 66 67 /** Number of bits for each entry of the local history table. 68 * @todo Doesn't this come from the size of the local predictor? 69 */ 70 unsigned localHistoryBits; 71 72 /** Mask to get the proper local history. */ 73 unsigned localHistoryMask; 74 75 76 /** Array of counters that make up the global predictor. */ 77 SatCounter *globalCtrs; 78 79 /** Size of the global predictor. */ 80 unsigned globalPredictorSize; 81 82 /** Number of bits of the global predictor's counters. */ 83 unsigned globalCtrBits; 84 85 /** Global history register. */ 86 unsigned globalHistory; 87 88 /** Number of bits for the global history. */ 89 unsigned globalHistoryBits; 90 91 /** Mask to get the proper global history. */ 92 unsigned globalHistoryMask; 93 94 95 /** Array of counters that make up the choice predictor. */ 96 SatCounter *choiceCtrs; 97 98 /** Size of the choice predictor (identical to the global predictor). */ 99 unsigned choicePredictorSize; 100 101 /** Number of bits of the choice predictor's counters. */ 102 unsigned choiceCtrBits; 103 104 /** Number of bits to shift the instruction over to get rid of the word 105 * offset. 106 */ 107 unsigned instShiftAmt; 108 109 /** Threshold for the counter value; above the threshold is taken, 110 * equal to or below the threshold is not taken. 111 */ 112 unsigned threshold; 113}; 114 115#endif // __CPU_BETA_CPU_TOURNAMENT_PRED_HH__ 116