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:

    Youth does not require reasons for living, it only needs pretexts.
    José Ortega Y Gasset (1883–1955)

    It’s an old trick now, God knows, but it works every time. At the very moment women start to expand their place in the world, scientific studies deliver compelling reasons for them to stay home.
    Mary Kay Blakely (20th century)

    By practice and conviction formed,
    With ancient stubbornness ingrained,
    Although her body clung and swarmed,
    My own identity remained.
    Yvor Winters (1900–1968)