I just searched for similar things for a time-critical loop in my embedded application. One interesting thing I found is code like this
bit = (a<b);
still generating instructions on my platform (TI F2812). It seems that the compiler has no direct way to move the state flag from comparison to register, so instead something is created like
temp_register = 0 cmp a,b branch to label if LT temp_register = 1 label: bit = temp_register
However, the processor has built-in max and min operators. Since branching is quite expensive, this code is faster:
bit = min(max((ba),0),1);
The result max will only be nonzero if a <b. And then min converts any nonzero value to 1.
This is a very specific processor and may not be used on the X86 at all.
source share