- C := A xor B
- C := 0 if condition is not true
- A := A xor C
- B := B xor C
Here is a sample x86 code, where condition is value of CF:
sbb edx, edx ; part of step 2. - edx = 0xffffff if CF=1, 0x000000 otherwise mov ecx, eax xor ecx, ebx ; step 1 and ecx, edx ; completed step 2. - now C is 0 or (A xor B) xor eax, ecx ; step 3 xor ebx, ecx ; step 4
Branchless moves are possible in Pentium Pro and higher with instructions cmovcc.
See also XOR linked list.