4 ms·
Nice bit twiddling hack! There are also the PDEP and PEXT instructions on x86 that could be used for this purpose, but it's possibly not worth it here.
by badmintonbaseba 2y ago
Nice bit twiddling hack! There are also the PDEP and PEXT instructions on x86 that could be used for this purpose, but it's possibly not worth it here.
- tubs 2y agoOn arm you can use https://developer.arm.com/documentation/dui0489/i/arm-and-thumb-instructions/bfc https://developer.arm.com/documentation/dui0489/i/arm-and-th... which is pretty convenient for this use-case.
- dan-robertson 2y agoAm I missing something or does that instruction only clear bits in the field and not shift the adjacent bits to contract the field to be empty?
- Retr0id 2y agoI wonder if the compiler is smart enough to emit those instructions with the right optimization flags
- badmintonbaseba 2y agoI never saw a compiler generating these instructions on its own. Compilers do produce popcnt and bswap from recognized algorithms, so I guess it's not entirely unreasonable, but I think the benefit would be marginal.