News for hackers. Stuff that matters.
Re:Round a direction vector to an 8-way compass by adrian_b on Monday July 25, 2022 @11:40AM (#32225930)
As written, the compiler can implement the "if"s with conditional move instructions and that would be faster than with conditional branches, as those would be hard to predict in this case.

Using "else if" is a valid optimization in general, but not necessarily when your target is a branchless program. Using "else if" may help in some cases, but you must have in mind exactly which CMOV instructions will be generated by the compiler, to be sure that there is any improvement, i.e. any reduction in the total number of CMOV instructions, and that you are not increasing the length of some chains of dependent instructions (leading to a greater latency).

There are no comments on this comment yet.