Raven Engine v0.1
Loading...
Searching...
No Matches
TrigPolyImpl.inl File Reference

Estrin-based polynomial evaluation for sine and cosine. More...

Namespaces

namespace  Crux
namespace  Crux::Detail

Functions

template<int Degree>
constexpr float Crux::Detail::PolySinImpl (float x)
 Generic Estrin-based sine polynomial of degree D on x in [-pi/4,pi/4].
template<>
float Crux::Detail::PolySinImpl< 5 > (float x)
template<>
float Crux::Detail::PolySinImpl< 7 > (float x)
template<>
float Crux::Detail::PolySinImpl< 9 > (float x)
template<int Degree>
constexpr float Crux::Detail::PolyCosImpl (float x)
 Generic Estrin-based cosine polynomial of degree D on x in [-pi/4,pi/4].
template<>
float Crux::Detail::PolyCosImpl< 5 > (float x)
template<>
float Crux::Detail::PolyCosImpl< 7 > (float x)
template<>
float Crux::Detail::PolyCosImpl< 9 > (float x)

Detailed Description

Estrin-based polynomial evaluation for sine and cosine.

After reducing x into the primary interval \([-\pi/4, \pi/4]\), we approximate:

  • Sine (odd degree \(D\)):

    \[ \sin(x) \approx x \; P(y), \quad y = x^2, \quad P(y) = c_1 + c_3\,y + c_5\,y^2 + \dots + c_D\,y^{(D-1)/2}. \]

    We factor out \(x\) so that the remaining polynomial \(P(y)\) is in even powers.
  • Cosine (even degree \(D\)):

    \[ \cos(x) \approx Q(y), \quad y = x^2, \quad Q(y) = c_0 + c_2\,y + c_4\,y^2 + \dots + c_D\,y^{D/2}. \]

To minimize the FMA dependency chain, we use Estrin's method:

  1. Compute powers \(y = x^2,\, y^2,\, y^4,\,\dots\) with minimal multiplies.
  2. Form independent sub-expressions:

    \[ A = c_1 + c_3\,y,\quad B = c_5 + c_7\,y,\quad \dots \]

  3. Combine via further FMAs:

    \[ P(y) = A + B\,y^2,\quad \dots \]

  4. Multiply by \(x\) for sine.

This yields short, parallelizable paths (FMA height \(\approx\) 2), ideal for SIMD pipelines.

See also
SinCoeffs, CosCoeffs, RV_FMA