27 releases

new 0.13.2 Sep 16, 2023
0.13.1 Apr 22, 2023
0.12.1 Apr 3, 2023
0.11.11 Mar 23, 2023
0.10.3 Nov 28, 2022

#90 in Hardware support

Download history 1353/week @ 2023-05-31 926/week @ 2023-06-07 875/week @ 2023-06-14 1091/week @ 2023-06-21 958/week @ 2023-06-28 731/week @ 2023-07-05 890/week @ 2023-07-12 718/week @ 2023-07-19 699/week @ 2023-07-26 541/week @ 2023-08-02 627/week @ 2023-08-09 805/week @ 2023-08-16 765/week @ 2023-08-23 604/week @ 2023-08-30 1632/week @ 2023-09-06 1610/week @ 2023-09-13

4,704 downloads per month
Used in 20 crates (14 directly)

MIT license

1MB
18K SLoC

pulp is a safe abstraction over SIMD instructions, that allows you to write a function once and dispatch to equivalent vectorized versions based on the features detected at runtime.

Documentation Crate

Autovectorization example

use pulp::Arch;

let mut v = (0..1000).map(|i| i as f64).collect::<Vec<_>>();
let arch = Arch::new();

arch.dispatch(|| {
    for x in &mut v {
        *x *= 2.0;
    }
});

for (i, x) in v.into_iter().enumerate() {
    assert_eq!(x, 2.0 * i as f64);
}

Manual vectorization example

use pulp::{Arch, Simd, WithSimd};

struct TimesThree<'a>(&'a mut [f64]);
impl<'a> WithSimd for TimesThree<'a> {
    type Output = ();

    #[inline(always)]
    fn with_simd<S: Simd>(self, simd: S) -> Self::Output {
        let v = self.0;
        let (head, tail) = S::f64s_as_mut_simd(v);

        let three = simd.f64s_splat(3.0);
        for x in head {
            *x = simd.f64s_mul(three, *x);
        }

        for x in tail {
            *x = *x * 3.0;
        }
    }
}

let mut v = (0..1000).map(|i| i as f64).collect::<Vec<_>>();
let arch = Arch::new();

arch.dispatch(TimesThree(&mut v));

for (i, x) in v.into_iter().enumerate() {
    assert_eq!(x, 3.0 * i as f64);
}

Dependencies

~395KB