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: Xinliang David Li <davidxl at google dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 4 Oct 2013 00:06:13 +0000
- Subject: Re: [PATCH] Fixing improper conversion from sin() to sinf() in optimization mode.
- Authentication-results: sourceware.org; auth=none
- References: <CAK=A3=1b=qhx8u8Wz7je=KYUbvOQHyKaWP353ud7D7f8gF56Bw at mail dot gmail dot com> <CAK=A3=0bQkcvprFZTtuJ0ZNbknSJixhMP559tiF3FFUL0zkmfw at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1308311615070 dot 20398 at digraph dot polyomino dot org dot uk> <CAK=A3=2PQh5RiuDWn9yGv-jxkC5G-s2JRSQTF0PEmaQSpsnyZg at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1309032123250 dot 27960 at digraph dot polyomino dot org dot uk> <CAAkRFZK1wL00=eU02LqEMVEpSxxgn8dFHhJEy6XbpYkB1T+X6g at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1309032137370 dot 27960 at digraph dot polyomino dot org dot uk> <CAK=A3=35nZpFVe=Y1J1mnWA==CtiMSifwBrvPmDt7G0c8Pz0AQ at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1309032232360 dot 27960 at digraph dot polyomino dot org dot uk> <CAK=A3=1m5Q1gAe0Ga+kQc9Cmaf1yoL7XXgi0GKB+7msvfznQrg at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1309042057520 dot 16060 at digraph dot polyomino dot org dot uk> <CAAkRFZKPxgjwHdM34kk2yOsXsVzqWHzfPGcaoViQyshGcLwfJw at mail dot gmail dot com> <Pine dot LNX dot 4 dot 64 dot 1309042141500 dot 16060 at digraph dot polyomino dot org dot uk> <CAK=A3=2jYZBkyhHM=5__s6DCqKv1Af_PmOHZLANpj1OOXoUEPA at mail dot gmail dot com>
On Fri, 6 Sep 2013, Cong Hou wrote:
> 4: (float) sqrtl ((long double) double_val) -> (float) sqrt (double_val)
I don't believe this case is in fact safe even if precision (long double)
>= precision (double) * 2 + 2 (when your patch would allow it).
The result that precision (double) * 2 + 2 is sufficient for the result of
rounding the long double value to double to be the same as the result of
rounding once from infinite precision to double would I think also mean
the same when rounding of the infinite-precision result to float happens
once - that is, if instead of (float) sqrt (double_val) you have fsqrt
(double_val) (fsqrt being the proposed function in draft TS 18661-1 for
computing a square root of a double value, rounded exactly once to float).
But here the question isn't whether rounding to long double then float
gives the same result as rounding to float. It's whether rounding to long
double then float gives the same result as rounding to double then float.
Consider, for example, double_val = 0x1.0000020000011p+0. The square root
rounded once to float (and so the result if you go via long double and
long double is sufficiently precise) is 0x1.000002p+0. But the square
root rounded to double is 0x1.000001p+0, which on rounding to float
produces 0x1p+0.
> 5: (double) sqrtl ((long double) float_val) -> sqrt ((double) float_val)
(This case, however, *is* safe if long double is sufficiently precise; the
conversion of float to long double is trivially equivalent to a conversion
involving an intermediate "double" type, so it reduces to a case for which
the standard formula involving precisions of just two types applies.)
--
Joseph S. Myers
joseph@codesourcery.com