Skip to main content

pack_bool_word_swar

Function pack_bool_word_swar 

Source
pub fn pack_bool_word_swar(bools: &[bool; 64]) -> u64
Expand description

Portable branch-free byte→bit pack kernel, used when no SIMD kernel is available.

Reads the bools eight at a time as a u64 and gathers the eight 0x00/0x01 bytes into eight contiguous bits with a single multiply: byte i contributes 2^(8i), and the magic constant 0x0102_0408_1020_4080 = Σ 2^(56-7i) shifts each contribution to bit 56 + i without any cross-term collisions, so the mask falls out of the top byte of the product.