Skip to main content

Module math

Module math 

Source
Expand description

SIMD-accelerated mathematical operations

This module provides mathematical functions with an architecture-specific fast path for a subset of operations. Key operations (sqrt, abs, floor, ceil, round) use NEON hardware instructions directly on aarch64. Transcendental functions (exp, log, sin, cos, …) currently call the standard library’s scalar libm implementation (e.g. f32::exp, f32::ln) on every target, including aarch64 — there is no SIMD polynomial approximation implemented for transcendentals today.

§Architecture Support

  • aarch64: NEON intrinsics for sqrt (vsqrtq_f32), abs (vabsq_f32), and floor/ceil/round (vrndmq_f32/vrndpq_f32/vrndaq_f32). Transcendental functions (exp, ln, log2, log10, sin, cos, …) fall back to scalar libm calls even on this target.
  • All other targets (including x86-64): Scalar fallback with auto-vectorization hints for every operation; there is no hand-written SSE2/SSE4.1/AVX2 path in this module today.

§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 oxigeo_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
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
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