Reasons For Use in Practice
In most practical scenarios, the trivial swap algorithm using a temporary register is more efficient. Limited situations in which XOR swapping may be practical include:
- On a processor where the instruction set encoding permits the XOR swap to be encoded in a smaller number of bytes;
- In a region with high register pressure, it may allow the register allocator to avoid spilling a register.
- In microcontrollers where available RAM is very limited.
Because these situations are rare, most optimizing compilers do not generate XOR swap code.
Read more about this topic: XOR Swap Algorithm
Famous quotes containing the words reasons for, reasons and/or practice:
“Happy the man who has been able to know the reasons for things.”
—Virgil [Publius Vergilius Maro] (7019 B.C.)
“The needs of a human being are sacred. Their satisfaction cannot be subordinated either to reasons of state, or to any consideration of money, nationality, race, or color, or to the moral or other value attributed to the human being in question, or to any consideration whatsoever.”
—Simone Weil (19091943)
“Kindness is a virtue neither modern nor urban. One almost unlearns it in a city. Towns have their own beatitude; they are not unfriendly; they offer a vast and solacing anonymity or an equally vast and solacing gregariousness. But one needs a neighbor on whom to practice compassion.”
—Phyllis McGinley (19051978)