As a novice in this area, it's not clear to me after reading this what exactly the 2-ahead branch predictor is.
Zen 5's 2-ahead branch predictor: how a 30 year old idea allows for new tricks
11–20 of 196 posts
Re: Zen 5's 2-ahead branch predictor: how a 30 year old idea allows for new tricks
#12that's probably bad idea but I would like to learn why: why when we have a conditional branch we cannot just fetch and prepare instructions for both possible branches and then discard the incorrect one? is this that much harder or there are other reasons that makes this not worth it
It's a huge waste of energy and in some cases it would even be slower because you'd execute more instructions overall. If the branch mispredict rate is around 1% it's simply not worth paying a penalty 99% of the time to get a gain 1% of the time. Maybe it would be worth doing on low-confidence branches.
Re: Zen 5's 2-ahead branch predictor: how a 30 year old idea allows for new tricks
#13that's probably bad idea but I would like to learn why: why when we have a conditional branch we cannot just fetch and prepare instructions for both possible branches and then discard the incorrect one? is this that much harder or there are other reasons that makes this not worth it
I think a lot of people don't have an intuition about how accurate branch prediction can be, but if you look at your own code, you'll quickly realize "well, yeah, control flow is almost always going to go this way and we just have this branch so we can handle the exceptional case" -- compilers can often deduce this pretty well themselves now, and cpus/jits/runtimes can develop some pretty impressive heuristics as well, and when all those fail you can often add explicit hints in your code that tell your compiler/etc what you expect if they can't guess.
Re: Zen 5's 2-ahead branch predictor: how a 30 year old idea allows for new tricks
#14that's probably bad idea but I would like to learn why: why when we have a conditional branch we cannot just fetch and prepare instructions for both possible branches and then discard the incorrect one? is this that much harder or there are other reasons that makes this not worth it
Transistor count; now you have to duplicate all the decode and speculative execution circuitry for both possible branches
Re: Zen 5's 2-ahead branch predictor: how a 30 year old idea allows for new tricks
#15Earlier quoted context omitted.
I sometimes wonder if there’s an academic career hidden in there for an engineer: go to the library and read what the CS folks were publishing on physical papers, maybe there are some ideas that can actually be implemented now that weren’t practical back then.
Yes, "read 10 year old papers as a source of ideas ripe for commercialization" IS common advice in universities.
Re: Zen 5's 2-ahead branch predictor: how a 30 year old idea allows for new tricks
#16that's probably bad idea but I would like to learn why: why when we have a conditional branch we cannot just fetch and prepare instructions for both possible branches and then discard the incorrect one? is this that much harder or there are other reasons that makes this not worth it
- Double the execution units; very expensive for wide vector units
- Massive waste of energy as half the resources will always be wasted no matter what
- Bad scaling, i.e. four branches ahead would require 16x the resources
Re: Zen 5's 2-ahead branch predictor: how a 30 year old idea allows for new tricks
#17As a novice in this area, it's not clear to me after reading this what exactly the 2-ahead branch predictor is.
You can check out the seminal paper linked in the article. Or start by summarizing the paper with Gemini, Claude, ChatGPT, etc. to get a high level overview (and then confirm the answer by reading the paper).
Re: Zen 5's 2-ahead branch predictor: how a 30 year old idea allows for new tricks
#18It's always interesting to see decades old papers, sometimes published with little to no fanfares, suddenly becomes "state of the art" because hardware have become powerful enough. For example Z-buffers[1]. It's used by 3d video games. When it's first published on paper, it's not even the main topic of the paper, just some side notes because it requires expensive amount of memory to run. Turn out megabytes is quite c…
I sometimes wonder if there’s an academic career hidden in there for an engineer: go to the library and read what the CS folks were publishing on physical papers, maybe there are some ideas that can actually be implemented now that weren’t practical back then.
Re: Zen 5's 2-ahead branch predictor: how a 30 year old idea allows for new tricks
#19that's probably bad idea but I would like to learn why: why when we have a conditional branch we cannot just fetch and prepare instructions for both possible branches and then discard the incorrect one? is this that much harder or there are other reasons that makes this not worth it
Re: Zen 5's 2-ahead branch predictor: how a 30 year old idea allows for new tricks
#20that's probably bad idea but I would like to learn why: why when we have a conditional branch we cannot just fetch and prepare instructions for both possible branches and then discard the incorrect one? is this that much harder or there are other reasons that makes this not worth it
We actually do that. It's called a GPU. And it sucks for general code.