Call math_opt_barrier inside if
Commit Message
On Thu, Jan 14, 2016 at 2:38 PM, Joseph Myers <joseph@codesourcery.com> wrote:
> On Thu, 14 Jan 2016, H.J. Lu wrote:
>
>> On Thu, Jan 14, 2016 at 2:13 PM, Joseph Myers <joseph@codesourcery.com> wrote:
>> > On Thu, 14 Jan 2016, H.J. Lu wrote:
>> >
>> >> Since floating-point operation may trigger floating-point exceptions,
>> >> we call math_opt_barrier inside if to prevent code motion.
>> >>
>> >> Tested on x86-64. OK for trunk?
>> >
>> > Please send a patch updating all implementations for which this issue is
>> > applicable.
>>
>> There are
>>
>> dbl-64/e_sqrt.c: libc_feholdexcept_setround (&env, FE_TONEAREST);
>> dbl-64/s_fma.c: libc_feholdexcept_setround (&env, FE_TONEAREST);
>> dbl-64/s_fmaf.c: libc_feholdexcept_setround (&env, FE_TOWARDZERO);
>>
>> under sysdeps/ieee754. dbl-64/s_fma.c is the only one with this
>> problem.
>
> I disagree with that analysis. The question isn't whether there's a call
> to a particular internal interface. The question is whether there are
> conditionals on arithmetic, such that the arithmetic is exact in the
> conditional case but may be inexact if moved before the conditional. I
> think at least ldbl-96/s_fmal.c, ldbl-96/s_fma.c and ldbl-128/s_fmal.c
> have the same issue.
>
Here is the updated patch. OK for trunk?
Comments
On Thu, 14 Jan 2016, H.J. Lu wrote:
> > I disagree with that analysis. The question isn't whether there's a call
> > to a particular internal interface. The question is whether there are
> > conditionals on arithmetic, such that the arithmetic is exact in the
> > conditional case but may be inexact if moved before the conditional. I
> > think at least ldbl-96/s_fmal.c, ldbl-96/s_fma.c and ldbl-128/s_fmal.c
> > have the same issue.
> >
>
> Here is the updated patch. OK for trunk?
OK.
From 009223c61e461e0feeeadce85d87b0eb3910f38d Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 14 Jan 2016 12:49:13 -0800
Subject: [PATCH] Call math_opt_barrier inside if
Since floating-point operation may trigger floating-point exceptions,
we call math_opt_barrier inside if to prevent code motion.
[BZ #19465]
* sysdeps/ieee754/dbl-64/s_fma.c (__fma): Call math_opt_barrier
inside if.
* sysdeps/ieee754/ldbl-128/s_fmal.c (__fmal): Likewise.
* sysdeps/ieee754/ldbl-96/s_fma.c (__fma): Likewise.
* sysdeps/ieee754/ldbl-96/s_fmal.c (__fmal): Likewise.
---
sysdeps/ieee754/dbl-64/s_fma.c | 5 ++++-
sysdeps/ieee754/ldbl-128/s_fmal.c | 5 ++++-
sysdeps/ieee754/ldbl-96/s_fma.c | 5 ++++-
sysdeps/ieee754/ldbl-96/s_fmal.c | 5 ++++-
4 files changed, 16 insertions(+), 4 deletions(-)
@@ -175,7 +175,10 @@ __fma (double x, double y, double z)
/* Ensure correct sign of exact 0 + 0. */
if (__glibc_unlikely ((x == 0 || y == 0) && z == 0))
- return x * y + z;
+ {
+ x = math_opt_barrier (x);
+ return x * y + z;
+ }
fenv_t env;
libc_feholdexcept_setround (&env, FE_TONEAREST);
@@ -179,7 +179,10 @@ __fmal (long double x, long double y, long double z)
/* Ensure correct sign of exact 0 + 0. */
if (__glibc_unlikely ((x == 0 || y == 0) && z == 0))
- return x * y + z;
+ {
+ x = math_opt_barrier (x);
+ return x * y + z;
+ }
fenv_t env;
feholdexcept (&env);
@@ -41,7 +41,10 @@ __fma (double x, double y, double z)
/* Ensure correct sign of exact 0 + 0. */
if (__glibc_unlikely ((x == 0 || y == 0) && z == 0))
- return x * y + z;
+ {
+ x = math_opt_barrier (x);
+ return x * y + z;
+ }
fenv_t env;
feholdexcept (&env);
@@ -177,7 +177,10 @@ __fmal (long double x, long double y, long double z)
/* Ensure correct sign of exact 0 + 0. */
if (__glibc_unlikely ((x == 0 || y == 0) && z == 0))
- return x * y + z;
+ {
+ x = math_opt_barrier (x);
+ return x * y + z;
+ }
fenv_t env;
feholdexcept (&env);
--
2.5.0