This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/55760] scalar code non using rsqrtss and rcpss


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55760

--- Comment #4 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2012-12-20 16:07:11 UTC ---
> is there any reason why rsqrtss and rcpss are not used for scalar code while
> rsqrtps and rcpps are used for loops?

Yep! I don't have the patience to dig the bugzilla archive right now, but the
main reason is related to a loss of accuracy (especially 1/2.0 != 0.5) leading
to problems in some codes (see gas_dyn.f90 in the polyhedron tests). You can
pass options to force the use of rsqrtss and rcpss for scalars:

-mrecip
This option enables use of RCPSS and RSQRTSS instructions (and their vectorized
variants RCPPS and RSQRTPS) with an additional Newton-Raphson step to increase
precision instead of DIVSS and SQRTSS (and their vectorized variants) for
single-precision floating-point arguments. These instructions are generated
only when -funsafe-math-optimizations is enabled together with
-finite-math-only and -fno-trapping-math. Note that while the throughput of the
sequence is higher than the throughput of the non-reciprocal instruction, the
precision of the sequence can be decreased by up to 2 ulp (i.e. the inverse of
1.0 equals 0.99999994).
Note that GCC implements 1.0f/sqrtf(x) in terms of RSQRTSS (or RSQRTPS) already
with -ffast-math (or the above option combination), and doesn't need -mrecip.

Also note that GCC emits the above sequence with additional Newton-Raphson step
for vectorized single-float division and vectorized sqrtf(x) already with
-ffast-math (or the above option combination), and doesn't need -mrecip. 

-mrecip=opt
This option controls which reciprocal estimate instructions may be used. opt is
a comma-separated list of options, which may be preceded by a `!' to invert the
option:
`all'
Enable all estimate instructions. 
`default'
Enable the default instructions, equivalent to -mrecip. 
`none'
Disable all estimate instructions, equivalent to -mno-recip. 
`div'
Enable the approximation for scalar division. 
`vec-div'
Enable the approximation for vectorized division. 
`sqrt'
Enable the approximation for scalar square root. 
`vec-sqrt'
Enable the approximation for vectorized square root.
So, for example, -mrecip=all,!sqrt enables all of the reciprocal
approximations, except for square root.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]