Compute the minimum or maximum of two integers without branching On some rare machines where branching is expensive, the below obvious approach to find minimum can be slow as it uses branching. /* The obvious approach to find minimum (involves branching) */ int min(int x, int y) { return (x < y) ? x : y } Below are the methods to get minimum(or maximum) without using branching. Typically, the obvious approach is best, though. Method 1(Use XOR and comparison operator) Minimum of x and y will be y ^ ((x ^ y) & -(x < y)) It works because if x < y, then -(x < y) will be all ones,
Read full article from Compute the minimum or maximum of two integers without branching | GeeksforGeeks