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:

    Here we also see: what this divinity lacks is not only a sense of shame—and there are also other reasons for conjecturing that in several respects all of the gods could learn from us humans. We humans are—more humane.
    Friedrich Nietzsche (1844–1900)

    Happy the man who has been able to know the reasons for things.
    Virgil [Publius Vergilius Maro] (70–19 B.C.)

    Certainly, young children can begin to practice making letters and numbers and solving problems, but this should be done without workbooks. Young children need to learn initiative, autonomy, industry, and competence before they learn that answers can be right or wrong.
    David Elkind (20th century)