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");
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
bool
DefaultBTB::valid(Addr instPC, ThreadID tid)
{
- unsigned btb_idx = getIndex(instPC);
+ unsigned btb_idx = getIndex(instPC, tid);
Addr inst_tag = getTag(instPC);
TheISA::PCState
DefaultBTB::lookup(Addr instPC, ThreadID tid)
{
- unsigned btb_idx = getIndex(instPC);
+ unsigned btb_idx = getIndex(instPC, tid);
Addr inst_tag = getTag(instPC);
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);
* @param instShiftAmt Offset amount for instructions to ignore alignment.
*/
DefaultBTB(unsigned numEntries, unsigned tagBits,
- unsigned instShiftAmt);
+ unsigned instShiftAmt, unsigned numThreads);
void reset();
* @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.
/** Number of bits to shift PC when calculating tag. */
unsigned tagShiftAmt;
+
+ /** Log2 NumThreads used for hashing threadid */
+ unsigned log2NumThreads;
};
#endif // __CPU_PRED_BTB_HH__