2bit_local.cc (8842:a02932e2e73d) | 2bit_local.cc (9480:d059f8a95a42) |
---|---|
1/* 2 * Copyright (c) 2004-2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 20 unchanged lines hidden (view full) --- 29 */ 30 31#include "base/intmath.hh" 32#include "base/misc.hh" 33#include "base/trace.hh" 34#include "cpu/pred/2bit_local.hh" 35#include "debug/Fetch.hh" 36 | 1/* 2 * Copyright (c) 2004-2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 20 unchanged lines hidden (view full) --- 29 */ 30 31#include "base/intmath.hh" 32#include "base/misc.hh" 33#include "base/trace.hh" 34#include "cpu/pred/2bit_local.hh" 35#include "debug/Fetch.hh" 36 |
37LocalBP::LocalBP(unsigned _localPredictorSize, 38 unsigned _localCtrBits, 39 unsigned _instShiftAmt) 40 : localPredictorSize(_localPredictorSize), 41 localCtrBits(_localCtrBits), 42 instShiftAmt(_instShiftAmt) | 37LocalBP::LocalBP(const Params *params) 38 : BPredUnit(params), 39 localPredictorSize(params->localPredictorSize), 40 localCtrBits(params->localCtrBits), 41 instShiftAmt(params->instShiftAmt) |
43{ 44 if (!isPowerOf2(localPredictorSize)) { 45 fatal("Invalid local predictor size!\n"); 46 } 47 48 localPredictorSets = localPredictorSize / localCtrBits; 49 50 if (!isPowerOf2(localPredictorSets)) { 51 fatal("Invalid number of local predictor sets! Check localCtrBits.\n"); 52 } 53 54 // Setup the index mask. 55 indexMask = localPredictorSets - 1; 56 | 42{ 43 if (!isPowerOf2(localPredictorSize)) { 44 fatal("Invalid local predictor size!\n"); 45 } 46 47 localPredictorSets = localPredictorSize / localCtrBits; 48 49 if (!isPowerOf2(localPredictorSets)) { 50 fatal("Invalid number of local predictor sets! Check localCtrBits.\n"); 51 } 52 53 // Setup the index mask. 54 indexMask = localPredictorSets - 1; 55 |
57 DPRINTF(Fetch, "Branch predictor: index mask: %#x\n", indexMask); | 56 DPRINTF(Fetch, "index mask: %#x\n", indexMask); |
58 59 // Setup the array of counters for the local predictor. 60 localCtrs.resize(localPredictorSets); 61 62 for (unsigned i = 0; i < localPredictorSets; ++i) | 57 58 // Setup the array of counters for the local predictor. 59 localCtrs.resize(localPredictorSets); 60 61 for (unsigned i = 0; i < localPredictorSets; ++i) |
63 localCtrs[i].setBits(_localCtrBits); | 62 localCtrs[i].setBits(localCtrBits); |
64 | 63 |
65 DPRINTF(Fetch, "Branch predictor: local predictor size: %i\n", | 64 DPRINTF(Fetch, "local predictor size: %i\n", |
66 localPredictorSize); 67 | 65 localPredictorSize); 66 |
68 DPRINTF(Fetch, "Branch predictor: local counter bits: %i\n", localCtrBits); | 67 DPRINTF(Fetch, "local counter bits: %i\n", localCtrBits); |
69 | 68 |
70 DPRINTF(Fetch, "Branch predictor: instruction shift amount: %i\n", | 69 DPRINTF(Fetch, "instruction shift amount: %i\n", |
71 instShiftAmt); 72} 73 74void 75LocalBP::reset() 76{ 77 for (unsigned i = 0; i < localPredictorSets; ++i) { 78 localCtrs[i].reset(); 79 } 80} 81 82void | 70 instShiftAmt); 71} 72 73void 74LocalBP::reset() 75{ 76 for (unsigned i = 0; i < localPredictorSets; ++i) { 77 localCtrs[i].reset(); 78 } 79} 80 81void |
83LocalBP::BTBUpdate(Addr &branch_addr, void * &bp_history) | 82LocalBP::btbUpdate(Addr branch_addr, void * &bp_history) |
84{ 85// Place holder for a function that is called to update predictor history when 86// a BTB entry is invalid or not found. 87} 88 89 90bool | 83{ 84// Place holder for a function that is called to update predictor history when 85// a BTB entry is invalid or not found. 86} 87 88 89bool |
91LocalBP::lookup(Addr &branch_addr, void * &bp_history) | 90LocalBP::lookup(Addr branch_addr, void * &bp_history) |
92{ 93 bool taken; 94 uint8_t counter_val; 95 unsigned local_predictor_idx = getLocalIndex(branch_addr); 96 | 91{ 92 bool taken; 93 uint8_t counter_val; 94 unsigned local_predictor_idx = getLocalIndex(branch_addr); 95 |
97 DPRINTF(Fetch, "Branch predictor: Looking up index %#x\n", | 96 DPRINTF(Fetch, "Looking up index %#x\n", |
98 local_predictor_idx); 99 100 counter_val = localCtrs[local_predictor_idx].read(); 101 | 97 local_predictor_idx); 98 99 counter_val = localCtrs[local_predictor_idx].read(); 100 |
102 DPRINTF(Fetch, "Branch predictor: prediction is %i.\n", | 101 DPRINTF(Fetch, "prediction is %i.\n", |
103 (int)counter_val); 104 105 taken = getPrediction(counter_val); 106 107#if 0 108 // Speculative update. 109 if (taken) { | 102 (int)counter_val); 103 104 taken = getPrediction(counter_val); 105 106#if 0 107 // Speculative update. 108 if (taken) { |
110 DPRINTF(Fetch, "Branch predictor: Branch updated as taken.\n"); | 109 DPRINTF(Fetch, "Branch updated as taken.\n"); |
111 localCtrs[local_predictor_idx].increment(); 112 } else { | 110 localCtrs[local_predictor_idx].increment(); 111 } else { |
113 DPRINTF(Fetch, "Branch predictor: Branch updated as not taken.\n"); | 112 DPRINTF(Fetch, "Branch updated as not taken.\n"); |
114 localCtrs[local_predictor_idx].decrement(); 115 } 116#endif 117 118 return taken; 119} 120 121void | 113 localCtrs[local_predictor_idx].decrement(); 114 } 115#endif 116 117 return taken; 118} 119 120void |
122LocalBP::update(Addr &branch_addr, bool taken, void *bp_history) | 121LocalBP::update(Addr branch_addr, bool taken, void *bp_history, bool squashed) |
123{ 124 assert(bp_history == NULL); 125 unsigned local_predictor_idx; 126 127 // Update the local predictor. 128 local_predictor_idx = getLocalIndex(branch_addr); 129 | 122{ 123 assert(bp_history == NULL); 124 unsigned local_predictor_idx; 125 126 // Update the local predictor. 127 local_predictor_idx = getLocalIndex(branch_addr); 128 |
130 DPRINTF(Fetch, "Branch predictor: Looking up index %#x\n", 131 local_predictor_idx); | 129 DPRINTF(Fetch, "Looking up index %#x\n", local_predictor_idx); |
132 133 if (taken) { | 130 131 if (taken) { |
134 DPRINTF(Fetch, "Branch predictor: Branch updated as taken.\n"); | 132 DPRINTF(Fetch, "Branch updated as taken.\n"); |
135 localCtrs[local_predictor_idx].increment(); 136 } else { | 133 localCtrs[local_predictor_idx].increment(); 134 } else { |
137 DPRINTF(Fetch, "Branch predictor: Branch updated as not taken.\n"); | 135 DPRINTF(Fetch, "Branch updated as not taken.\n"); |
138 localCtrs[local_predictor_idx].decrement(); 139 } 140} 141 142inline 143bool 144LocalBP::getPrediction(uint8_t &count) 145{ 146 // Get the MSB of the count 147 return (count >> (localCtrBits - 1)); 148} 149 150inline 151unsigned 152LocalBP::getLocalIndex(Addr &branch_addr) 153{ 154 return (branch_addr >> instShiftAmt) & indexMask; 155} | 136 localCtrs[local_predictor_idx].decrement(); 137 } 138} 139 140inline 141bool 142LocalBP::getPrediction(uint8_t &count) 143{ 144 // Get the MSB of the count 145 return (count >> (localCtrBits - 1)); 146} 147 148inline 149unsigned 150LocalBP::getLocalIndex(Addr &branch_addr) 151{ 152 return (branch_addr >> instShiftAmt) & indexMask; 153} |
154 155void 156LocalBP::uncondBranch(void *&bp_history) 157{ 158} |
|