a ^= b
b ^= a
a ^= b
(Here ^ denotes bitwise XOR) a ^= (b & mask)
b ^= (a & mask)
a ^= (b & mask)
The in-place version of swap is generally discouraged because compilers are smart (https://stackoverflow.com/questions/36906/what-is-the-fastes...) but I do wonder whether the masking in swap_if obscures intent to the compiler enough to close the gap.