[][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 2 bits is a number stored in parallel.

Bits4

This is used when every 4 bits is a number stored in parallel.

Bits8

This is used when every 8 bits is a number stored in parallel.

Bits16

This is used when every 16 bits is a number stored in parallel.

Bits32

This is used when every 32 bits is a number stored in parallel.

Bits64

This is used when every 64 bits is a number stored in parallel.

Bits128

This is used when every 128 bits is a number stored in parallel.

Bits16x32

This is used when every 16 bits is a number stored in parallel with a stride of 32.

Bits17x32

This is used when every 17 bits is a number stored in parallel with a stride of 32.

Bits1x2

This is used when each bit is a number stored in parallel with a stride of 2.

Bits2x4

This is used when every 2 bits is a number stored in parallel with a stride of 4.

Bits32x64

This is used when every 32 bits is a number stored in parallel with a stride of 64.

Bits33x64

This is used when every 33 bits is a number stored in parallel with a stride of 64.

Bits3x4

This is used when every 3 bits is a number stored in parallel with a stride of 4.

Bits4x8

This is used when every 4 bits is a number stored in parallel with a stride of 8.

Bits5x8

This is used when every 5 bits is a number stored in parallel with a stride of 8.

Bits64x128

This is used when every 64 bits is a number stored in parallel with a stride of 128.

Bits65x128

This is used when every 65 bits is a number stored in parallel with a stride of 128.

Bits8x16

This is used when every 8 bits is a number stored in parallel with a stride of 16.

Bits9x16

This is used when every 9 bits is a number stored in parallel with a stride of 16.