Changeset 888


Ignore:
Timestamp:
Sep 2, 2011, 2:06:21 AM (8 years ago)
Author:
sam
Message:

core: minor optimisation in the x86 version of lol_sin()

Instead of dividing by 2 and rounding with magic number 252, we round with
magic number 2
53, which gives us the parity with at least one mul less.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/trig.cpp

    r885 r888  
    3737static const double VERY_SMALL_NUMBER = 0x1.0p-128;
    3838static const double VERY_LARGE_NUMBER = 4503599627370496.0;
     39static const double EVEN_LARGER_NUMBER = 9007199254740992.0;
    3940
    4041/** sin Taylor series coefficients. */
     
    127128    return r;
    128129#else
    129     if (c >= 0) return gte; return lt;
     130    return (c >= 0) ? gte : lt;
    130131#endif
    131132}
     
    166167{
    167168    double absx = lol_fabs(x);
     169    double sign = lol_fsel(x, ONE, NEG_ONE);
    168170#if defined __CELLOS_LV2__
    169171    double num_cycles = lol_round(absx * INV_PI);
    170172    double is_even = lol_trunc(num_cycles * HALF) - (num_cycles * HALF);
    171173#else
    172     double num_cycles = absx * INV_PI;
    173     num_cycles += VERY_LARGE_NUMBER;
     174    double num_cycles = absx * INV_PI + VERY_LARGE_NUMBER;
    174175    __asm__("" : "+m" (num_cycles));
    175176    num_cycles -= VERY_LARGE_NUMBER;
    176     double is_even = num_cycles * HALF - HALF;
    177     is_even += VERY_LARGE_NUMBER;
     177
     178    double is_even = num_cycles - HALF;
    178179    __asm__("" : "+m" (is_even));
    179     is_even -= VERY_LARGE_NUMBER;
    180     is_even -= num_cycles * HALF;
     180    is_even += EVEN_LARGER_NUMBER;
     181    __asm__("" : "+m" (is_even));
     182    is_even -= EVEN_LARGER_NUMBER;
     183    __asm__("" : "+m" (is_even));
     184    is_even -= num_cycles;
    181185#endif
    182186    double norm_x = absx - PI * num_cycles;
     
    186190                                  * y + SC[2]) * y + SC[1])
    187191                                  * y + SC[0]) * y);
    188     double sign = lol_fsel(is_even * x, ONE, NEG_ONE);
     192    sign = lol_fsel(is_even, sign, -sign);
    189193    double result = norm_x + norm_x * taylor;
    190194    return result * sign;
Note: See TracChangeset for help on using the changeset viewer.