summaryrefslogtreecommitdiff
path: root/src/cpu/pred/btb.cc
diff options
context:
space:
mode:
authorMitch Hayenga <mitch.hayenga@arm.com>2016-04-05 11:44:27 -0500
committerMitch Hayenga <mitch.hayenga@arm.com>2016-04-05 11:44:27 -0500
commit7bc52af7716168baa5deb28bb88475ddbba5d62a (patch)
tree23cf6a6c94e8386b2c64c210a4a9e6962234faf8 /src/cpu/pred/btb.cc
parentf902c0218ae3a8df558f1427302fbf0931b8f7d7 (diff)
downloadgem5-7bc52af7716168baa5deb28bb88475ddbba5d62a.tar.xz
cpu: Fix BTB threading oversight
The extant BTB code doesn't hash on the thread id but does check the thread id for 'btb hits'. This results in 1-thread of a multi-threaded workload taking a BTB entry, and all other threads missing for the same branch missing.
Diffstat (limited to 'src/cpu/pred/btb.cc')
-rw-r--r--src/cpu/pred/btb.cc18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/cpu/pred/btb.cc b/src/cpu/pred/btb.cc
index 393e52ccf..c7ef1959f 100644
--- 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 @@ DefaultBTB::reset()
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 @@ DefaultBTB::getTag(Addr instPC)
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 @@ DefaultBTB::valid(Addr instPC, ThreadID tid)
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 @@ DefaultBTB::lookup(Addr instPC, ThreadID tid)
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);