XOR Swap Algorithm - Reasons For Use in Practice

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 great reasons for the popularity of strikes is that they give the suppressed self a sense of power. For once the human tool knows itself a man, able to stand up and speak a word or strike a blow.
    Charles Horton Cooley (1864–1929)

    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 (1894–1963)

    Know how to be content and you will never be disgraced; practice self-restraint and you will never be in danger.
    —Chinese proverb.

    Laozi.