Skip to main content

Module sleef

Module sleef 

Source
Expand description

SLEEF’s 1-ulp sinf and expf, ported to safe scalar Rust.

§Why this exists

The pinned CPU-fp32 oracle does not evaluate elementwise transcendentals with the platform’s scalar libm. Its CPU kernels run through a vectorized Vectorized<float>, and on AArch64 that type’s sin and exp dispatch to SLEEF’s Sleef_sinf4_u10 / Sleef_expf4_u10 — routines that are accurate to 1 ulp rather than correctly rounded. codec_snake_bisect proved by measurement that this is the whole remaining question at the SnakeBeta seam: every other operation there is a correctly-rounded f32 *, + or / with no freedom at all, and widening sin or exp toward the true value moves us further from the oracle, not closer. That direction is only possible if the target itself is a ~1-ulp routine.

So this module answers the question the bisect posed: it is the candidate implementation, in pure portable Rust, that an Accelerate vvsinf call could only ever approximate.

§What is ported, and what is not

Both routines here are the per-lane arithmetic of SLEEF’s AArch64 (advsimd) kernels with ENABLE_FMA_SP on, which is what a PyTorch AArch64 build compiles. Every lane of those kernels is an independent branch-free expression, so evaluating one element at a time is faithful — with one exception, recorded here rather than hidden: xsinf_u1 switches its whole vector to a Payne–Hanek reduction when any lane exceeds TRIGRANGEMAX2_F, and that branch is NOT ported. sinf_u10 falls back to a correctly-rounded f64 evaluation above that threshold and sinf_u10_in_fast_range lets a caller assert it never got there.

Nothing in this module is on the production path. It is selected only by the parity harness, through crate::f32ref::F32Transcendental.

Constants§

TRIGRANGEMAX2_F
Above this magnitude SLEEF abandons the Cody–Waite reduction for Payne–Hanek.

Functions§

expf_u10
Sleef_expf_u10exp(d) to within 1 ulp. SLEEF ships no lower-accuracy expf.
sinf_u10
Sleef_sinf_u10sin(d) to within 1 ulp.
sinf_u10_in_fast_range
True when x takes SLEEF’s Cody–Waite branch, the only one ported here.