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)
“Whenever we approve, we can find a hundred good reasons to justify our approbation. Whenever we dislike, we can find a thousand to justify our dislike.”
—Samuel Richardson (16891761)
“Fine art, that exists for itself alone, is art in a final state of impotence. If nobody, including the artist, acknowledges art as a means of knowing the world, then art is relegated to a kind of rumpus room of the mind and the irresponsibility of the artist and the irrelevance of art to actual living becomes part and parcel of the practice of art.”
—Angela Carter (19401992)