Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

On 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...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: