elem-simd-math 0.1.3

Vectorized elementwise math kernels for f32/f64 over stable-Rust SIMD (port of SLEEF via sleef-rs, on fearless_simd).
Documentation
//! `i0e`, `i1e` and `xlogy` over native-width `f32` vectors.
//!
//! Provenance as for [`crate::f64x::special`]: SciPy's [xsf] (BSD-3-Clause) commit
//! `39019a470a208221d55a587f0baa329c3d1054c5`. xsf has no single-precision series for these
//! functions (SciPy evaluates its `float32` loops in `double`), so neither does this module:
//!
//! * [`i0e`] and [`i1e`] widen each lane to `f64`, run the `f64` kernel on both halves, and
//!   narrow. The `f64` result is within about `6e-16` relative of the true value, so the rounded
//!   `f32` is correctly rounded except for the rare input whose true value lies within that
//!   distance of a rounding boundary: the bound is `0.5001 ULP`. No second coefficient set is
//!   needed.
//! * [`xlogy`] stays in `f32` on [`u10::log`] (1.0 ULP) plus one multiplication: `1.5 ULP`.
//!
//! [xsf]: https://github.com/scipy/xsf
//!
//! Bit-identity: all three are bit-identical on every SIMD level. [`i0e`] and [`i1e`] are
//! bit-identical to the scalar reference `crate::bessel::i0e(x as f64) as f32`; [`xlogy`] is not
//! (the scalar reference uses the platform `ln`).

use super::*;

/// `exp(-|x|) I0(x)` for `f32`; `0.5001 ULP`, finite for every input (`i0e(+-inf) = 0`).
#[inline(always)]
pub fn i0e<S: Simd>(simd: S, x: F32s<S>) -> F32s<S> {
    let (lo, hi) = x.widen();
    crate::f64x::special::i0e(simd, lo).narrow(crate::f64x::special::i0e(simd, hi))
}

/// `exp(-|x|) I1(x)` for `f32`; `0.5001 ULP`, odd in `x`, `i1e(+-inf) = +-0`.
#[inline(always)]
pub fn i1e<S: Simd>(simd: S, x: F32s<S>) -> F32s<S> {
    let (lo, hi) = x.widen();
    crate::f64x::special::i1e(simd, lo).narrow(crate::f64x::special::i1e(simd, hi))
}

/// `x * ln(y)` for `f32`, defined as `0` when `x == 0` and `y` is not NaN; `1.5 ULP`.
///
/// Special cases are those of [`crate::f64x::special::xlogy`].
#[inline(always)]
pub fn xlogy<S: Simd>(simd: S, x: F32s<S>, y: F32s<S>) -> F32s<S> {
    let product = x * u10::log(simd, y);
    let zero = splat(simd, 0.);
    let defined_zero = x.simd_eq(zero) & y.simd_eq(y);
    defined_zero.select(zero, product)
}