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:
“One of the many reasons for the bewildering and tragic character of human existence is the fact that social organization is at once necessary and fatal. Men are forever creating such organizations for their own convenience and forever finding themselves the victims of their home-made monsters.”
—Aldous Huxley (18941963)
“Write to the point: say immediately what you want to say most, even if it doesnt come first. There are three reasons for doing this. First, you will then have said it, even if nothing else gets said. Second, your readers will then have read it, even if they read no more. Third, having said it, you are likely to have to say something more, because you will have to explain and justify what you chose to say.”
—Bill Stott (b. 1940)
“Toddlers who dont learn gradually about disappointment lose their resilience through lack of practice in give-and-take with other peoples needs. They can become self-centered, demanding, and difficult to like or to be with.”
—Alicia F. Lieberman (20th century)