Skip to content
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

about Branch target buffer #15

Open
cool-ic opened this issue Nov 16, 2021 · 2 comments
Open

about Branch target buffer #15

cool-ic opened this issue Nov 16, 2021 · 2 comments

Comments

@cool-ic
Copy link

cool-ic commented Nov 16, 2021

I notice that your branch target buffer is a Register file, which have no read latency. So I got two question:

Is this a usual way to use Register file as BTB rather than use a block of sram?
And if we use sram, comparing to register file, there may be one cycle delay for read operation. I think the read delay disturb the design of branch prediction. How to handle it?

Best regards

@ultraembedded
Copy link
Owner

Good question! I’ve been thinking about this recently...

The Rocket and WD SweRV cores use flops for the BTB.
Those cores and this one use 28-32 fully associative BTB entries.
A larger SRAM based BTB would be possible, I think, but you would lose the fully associative capability, but it could be much bigger to compensate (and would be much more FPGA friendly).
As you note, there would be a read latency to deal with - the less than ideal workaround is to read ahead by one address and accept that following a predicted branch, the BTB would not be able to provide another prediction for one cycle.

I have been modelling various branch prediction designs, and it seems that a BTB with one cycle latency is indeed worse for various benchmarks, but it’s not terrible.

@stephenry
Copy link

@cool-ic There are varying sizes of BTB. Some CPU have an initial micro-BTB that is implemented in flops, and then have a secondary, larger BTB implemented in SRAM. It's not possible to lookup the second, larger BTB on a cycle-by-cycle basis, but nevertheless its presence allows for the branch target to be resolved earlier in the pipeline should the address miss in the micro-BTB (although not at the very start). You will only really see this for pipelines that have a couple of stages at the front-end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants