[J3] Questions about sqrt -- mostly for vendors
Van Snyder
Van.Snyder at jpl.nasa.gov
Tue Jan 29 19:21:37 EST 2019
> gfortran will normally use sqrt(x) and a division for y = 1 / sqrt(x).
> If, however, -ffast-math or -funsafe-math-optimization is specified
> on the command line, gfortran will use rsqrt(x) and a Newton-Raphson
> step to ensure precision. This applies to REAL x. For DOUBLE PRECISION
> x, there is no rsqrt so gfortran uses sqrt and does the division.
Algorithms for rsqrt are faster than algorithms for sqrt because the
Newton iteration doesn't require divides.
For inverse sqrt, it is almost certainly faster to use the
single-precision rsqrt instruction and one (or maybe two) Newton
iterations to get to double precision. If sqrt is desired, it's almost
certainly faster to compute rsqrt, and then multiply by X. Don't
divide.
More information about the J3
mailing list