3 ms·
I am pretty sure it hurts you in the short run too. After all, the microcode probably does a register rename or the like with a normal swap, but has to actually
by kazagistar 10y ago
I am pretty sure it hurts you in the short run too. After all, the microcode probably does a register rename or the like with a normal swap, but has to actually burn cycles on using aritmetic for the xor swap.
- sverrirs 10y agoOn modern CPU architectures, the XOR technique can be slower than using a temporary variable to do swapping. One reason is that modern CPUs strive to execute instructions in parallel via instruction pipelines. In the XOR technique, the inputs to each operation depend on the results of the previous operation, so they must be executed in strictly sequential order, negating any benefits of instruction-level parallelism.[3] https://en.wikipedia.org/wiki/XOR_swap_algorithm#Reasons_for_avoidance_in_practice https://en.wikipedia.org/wiki/XOR_swap_algorithm#Reasons_for...