Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up approximate exponential function by 2.1x #210

Closed
wants to merge 6 commits into from

Commits on Dec 15, 2023

  1. Replace the fast exponential approximation based on the limits exp(n)…

    … = lim_{n->inf} (1+1/n)^n, which uses 1 double division, 1 double addition and 12 double multiplications, with Shraudolph's approximation from https://www.schraudolph.org/pubs/Schraudolph99.pdf, which uses 1 double multiplication, 1 integer addition, 1 integer shift.
    
    This makes exp2 disappear from the profile entirely in our application, and reduced the time spent in sta::findRoot by 12%.
    
    For our application, this reduces
    
    Signed-off-by: Rasmus Munk Larsen <rmlarsen@google.com>
    rmlarsen committed Dec 15, 2023
    Configuration menu
    Copy the full SHA
    b290855 View commit details
    Browse the repository at this point in the history
  2. Use std::memcpy for type punning. Follow naming convention is Shraudo…

    …lph's
    
    paper for easier reference.
    
    Signed-off-by: Rasmus Munk Larsen <rmlarsen@google.com>
    rmlarsen committed Dec 15, 2023
    Configuration menu
    Copy the full SHA
    a5a7f5c View commit details
    Browse the repository at this point in the history

Commits on Dec 19, 2023

  1. Handle arguments that fall outside the range where the Shraudolph app…

    …roximation is accurate. Fortunately, this is almost the entire range in which exp(x) is finite.
    
    Signed-off-by: Rasmus Munk Larsen <rmlarsen@google.com>
    rmlarsen committed Dec 19, 2023
    Configuration menu
    Copy the full SHA
    b2db72b View commit details
    Browse the repository at this point in the history
  2. format

    Signed-off-by: Rasmus Munk Larsen <rmlarsen@google.com>
    rmlarsen committed Dec 19, 2023
    Configuration menu
    Copy the full SHA
    27a6f73 View commit details
    Browse the repository at this point in the history
  3. Recover most of the speed lost to range checking by only checking mag…

    …nitude in the common case.
    
    Signed-off-by: Rasmus Munk Larsen <rmlarsen@google.com>
    rmlarsen committed Dec 19, 2023
    Configuration menu
    Copy the full SHA
    785bc8e View commit details
    Browse the repository at this point in the history

Commits on Dec 28, 2023

  1. Merge branch 'master' into schraudolph

    Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
    maliberty committed Dec 28, 2023
    Configuration menu
    Copy the full SHA
    210e82e View commit details
    Browse the repository at this point in the history