This is the mail archive of the gcc-patches@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]

Re: Reverted: [RFC PATCH, i386]: Convert 1.0/sqrtf (x) into rsqrtf even without -mrecip


On Jan 17, 2008 11:09 AM, Ye, Joey <joey.ye@intel.com> wrote:

> I have a small case showing the root cause:

Joey, thanks for your analysis.

>  rsqrt(0)=       +Infinity
>  rsqrt(INF)=   0.0000000
>  rsqrt(-0)=       -Infinity

Please note, that -mrecip conversion is constrained by
flag_finite_math_only, so cases where input or output is inf are out
of specs for this flag. In current state of affairs, and as shown by
your example, NaN is emitted when input argument space is violated.

It looks that 481.wrf depends on infinities in some way. While
-ffast-math [usually] tolerates infinities, like in the testcase
below, -mrecip depends on the fact that infinities will never be
encountered:

--cut here--
float __attribute__((noinline))
test (double a)
{
	return 1.0f / sqrtf (a);
}

int main()
{
	printf ("%f\n", test (0.0f));
	return 0;
}
--cut here--

gcc -O2 -ffast-math
./a.out
inf

gcc -O2 -ffast-math [-msse -mfpmath=sse] -mrecip
./a.out
nan

> Following patch on 131342 passes the small case as well as 481.wrf and
> bootstrap. It may not be the well optimized and performance impact is

There is a question, if we should fix -mrecip for programs that are in
fact incompatible with -ffinite-math-only and work with current
-ffast-math only by luck. I think that the purpose of -mrecip is to
emit the sequence that calculates division and sqrt as fast as
possible on the expense of limited precision and argument ranges (like
... games), for all other purposes divss and sqrtss work well enough.

Uros.


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