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:

    It seems to me that we have to draw the line in sibling rivalry whenever rivalry goes out of bounds into destructive behavior of a physical or verbal kind. The principle needs to be this: Whatever the reasons for your feelings you will have to find civilized solutions.
    Selma H. Fraiberg (20th century)

    It seems to me that we have to draw the line in sibling rivalry whenever rivalry goes out of bounds into destructive behavior of a physical or verbal kind. The principle needs to be this: Whatever the reasons for your feelings you will have to find civilized solutions.
    Selma H. Fraiberg (20th century)

    Children also need opportunities to practice being less than perfect. They can afford to be ill tempered with us because it is our love that is most constant. This is the essence of unconditional love.... Our steadfast love provides a safe haven.
    Cathy Rindner Tempelsman (20th century)