From patchwork Thu Jan 14 23:11:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 10387 Received: (qmail 66517 invoked by alias); 14 Jan 2016 23:11:57 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 66508 invoked by uid 89); 14 Jan 2016 23:11:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=fenv_t, __fma, sk:bc3677d, 175, 7 X-HELO: mail-qg0-f48.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=tfqDmVzEJnPncQnwnZw1148MsEv/WrdxwNN6LCF82jI=; b=igFg567KXpzc4N5daxP65BNqrlO0IxbDyAIaWvho5gW9hBLZJ1vNXglDJIwssHRo/o iwTFn5auZaziyUjdaREjs04Wfex71VFov1t9DYMmHjC65nD8KQe2eXIk9o8Ij5dcXcEJ hJi6ru7vkdVGWrI+LLc+MnSQhUR0z3EIayrXZYoWTbAU4bZktAXqq56833N86GgLfv/U fDGxXFXppPZgBe7zb16TjWSO+YB1Z65vJrbBCFXP0/qPm5a1cwmBtqnGjEmDnJEzGlAr hGjKFDoJ9hywvarCKWgMN5BHlcAX/A+AtlRsOgJTBT/q12aZL7+VcnPDTVbU/yEm3DUX I+/g== X-Gm-Message-State: ALoCoQn7GzzqlQwrTlJU0weeZy24FJoiWzBBjS+1Gmy8rmYBsNZt/sH2f7cuj3OkfiHL2jgpZpBTArTsOgzX7N5OLmU8pfckjg== MIME-Version: 1.0 X-Received: by 10.140.27.139 with SMTP id 11mr9225821qgx.62.1452813113083; Thu, 14 Jan 2016 15:11:53 -0800 (PST) In-Reply-To: References: <20160114214145.GA22984@intel.com> Date: Thu, 14 Jan 2016 15:11:52 -0800 Message-ID: Subject: Re: [PATCH] Call math_opt_barrier inside if From: "H.J. Lu" To: Joseph Myers Cc: GNU C Library On Thu, Jan 14, 2016 at 2:38 PM, Joseph Myers wrote: > On Thu, 14 Jan 2016, H.J. Lu wrote: > >> On Thu, Jan 14, 2016 at 2:13 PM, Joseph Myers 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? From 009223c61e461e0feeeadce85d87b0eb3910f38d Mon Sep 17 00:00:00 2001 From: "H.J. Lu" 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(-) diff --git a/sysdeps/ieee754/dbl-64/s_fma.c b/sysdeps/ieee754/dbl-64/s_fma.c index bc3677d..a349243 100644 --- a/sysdeps/ieee754/dbl-64/s_fma.c +++ b/sysdeps/ieee754/dbl-64/s_fma.c @@ -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); diff --git a/sysdeps/ieee754/ldbl-128/s_fmal.c b/sysdeps/ieee754/ldbl-128/s_fmal.c index ac30027..728949c 100644 --- a/sysdeps/ieee754/ldbl-128/s_fmal.c +++ b/sysdeps/ieee754/ldbl-128/s_fmal.c @@ -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); diff --git a/sysdeps/ieee754/ldbl-96/s_fma.c b/sysdeps/ieee754/ldbl-96/s_fma.c index 5fbdda7..ab45bcf 100644 --- a/sysdeps/ieee754/ldbl-96/s_fma.c +++ b/sysdeps/ieee754/ldbl-96/s_fma.c @@ -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); diff --git a/sysdeps/ieee754/ldbl-96/s_fmal.c b/sysdeps/ieee754/ldbl-96/s_fmal.c index 57774cf..f1467fd 100644 --- a/sysdeps/ieee754/ldbl-96/s_fmal.c +++ b/sysdeps/ieee754/ldbl-96/s_fmal.c @@ -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