[−][src]Crate swar
Computing hamming weights in parallel
use swar::*; let n = 0xAAAA_AAAA_AAAA_AAAA_AAAA_AAAA_AAAA_AAAAu128; let weight: u128 = Bits1(n).sum_weight2() .sum_weight2() .sum_weight2() .sum_weight2() .sum_weight2() .sum_weight2() .sum_weight2() .into(); assert_eq!(weight as u32, n.count_ones()); assert_eq!(Bits1(n).sum_weight2().sum_weight2().0, 0x2222_2222_2222_2222_2222_2222_2222_2222); assert_eq!(Bits1(n).sum_weight2().sum_weight2().split().0, Bits4x8(Bits8(0x0202_0202_0202_0202_0202_0202_0202_0202)));
Finding hamming weight differences in parallel
use swar::*; // All combinations of inputs 0-2 (hamming weights) let a = Bits2(0b00_01_10_00_01_10_00_01_10u128); let b = Bits2(0b00_00_00_01_01_01_10_10_10u128); // Expected output weights let expected = Bits2(0b00_01_10_01_00_01_10_01_00u128); assert_eq!(a.hwd(b), expected);
Modules
u128 |
Structs
Bits1 | This is used when each bit is a number stored in parallel. |
Bits2 | This is used when every |
Bits4 | This is used when every |
Bits8 | This is used when every |
Bits16 | This is used when every |
Bits32 | This is used when every |
Bits64 | This is used when every |
Bits128 | This is used when every |
Bits16x32 | This is used when every |
Bits17x32 | This is used when every |
Bits1x2 | This is used when each bit is a number stored in parallel with a stride of |
Bits2x4 | This is used when every |
Bits32x64 | This is used when every |
Bits33x64 | This is used when every |
Bits3x4 | This is used when every |
Bits4x8 | This is used when every |
Bits5x8 | This is used when every |
Bits64x128 | This is used when every |
Bits65x128 | This is used when every |
Bits8x16 | This is used when every |
Bits9x16 | This is used when every |