Jump to content
  • Advertisement
Sign in to follow this  
beebs1

Branch Prediction

This topic is 2498 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya,

I remember reading some advice from the Intel manuals a few years ago, which said that usually x86-family processors assume that an if-branch would be taken when predicting instructions. Therefore, code that is written so that if-branches are taken most of the time may be more efficient.

Of course, there are bigger things to look for first when optimising, but does anyone know if this is still true today as an isolated statement?

If there are any gains to be made, I'd guess you would only see a difference if the majority of the branches were being predicted correctly. But still.

Any thoughts appreciated!

Cheers.

Share this post


Link to post
Share on other sites
Advertisement
This is far from a beginner's topic :)

Branch prediction is considerably more complex than just predicting all conditionals/loops as taken. There is usually a 'predictor', which is a few bits that track the direction that branches have taken in the past, and these are used to decide which way to predict the current branch... That's a gross over-simplification, and the details vary by processor architecture, but you get the general idea.

In an ideal world, the final optimisation pass of your compiler is taking this into account, but it depends on the complexity of the language/compiler. I wouldn't worry about it - the performance difference is minimal, except for in pathological cases.

Share this post


Link to post
Share on other sites
I definitely consider myself a beginner :)

That's interesting. The manuals are quite old (but not too ancient) - the NetBurst architecture. As far as I can tell the only prediction used was static, depending on whether the jmp target was forwards or backwards.

Seems things are considerably more involved on modern CPUs!

Thanks for quick replies and link :)

Share this post


Link to post
Share on other sites
You shouldn't have to worry about it. I'm sure that the branch prediction should be higher than 95% in modern computers. I'm not sure but I think most branch predictors take the environment of the code into account, which was shown to have branch prediction rate of higher than 98% coupled with other techniques. It doesn't hurt to know about these kind of stuff or at least have some vague idea( like me :) ) but don't worry about it. If you want speed improvements, then focus on choosing the correct data structure and algorithms instead of stuff like this. Take care!

regards D.C

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!