KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
When I'm writing some tight loop that needs to work fast I am often bothered by thoughts about how the processor branch prediction is going to behave. For instance I try my best to avoid having an if statement in the most inner loop, especially one with a result which is not somewhat uniform (say evaluates to true or false randomly). I tend to do that because of the somewhat common knowledge that the processor pre-fetches instructions and if it turned out that it mis-predicted a branch then the pre-fetch is useless. My question is - Is this really an issue with modern processors? How good can branch prediction expected to be? What coding patterns can be used to make it better? (For the sake of the discussion, assume that I am beyond the "early-optimization is the root of all evil" phase)
Tags (comma-separated)
Save Edits
Cancel