-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation of branch prediction using a BTB #124
Initial implementation of branch prediction using a BTB #124
Conversation
This is awesome! Thanks for putting this together. I'll check it out in more detail in a bit. I did take a few minutes at lunch to address your first POI:
I ran your branch through Apple's Instruments and found that |
Yeah, if you add (untested) this line to the bottom of
|
core/BTB.hpp
Outdated
void reset(uint64_t addr) | ||
{ | ||
setValid(true); | ||
setAddr(addr); | ||
resetLHistCounter_(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never been a fan of reset
methods. Instead, you can do this after adding a new constructor that accepts an address:
btb_entries_[idx] = BTBEntry(addr);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I can do this (unless I'm not understanding something, fairly new to C++).
The problem is that we're using the Cache and BasicCacheSet as the underlying data structures. The BTB acts as a shim.
The Cache returns pointers to the BTBEntry objects stored within a vector inside BasicCacheSet, the user can then manipulate the object using the pointer, but there isn't a way to put a new object into the vector down in the Set class.
Is there a way I can use the constructor you suggested to copy into the pointer object on the RHS?
(I tried to experiment a bit, but couldn't get the syntax right - complains that the btb_entry is a pointer and if use new then I think you'd get a memory leak?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious on your experiment...
Anyway, this would work to "replace" or reset the object deep in the guts of the cache, me thinks (forgive the pseudo code):
auto entry_ptr = cache->getEntry();
*entry_ptr = BTBEntry();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the API, I suggest you don't use references as the parameters, but instead use pointers:
(const BTBEntry * line)
Reason for this, look at this example of buggy code:
auto btb_entry = btb_->getEntry();
doSomeStuffToUpdateEntry_(&btb_entry);
Does getEntry
return reference or a copy? The auto
might make a copy and the call to doSomeStuffToUpdateEntry_
will not update the original.
core/Rename.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the changes here reset the entirety of rename, preventing support for partial flushes. 🤔 -- would you be up to updating the flushing criteria to include those instructions being flushed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Early branch misprediction recovery could be done at a later date, but will require some more complex mechanism for restoring rename map before restarting.
Ah, you already mentioned this...
Thank you for initiating this. To provide more history, per previous discussion, we intend to add branch prediction support via an API, along with an implementation of simple branch predictor. This would enable use of a simple predictor while allowing for implementation of other predictors. There's also an interest in re-using existing branch predictor implementations Please see #1 I will start a discussion item on this topic. Let's collaborate via the discussion thread and review a proposal for branch prediction API |
From our discussion in the SIG yesterday:
|
Updated branch to walk the ROB when restoring the rename map table following a flush, to fix the hack I did in the previous commit, and in anticipation of adding execute redirect on branch misprediction.
On the last point, moving ROB allocation to rename isn't the only solution, and even now it requires that the ROB is updated before the flush creating a constraint on the reorder buffer write port being scheduled on the PortUpdate phase with a 1 cycle delay.
I'm sure there are more (better) ideas out there.. |
Moving forward following the discussion in our last meeting on the 20th of December. I think we should separate out the changes needed for flushing. Then rebase the branch prediction API branch on top of it and close this PR |
Attempting to add some branch prediction logic to Olympia. I started with a branch target buffer.
Plan is to add a simple predictor, and a return address stack next. As this will require some form of recovery following speculative updates. Forming a foundation for further branch prediction modelling.
Early branch misprediction recovery could be done at a later date, but will require some more complex mechanism for restoring rename map before restarting.
Few points of interest: