<p>I want to swap two integers, and I want to know which of these two implementations will be faster:
The obvious way with a temp variable:</p>

<pre><code>void swap(int* a, int* b)
{
    int temp = *a;
    *a = *b;
    *b = temp;
}
</code></pre>

<p>Or the xor version that I'm sure most people have seen:</p>

<pre><code>void swap(int* a, int* b)
{
    *a ^= *b;
    *b ^= *a;
    *a ^= *b;
}
</code></pre>

<p>It seems like the first uses an extra register, but the second one is doing three loads and stores while the first only does two of each.  Can someone tell me which is faster and why?  The why being more important.</p>

Number 2 is often quoted as being the "clever" way of doing it. It is in fact most likely slower as it obscures the explicit aim of the programmer - swapping two variables. This means that a compiler can't optimize it to use the actual assembler ops to swap. It also assumes the ability to do a bitwise xor on the objects.
Stick to number 1, it's the most generic and most understandable swap and can be easily templated/genericized.
This wikipedia section explains the issues quite well:
http://en.wikipedia.org/wiki/XOR_swap_algorithm#Reasons_for_avoidance_in_practice