Skip to main content

Module math

Module math 

Source
Expand description

SIMD-accelerated mathematical operations

This module provides high-performance mathematical functions optimized with architecture-specific SIMD intrinsics. Key operations (sqrt, abs, floor, ceil, round) use hardware instructions directly. Transcendental functions (exp, log, sin, cos) use fast polynomial approximations evaluated in SIMD registers.

§Architecture Support

  • aarch64: NEON intrinsics for sqrt (vrsqrteq_f32), abs (vabsq_f32), floor/ceil/round (vrndmq_f32/vrndpq_f32/vrndnq_f32), and polynomial evaluations using FMA (vfmaq_f32)
  • x86-64: SSE2 for basic ops, SSE4.1 for floor/ceil/round (_mm_floor_ps), AVX2 for wider operations
  • Other: Scalar fallback with auto-vectorization hints

§Supported Operations

  • Power/Root: sqrt, cbrt, pow, exp, exp2
  • Logarithms: log, log2, log10
  • Trigonometric: sin, cos, tan, asin, acos, atan, atan2
  • Hyperbolic: sinh, cosh, tanh
  • Special: abs, signum, floor, ceil, round, fract

§Performance

Expected speedup over scalar: 3-6x for most operations

§Example

use oxigdal_algorithms::simd::math::{sqrt_f32, exp_f32};

let data = vec![1.0, 4.0, 9.0, 16.0];
let mut result = vec![0.0; 4];

sqrt_f32(&data, &mut result)?;
assert_eq!(result, vec![1.0, 2.0, 3.0, 4.0]);

Functions§

abs_f32
Compute absolute value element-wise using hardware SIMD
acos_f32
Compute arccosine element-wise
asin_f32
Compute arcsine element-wise
atan2_f32
Compute two-argument arctangent element-wise: atan2(y, x)
atan_f32
Compute arctangent element-wise
ceil_f32
Compute ceiling element-wise using hardware SIMD
cos_f32
Compute cosine element-wise
cosh_f32
Compute hyperbolic cosine element-wise
exp2_f32
Compute 2^x element-wise
exp_f32
Compute exponential (e^x) element-wise using SIMD polynomial approximation
floor_f32
Compute floor element-wise using hardware SIMD
fract_f32
Compute fractional part element-wise: fract(x) = x - floor(x)
ln_f32
Compute natural logarithm (ln) element-wise using SIMD polynomial approximation
log2_f32
Compute base-2 logarithm element-wise
log10_f32
Compute base-10 logarithm element-wise
pow_f32
Compute power (base^exponent) element-wise
round_f32
Compute round (nearest integer) element-wise using hardware SIMD
sin_f32
Compute sine element-wise
sinh_f32
Compute hyperbolic sine element-wise
sqrt_f32
Compute square root element-wise using hardware SIMD
tan_f32
Compute tangent element-wise
tanh_f32
Compute hyperbolic tangent element-wise