3 ms·
Another simple bit-twiddling-hack (it has a proper name which I unfortunately forgot) is SIMD without SIMD instructions by masking out the top-level bits (which
by flohofwoe 6y ago
Another simple bit-twiddling-hack (it has a proper name which I unfortunately forgot) is SIMD without SIMD instructions by masking out the top-level bits (which are essentially the carry-flags), e.g. doing eight 7-bit additions at once:
uint64_t a = ((a0 & 0x7F) | ((a1 & 0x7F)<<8) ...;
uint64_t b = ((b0 & 0x7F) | ((b1 & 0x7F)<<8) ...;
uint64_t c = (a + b) & 0x7F7F7F7F7F7F7F7F;
- hairtuq 6y agoThe name SWAR is sometimes used (https://en.wikipedia.org/wiki/SWAR https://en.wikipedia.org/wiki/SWAR). Indeed, even 8-bit fields can be added in parallel, using the fact that ^ is like a + that does not produce a carry: uint64_t signmask = 0x8080808080808080; uint64_t sum_without_sign_bits = ((x & ~signmask) + (y & ~signmask)); uint64_t sum_of_sign_bits = (x ^ y) & signmask; return sum_without_sign_bits ^ sum_of_sign_bits;