By: Jörn Engel (joern.delete@this.purestorage.com), April 1, 2021 9:15 pm
Room: Moderated Discussions
Linus Torvalds (torvalds.delete@this.linux-foundation.org) on April 1, 2021 10:00 am wrote:
>
> So if the static prediction by the compiler isn't good enough, you have three choices:
>
> (a) don't predict at all (outside of the truly obvious case where the compiler can see "this has no
> chance at all"), and take the failure case every time (or at least quite often), go to the slow case
>
> (b) add dynamic prediction in software
>
> (c) do the dynamic prediction in hardware.
I think it is even worse than that. If I had to do the prediction in software, how would I do that? Maybe default to using TM, count how often that failed and eventually switch to not using TM, ok. But now something changes and it would make sense to use TM again - how do I even notice?
With branch predictors, it is easy to tell that you got it wrong. With TM you can only tell that using TM was not, but you never know if not using TM was wrong. Simply trying it against everything your predictor tells you is the only way you would ever notice. Should I do an explicit mispredict every 1000 iterations just to check if the situation has changed?
That problem doesn't get any easier if prediction happens in hardware.
>
> So if the static prediction by the compiler isn't good enough, you have three choices:
>
> (a) don't predict at all (outside of the truly obvious case where the compiler can see "this has no
> chance at all"), and take the failure case every time (or at least quite often), go to the slow case
>
> (b) add dynamic prediction in software
>
> (c) do the dynamic prediction in hardware.
I think it is even worse than that. If I had to do the prediction in software, how would I do that? Maybe default to using TM, count how often that failed and eventually switch to not using TM, ok. But now something changes and it would make sense to use TM again - how do I even notice?
With branch predictors, it is easy to tell that you got it wrong. With TM you can only tell that using TM was not, but you never know if not using TM was wrong. Simply trying it against everything your predictor tells you is the only way you would ever notice. Should I do an explicit mispredict every 1000 iterations just to check if the situation has changed?
That problem doesn't get any easier if prediction happens in hardware.