Is there a clever (ie: branchless) way to "compact" a hex number. Basically move all the 0s all to one side?
eg:
0x10302040 -> 0x13240000
or
0x10302040 -> 0x00001324
I looked on Bit Twiddling Hacks but didn't see anything.
It's for a SSE numerical pivoting algorithm. I need to remove any pivots that become 0. I can use _mm_cmpgt_ps
to find good pivots, _mm_movemask_ps
to convert that in to a mask, and then bit hacks to get something like the above. The hex value gets munged in to a mask for a _mm_shuffle_ps
instruction to perform a permutation on the SSE 128 bit register.
_pext_u32
with a mask of 0xf0f0f0f0 does this, if you want to do it with SSE you can of course shift/mask/recombine0x01200340
? What good is this compacting if you can't extract the original number?