Skip to main content

bitwise_count4

Function bitwise_count4 

Source
pub fn bitwise_count4<T: UnsignedInteger>(m: &[T; 4]) -> [T; 3]
Expand description

Computes the population count for each bit position across 4 input masks.

Returns three masks [bit0, bit1, bit2] that encode, per bit position, the 3-bit count of how many of the 4 inputs have that bit set.

For example, if a given bit is set in 3 inputs, then that bit would be set in bit0 and bit1. If a given bit is set in all 4 inputs, then that bit would only be set in bit2.

ยงExamples

let [bit0, bit1, bit2] = bitwise_count4::<u8>(&[
    0b10000,
    0b11000,
    0b11100,
    0b11110,
]);
assert_eq!(bit0, 0b01010);
assert_eq!(bit1, 0b01100);
assert_eq!(bit2, 0b10000);