[][src]Struct swar::Bits4

pub struct Bits4<N>(pub N);

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

Methods

impl Bits4<u128>[src]

pub fn from_element(e: u128) -> Self[src]

Spread a single value out to each element. Must be able to fit.

use swar::*;

assert_eq!(Bits4::from_element(0b0110), Bits4(0x6666_6666_6666_6666_6666_6666_6666_6666));

pub fn union(left: Bits8<u128>, right: Bits8<u128>) -> Self[src]

Takes two inputs that have half-sized elements and compresses them into half the space and puts them in the left and right sides of this.

use swar::*;

let input = Bits4(0xFEED_FACE_CAFE_BEEF_FEED_FACE_CAFE_BEEF);
let (left, right) = input.halve();
let output = Bits4::union(left, right);
assert_eq!(input, output);

pub fn sum_weight2(self) -> Bits8<u128>[src]

pub fn hwd(self, other: Self) -> Self[src]

This computes the hamming weight distance from hamming weights.

use swar::*;

for a in 0u128..=4 {
    for b in 0u128..=4 {
        let aa = Bits4(a | a << 4);
        let bb = Bits4(b | b << 4);
        let out = aa.hwd(bb);
        let diff = (a as i128 - b as i128).abs() as u128;
        let expected = Bits4(diff | diff << 4);
        assert_eq!(out, expected, "got hamming distances {:08b} expected {:08b} ({:04b}, {:04b})", out.0, expected.0, a, b);
    }
}

pub fn split(self) -> (Bits8<u128>, Bits8<u128>)[src]

pub fn halve(self) -> (Bits8<u128>, Bits8<u128>)[src]

Takes the left and right sides and spreads them out so that the bits in each element are spread out into twice the amount of space.

use swar::*;

let input = Bits4(0xABCD << 64 | 0xDEAD);
let (left, right) = input.halve();
assert_eq!(left, Bits8(0x0A0B_0C0D));
assert_eq!(right, Bits8(0x0D0E_0A0D));

Trait Implementations

impl<N: Copy> Copy for Bits4<N>[src]

impl<N: Debug> Debug for Bits4<N>[src]

impl<N: PartialEq> PartialEq<Bits4<N>> for Bits4<N>[src]

impl<N: Eq> Eq for Bits4<N>[src]

impl Add<Bits4<u128>> for Bits4<u128>[src]

Note that you are responsible for dealing with overflow. Try to avoid overflow or use the split() method to add in two halves. You can use split() on the result to get the carry bits.

type Output = Self

The resulting type after applying the + operator.

impl BitAnd<u128> for Bits4<u128>[src]

type Output = Self

The resulting type after applying the & operator.

impl Shr<u32> for Bits4<u128>[src]

type Output = Self

The resulting type after applying the >> operator.

impl<N: Clone> Clone for Bits4<N>[src]

default fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl<N> Send for Bits4<N> where
    N: Send

impl<N> Sync for Bits4<N> where
    N: Sync

Blanket Implementations

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]