Skip to main content

elem_simd_math/
lib.rs

1//! `elem-simd-math` — vectorized elementwise math for `f64`.
2//!
3//! This crate is a port of [SLEEF] as expressed by the [sleef-rs] crate, rewritten against the
4//! stable-Rust SIMD abstraction of [`fearless_simd`] so that it builds on stable Rust with
5//! runtime CPU feature detection. See `NOTICE` and `THIRD-PARTY-LICENSES` for the provenance and
6//! licensing of the derived portions.
7//!
8//! [SLEEF]: https://sleef.org/
9//! [sleef-rs]: https://github.com/burrbull/sleef-rs
10//!
11//! # Layers
12//!
13//! * [`f64x`] exposes the ported kernels as functions generic over a
14//!   [`fearless_simd::Simd`] token, operating on native-width vectors. Use these when you
15//!   already own the SIMD loop.
16//! * [`ElementwiseMath`] exposes slice entry points that pick the best available SIMD level at
17//!   runtime, with a scalar fallback.
18//!
19//! # Accuracy
20//!
21//! Kernels come from SLEEF's four accuracy tiers and each function documents its tier's error
22//! bound (`u05` = 0.5 ULP, `u10` = 1.0 ULP, `u15` = 1.5 ULP, `u35` = 3.5 ULP). Those bounds are
23//! asserted by the ported upstream test suites against MPFR. They bound the vector body; the
24//! value produced for inputs outside a kernel's tested domain is documented per function.
25
26#![forbid(unsafe_code)]
27#![warn(missing_docs)]
28// The ported coefficients are written out to upstream's full decimal expansion. Shortening them
29// to the shortest round-tripping form would change the constants, and several are deliberately
30// not the nearest `f64` to a mathematical constant (they are the range-reduction splits).
31#![allow(clippy::excessive_precision)]
32#![allow(clippy::approx_constant)]
33
34pub mod common;
35pub mod constants;
36pub mod doubled;
37pub mod f32x;
38pub mod f64x;
39pub(crate) mod tables;
40
41mod dispatch;
42
43pub use dispatch::{ElementwiseMath, LengthMismatch};
44
45/// The `f32` slice entry points are also available as free functions here.
46pub mod f32 {
47    pub use crate::dispatch::f32::*;
48}
49
50/// The `f64` slice entry points are also available as free functions here.
51pub mod f64 {
52    pub use crate::dispatch::f64::*;
53}