What is the effect of ordering if…else if statements by probability?
As a general rule, most if not all Intel CPUs assume forward branches are not taken the first time they see them. See Godbolt’s work. After that, the branch goes into a branch prediction cache, and past behavior is used to inform future branch prediction. So in a tight loop, the effect of misordering is … Read more