-
Notifications
You must be signed in to change notification settings - Fork 104
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
Improve efficiency of branch history table #271
Conversation
It's worth mentioning that the check of the history table is changed to a static range [0, HISTORY_SIZE). I assume that it is impossible to branch to PC 0, so the condition |
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.
Right, the line 52 should be HISTORY_SIZE
, instead of ir->branch_table_count
. The other modification save 1 byte memory (maybe more bytes becasue of memory alignment) for non indirect jump instruction IR.
The error only occurs when jump target is PC 0, but it is not common. Other solution is initializing the PC array to an odd value because the odd jump target is impossible. |
af524d2
to
eafabd4
Compare
By the way, I am wondering which value should be chosen for |
Based on my observations, the majority of branch targets typically number less than 10. However, for certain hard-to-predict branches, the count exceeds 20. I believe the branch history table is tailored to enhance the performance of indirect jump instructions featuring a limited number of branch targets. Therefore, I propose that the value 16 is suited for this purpose. |
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.
Consider the following change for git commit message:
The previous implementation of the branch history table had some limitations that prevented us from fully leveraging its capabilities. This commit aims to improve access to recent history entries and make it more cache-friendly.
The previous implementation of the branch history table had some limitations that prevented us from fully leveraging its capabilities. This commit aims to improve access to recent history entries and make it more cache-friendly.
Actually I am thinking to optimize this with SIMD operation, and HISTORY_SIZE needs to be 8 consider 256 bits vector. But the idea seems to be a sledgehammer to crack a nut at the first glance. |
There are some small mistakes/defects in the original history table design:
ir->branch_table_count
, but we only check the range in [0,ir->branch_table_count
)ir->branch_table_count
rings back to index 0, the previous history will be dropped because we only check the range in [0,ir->branch_table_count
)PC
for every branch history entry can be put densely since they are the key for comparison, so they could be beneficial for cache and probably provide chance to optimize using SIMD operation