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:

    The lore of our fathers is a fabric of sentences.... It is a pale gray lore, black with fact and white with convention. But I have found no substantial reasons for concluding that there are any quite black threads in it, or any white ones.
    Willard Van Orman Quine (b. 1908)

    The source of Pyrrhonism comes from failing to distinguish between a demonstration, a proof and a probability. A demonstration supposes that the contradictory idea is impossible; a proof of fact is where all the reasons lead to belief, without there being any pretext for doubt; a probability is where the reasons for belief are stronger than those for doubting.
    Andrew Michael Ramsay (1686–1743)

    The classroom, with all its limitations, remains a location of possibility. In that field of possibility we have the opportunity to labor for freedom, to demand of ourselves and our comrades, an openness of mind and heart that allows us to face reality even as we collectively imagine ways to move beyond boundaries, to transgress. This is education as the practice of freedom.
    bell hooks (b. c. 1955)