www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12084] New: std.math.poly using Estrin method

https://d.puremagic.com/issues/show_bug.cgi?id=12084

           Summary: std.math.poly using Estrin method
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



Part of the docs of std.math.poly:

pure nothrow  trusted real poly(real x, const real[] A);
    Evaluate polynomial A(x) = a0 + a1x + a2x2 + a3x3; ...
    Uses Horner's rule A(x) = a0 + x(a1 + x(a2 + x(a3 + ...)))


Its fallback code when asm is not available:

{
    ptrdiff_t i = A.length - 1;
    real r = A[i];
    while (--i >= 0)
    {
        r *= x;
        r += A[i];
    }
    return r;
}


But on modern CPUs this algorithm is usually more efficient:
http://en.wikipedia.org/wiki/Estrin%27s_scheme

See also for an example:
http://lolengine.net/blog/2011/9/17/playing-with-the-cpu-pipeline

I also suspect that with gdc and ldc2 the asm code is not necessary.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 05 2014