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:

    Could truth perhaps be a woman who has reasons for not permitting her reasons to be seen? Could her name perhaps be—to speak Greek—Baubo?... Oh, those Greeks! They understood how to live: to do that it is necessary to stop bravely at the surface, the fold, the skin, to adore the appearance, to believe in forms, in tones, in words, in the whole Olympus of appearance! Those Greeks were superficial—out of profundity!
    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.)

    We black women must forgive black men for not protecting us against slavery, racism, white men, our confusion, their doubts. And black men must forgive black women for our own sometimes dubious choices, divided loyalties, and lack of belief in their possibilities. Only when our sons and our daughters know that forgiveness is real, existent, and that those who love them practice it, can they form bonds as men and women that really can save and change our community.
    Marita Golden, educator, author. Saving Our Sons, p. 188, Doubleday (1995)