SIMD (Single Instruction Multiple Data) extension for a variety of targets. This project was initially started to facilitate the expansion of LLML's suported targets & features
This crate/library contains bindings to native-level SIMD instructions (alongside some polyfill) for SSE, AVX (see AVX support), NEON & WASM. It also contains naive implementations of all data-types (see naive implementation)
llml_simd
is a no_std crate. This means that it can be used for embeded systems projects seamlessly.
If no supported target is detected (or if you enable the feature force_naive
), Rust will compile the the SIMD vectors in naive mode. This mode represent's all data types as an array, executing most of the methods via iterators. This mode, while not recommended, is usefull if you intend to share code with some other programm that doesn't have SIMD support.
Warning
While not explicitly SIMD,rustc
might still optimize some parts of the code to utilize SIMD instructions if it can and you allow it to. If you want to fully disable SIMD instructions, use--target-feature=-sse
on x86/x86_64 and--target-feature=-neon
on arm/aarch64 (naive mode will be used automatically in those cases, not requiring to enableforce_naive
)
If Rust detects avx
as a target feature and you have the use_avx
feature enabled (see features), llml_simd
will compile all vectors over 128-bit long with AVX instructions, increasing performance significantly.
Thanks to WASM, llml_simd
is available for JavaScript/TypeScript via npm.
You can install it into your Node project with npm i llml_simd
Feature | Description |
---|---|
use_std |
Enables standard library functionality. Enabled by default |
force_naive |
Forces naive types (see Naive implementation) |
use_avx |
Enables the use of AVX SIMD types (see AVX support) |
random |
Enables random generation of vectors via rand |
serialize |
Enables serialization and deserialization of vectors via serde |
use llml_simd::float::single::f32x4;
pub fn main() {
let alpha = f32x4::new([1., 2., 3., 4.]);
let beta = f32x4::new([5., 6., 7., 8.]);
let dot = (alpha * beta).sum();
assert_eq!(dot, 70.);
}
import { f32x4 } from llml_simd
let alpha = new f32x4(new Float32Array([1, 2, 3, 4]))
let beta = new f32x4(new Float32Array([5, 6, 7, 8]))
let dot = alpha.mul(beta).sum()
console.assert(dot === 70)