Crate pulp

Source
Expand description

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.

§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::as_mut_simd_f64s(v);

		let three = simd.splat_f64s(3.0);
		for x in head {
			*x = simd.mul_f64s(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);
}

Re-exports§

pub use x86::Arch;
pub use bytemuck;
pub use num_complex;

Modules§

core_arch
Platform dependent intrinsics.
x86x86 or x86-64
Low level x86 API.

Macros§

cast
Safe transmute macro.
feature_detected
simd_type
static_assert_same_size
static_assert_size_less_than_or_equal
try_const

Structs§

MemMask
Scalar
Scalar128b
Scalar256b
Scalar512b
b8
Bitmask type for 8 elements, used for mask operations on AVX512.
b16
Bitmask type for 16 elements, used for mask operations on AVX512.
b32
Bitmask type for 32 elements, used for mask operations on AVX512.
b64
Bitmask type for 64 elements, used for mask operations on AVX512.
f32x4
A 128-bit SIMD vector with 4 elements of type f32.
f32x8
A 256-bit SIMD vector with 8 elements of type f32.
f32x16
A 512-bit SIMD vector with 16 elements of type f32.
f64x2
A 128-bit SIMD vector with 2 elements of type f64.
f64x4
A 256-bit SIMD vector with 4 elements of type f64.
f64x8
A 512-bit SIMD vector with 8 elements of type f64.
i8x16
A 128-bit SIMD vector with 16 elements of type i8.
i8x32
A 256-bit SIMD vector with 32 elements of type i8.
i8x64
A 512-bit SIMD vector with 64 elements of type i8.
i16x8
A 128-bit SIMD vector with 8 elements of type i16.
i16x16
A 256-bit SIMD vector with 16 elements of type i16.
i16x32
A 512-bit SIMD vector with 32 elements of type i16.
i32x4
A 128-bit SIMD vector with 4 elements of type i32.
i32x8
A 256-bit SIMD vector with 8 elements of type i32.
i32x16
A 512-bit SIMD vector with 16 elements of type i32.
i64x2
A 128-bit SIMD vector with 2 elements of type i64.
i64x4
A 256-bit SIMD vector with 4 elements of type i64.
i64x8
A 512-bit SIMD vector with 8 elements of type i64.
m8
Mask type with 8 bits. Its bit pattern is either all ones or all zeros. Unsafe code must not depend on this, however.
m8x16
A 128-bit SIMD vector with 16 elements of type m8.
m8x32
A 256-bit SIMD vector with 32 elements of type m8.
m16
Mask type with 16 bits. Its bit pattern is either all ones or all zeros. Unsafe code must not depend on this, however.
m32
Mask type with 32 bits. Its bit pattern is either all ones or all zeros. Unsafe code must not depend on this, however.
m64
Mask type with 64 bits. Its bit pattern is either all ones or all zeros. Unsafe code must not depend on this, however.
m16x8
A 128-bit SIMD vector with 8 elements of type m16.
m16x16
A 256-bit SIMD vector with 16 elements of type m16.
m32x4
A 128-bit SIMD vector with 4 elements of type m32.
m32x8
A 256-bit SIMD vector with 8 elements of type m32.
m32x16
A 512-bit SIMD vector with 16 elements of type m32.
m64x2
A 128-bit SIMD vector with 2 elements of type m64.
m64x4
A 256-bit SIMD vector with 4 elements of type m64.
m64x8
A 512-bit SIMD vector with 8 elements of type m64.
u8x16
A 128-bit SIMD vector with 16 elements of type u8.
u8x32
A 256-bit SIMD vector with 32 elements of type u8.
u8x64
A 512-bit SIMD vector with 64 elements of type u8.
u16x8
A 128-bit SIMD vector with 8 elements of type u16.
u16x16
A 256-bit SIMD vector with 16 elements of type u16.
u16x32
A 512-bit SIMD vector with 32 elements of type u16.
u32x4
A 128-bit SIMD vector with 4 elements of type u32.
u32x8
A 256-bit SIMD vector with 8 elements of type u32.
u32x16
A 512-bit SIMD vector with 16 elements of type u32.
u64x2
A 128-bit SIMD vector with 2 elements of type u64.
u64x4
A 256-bit SIMD vector with 4 elements of type u64.
u64x8
A 512-bit SIMD vector with 8 elements of type u64.

Traits§

Interleave
Types that allow [de]interleaving.
NullaryFnOnce
PortableSimd
Simd
WithSimd

Functions§

as_arrays
Splits a slice into chunks of equal size (known at compile time).
as_arrays_mut
Splits a slice into chunks of equal size (known at compile time).
cast
Safe transmute function.
cast_lossy
Safe lossy transmute function, where the destination type may be smaller than the source type.
iota_32
iota_64

Type Aliases§

c32
c64

Attribute Macros§

with_simdmacro
Requires the first non-lifetime generic parameter, as well as the function’s first input parameter to be the SIMD type. Also currently requires that all the lifetimes be explicitly specified.