3 ms·
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 h
by adrian_b 4y ago
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).