5 ms·
Wow, thanks for the link. I'd never heard of sorting networks before. The first thing I thought of was "use an XOR swap to cut memory accesses"...
by skimbrel 15y ago
Wow, thanks for the link. I'd never heard of sorting networks before. The first thing I thought of was "use an XOR swap to cut memory accesses"...
- onemoreact 15y agoI don't think that optimization helps when you have a spare register to use as a temp value.
- rpearl 15y agoIf you do the naive implementation: int temp = x; x = y; y = temp; Then a sufficiently smart compiler can decide to assign, say, %eax to x and %ebx to y, and then just rename its notion of registers, and after the swap just begin using %ebx for x and %eax for y. A swap with no copies at all! (It won't do this in every case, and it depends on context, but such an optimization is possible... but not with xor swaps.)
- eru 15y agoAt least xor swaps would need an even smarter compiler.