Skip to main content

core/portable-simd/crates/core_simd/src/
mod.rs

1#[macro_use]
2mod swizzle;
3
4mod alias;
5mod cast;
6mod fmt;
7mod iter;
8mod masks;
9mod ops;
10mod select;
11mod swizzle_dyn;
12mod to_bytes;
13mod vector;
14mod vendor;
15
16pub mod simd {
17    #![doc = "Portable SIMD module.\n\nThis module offers a portable abstraction for SIMD operations\nthat is not bound to any particular hardware architecture.\n\n# What is \"portable\"?\n\nThis module provides a SIMD implementation that is fast and predictable on any target.\n\n### Portable SIMD works on every target\n\nUnlike target-specific SIMD in `std::arch`, portable SIMD compiles for every target.\nIn this regard, it is just like \"regular\" Rust.\n\n### Portable SIMD is consistent between targets\n\nA program using portable SIMD can expect identical behavior on any target.\nIn most regards, [`Simd<T, N>`] can be thought of as a parallelized `[T; N]` and operates like a sequence of `T`.\n\nThis has one notable exception: a handful of older architectures (e.g. `armv7` and `powerpc`) flush [subnormal](`f32::is_subnormal`) `f32` values to zero.\nOn these architectures, subnormal `f32` input values are replaced with zeros, and any operation producing subnormal `f32` values produces zeros instead.\nThis doesn\'t affect most architectures or programs.\n\n### Operations use the best instructions available\n\nOperations provided by this module compile to the best available SIMD instructions.\n\nPortable SIMD is not a low-level vendor library, and operations in portable SIMD _do not_ necessarily map to a single instruction.\nInstead, they map to a reasonable implementation of the operation for the target.\n\nConsistency between targets is not compromised to use faster or fewer instructions.\nIn some cases, `std::arch` will provide a faster function that has slightly different behavior than the `std::simd` equivalent.\nFor example, `_mm_min_ps`[^1] can be slightly faster than [`SimdFloat::simd_min`](`num::SimdFloat::simd_min`), but does not conform to the IEEE standard also used by [`f32::min`].\nWhen necessary, [`Simd<T, N>`] can be converted to the types provided by `std::arch` to make use of target-specific functions.\n\nMany targets simply don\'t have SIMD, or don\'t support SIMD for a particular element type.\nIn those cases, regular scalar operations are generated instead.\n\n[^1]: `_mm_min_ps(x, y)` is equivalent to `x.simd_lt(y).select(x, y)`\n"include_str!("core_simd_docs.md")]
18
19    pub mod prelude;
20
21    pub mod num;
22
23    pub mod ptr;
24
25    pub mod cmp;
26
27    pub use crate::core_simd::alias::*;
28    pub use crate::core_simd::cast::*;
29    pub use crate::core_simd::masks::*;
30    pub use crate::core_simd::select::*;
31    pub use crate::core_simd::swizzle::*;
32    pub use crate::core_simd::to_bytes::ToBytes;
33    pub use crate::core_simd::vector::*;
34}