This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Cong Hou <congh at google dot com>
- Cc: <gcc-patches at gcc dot gnu dot org>, David Li <davidxl at google dot com>
- Date: Fri, 23 Aug 2013 21:00:55 +0000
- Subject: Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.
- References: <CAK=A3=1b=qhx8u8Wz7je=KYUbvOQHyKaWP353ud7D7f8gF56Bw at mail dot gmail dot com>
On Tue, 20 Aug 2013, Cong Hou wrote:
> When a sin() (cos(), log(), etc.) function is called on a value of
> float type and the returned double value is converted to another value
> of float type, GCC converts this function call into a float version
> (sinf()) in the optimization mode. This avoids two type conversions
> and the float version function call usually takes less time. However,
> this can result in different result and therefore is unsafe.
Whether it's safe depends on the existence of input values for which the
double-rounded result is different from the single-rounded result. It's
certainly safe for some of the functions for which the optimization is
enabled, regardless of the precisions involved (fabs, logb). For sqrt, if
the smaller precision is p then the larger precision being at least 2p+3
(I think) makes things same. For the other cases, exhaustive searches may
be needed to determine when the conversion is safe.
(Actually, this code appears to deal with cases with up to three types
involved - the operand, the result and the function that's called. This
complicates the analysis a bit, but the same principles apply.)
--
Joseph S. Myers
joseph@codesourcery.com