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:
“While there are practical and sometimes moral reasons for the decomposition of the family, it coincides neither with what most people in society say they desire nor, especially in the case of children, with their best interests.”
—Robert Neelly Bellah (20th century)
“I should like to know what is the proper function of women, if it is not to make reasons for husbands to stay at home, and still stronger reasons for bachelors to go out.”
—George Eliot [Mary Ann (or Marian)
“A little instruction in the elements of chartographya little practice in the use of the compass and the spirit level, a topographical map of the town common, an excursion with a road mapwould have given me a fat round earth in place of my paper ghost.”
—Mary Antin (18811949)