# Node ID bce8444407d3eeb5a46e48e87a3ca8e1fa05f6b2 # Parent 32735260c87d0d56bc5fd46d3ad7271450dddb49 diff --git a/src/cpu/pred/bpred_unit.cc b/src/cpu/pred/bpred_unit.cc --- a/src/cpu/pred/bpred_unit.cc +++ b/src/cpu/pred/bpred_unit.cc @@ -59,7 +59,8 @@ predHist(numThreads), BTB(params->BTBEntries, params->BTBTagSize, - params->instShiftAmt), + params->instShiftAmt, + params->numThreads), RAS(numThreads), instShiftAmt(params->instShiftAmt) { diff --git a/src/cpu/pred/btb.hh b/src/cpu/pred/btb.hh --- a/src/cpu/pred/btb.hh +++ b/src/cpu/pred/btb.hh @@ -66,7 +66,7 @@ * @param instShiftAmt Offset amount for instructions to ignore alignment. */ DefaultBTB(unsigned numEntries, unsigned tagBits, - unsigned instShiftAmt); + unsigned instShiftAmt, unsigned numThreads); void reset(); @@ -97,7 +97,7 @@ * @param inst_PC The branch to look up. * @return Returns the index into the BTB. */ - inline unsigned getIndex(Addr instPC); + inline unsigned getIndex(Addr instPC, ThreadID tid); /** Returns the tag bits of a given address. * @param inst_PC The branch's address. @@ -125,6 +125,9 @@ /** Number of bits to shift PC when calculating tag. */ unsigned tagShiftAmt; + + /** Log2 NumThreads used for hashing threadid */ + unsigned log2NumThreads; }; #endif // __CPU_PRED_BTB_HH__ diff --git a/src/cpu/pred/btb.cc b/src/cpu/pred/btb.cc --- a/src/cpu/pred/btb.cc +++ b/src/cpu/pred/btb.cc @@ -35,10 +35,12 @@ DefaultBTB::DefaultBTB(unsigned _numEntries, unsigned _tagBits, - unsigned _instShiftAmt) + unsigned _instShiftAmt, + unsigned _num_threads) : numEntries(_numEntries), tagBits(_tagBits), - instShiftAmt(_instShiftAmt) + instShiftAmt(_instShiftAmt), + log2NumThreads(floorLog2(_num_threads)) { DPRINTF(Fetch, "BTB: Creating BTB object.\n"); @@ -69,10 +71,12 @@ inline unsigned -DefaultBTB::getIndex(Addr instPC) +DefaultBTB::getIndex(Addr instPC, ThreadID tid) { // Need to shift PC over by the word offset. - return (instPC >> instShiftAmt) & idxMask; + return ((instPC >> instShiftAmt) + ^ (tid << (tagShiftAmt - instShiftAmt - log2NumThreads))) + & idxMask; } inline @@ -85,7 +89,7 @@ bool DefaultBTB::valid(Addr instPC, ThreadID tid) { - unsigned btb_idx = getIndex(instPC); + unsigned btb_idx = getIndex(instPC, tid); Addr inst_tag = getTag(instPC); @@ -106,7 +110,7 @@ TheISA::PCState DefaultBTB::lookup(Addr instPC, ThreadID tid) { - unsigned btb_idx = getIndex(instPC); + unsigned btb_idx = getIndex(instPC, tid); Addr inst_tag = getTag(instPC); @@ -124,7 +128,7 @@ void DefaultBTB::update(Addr instPC, const TheISA::PCState &target, ThreadID tid) { - unsigned btb_idx = getIndex(instPC); + unsigned btb_idx = getIndex(instPC, tid); assert(btb_idx < numEntries);