3 ms·
xor swap trick was useful in older simd (sse1/sse2) when based on some condition you want to swap values or not: tmp = (a ^ b) & mask a ^= tmp b ^= tmp
by mmozeiko 6mo ago
xor swap trick was useful in older simd (sse1/sse2) when based on some condition you want to swap values or not:
tmp = (a ^ b) & mask
a ^= tmp
b ^= tmp
If mask = 0xfff...fff then a/b will be swapped, otherwise if mask = 0 then they'll remain the same.
- CJefferson 6mo agoOh, that is cool, I’ve never seen that. I might add that to an extended version of the post sometime, I’ll be sure to credit you.
- jesse__ 6mo agoThat's hella cute
- koolala 6mo agoCould this still be the ideal way for vectors of Ints in WebGL2?
- jagged-chisel 6mo agoSo mask is marking the bits you want swapped and leaving the others in place.