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 reasons for the failure of feminism to dislodge deeply held perceptions of male and female behaviour was its insistence that women were victims, and men powerful patriarchs, which made a travesty of ordinary people’s experience of the mutual interdependence of men and women.
    Rosalind Coward (b. 1953)

    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)

    She, too, would now swim down the river of matrimony with a beautiful name, and a handle to it, as the owner of a fine family property. Women’s rights was an excellent doctrine to preach, but for practice could not stand the strain of such temptation.
    Anthony Trollope (1815–1882)