public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Adhemerval Zanella <azanella@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc/azanella/x86-libc_fe] Use libc_fe* macros in ldbl-128/s_fmal.c. Date: Mon, 20 Apr 2020 18:52:55 +0000 (GMT) [thread overview] Message-ID: <20200420185255.87E203858D31@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c02676e99ada0348b99c71bf6d6563803721e396 commit c02676e99ada0348b99c71bf6d6563803721e396 Author: Stefan Liebler via Libc-alpha <libc-alpha@sourceware.org> Date: Mon Apr 20 08:13:33 2020 -0300 Use libc_fe* macros in ldbl-128/s_fmal.c. Diff: --- sysdeps/ieee754/float128/float128_private.h | 10 +++++++++ sysdeps/ieee754/ldbl-128/s_fmal.c | 33 ++++++++++++++++------------- sysdeps/x86/fpu/fenv_private.h | 4 ++++ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/sysdeps/ieee754/float128/float128_private.h b/sysdeps/ieee754/float128/float128_private.h index af1ed8f3c0..671323035d 100644 --- a/sysdeps/ieee754/float128/float128_private.h +++ b/sysdeps/ieee754/float128/float128_private.h @@ -76,6 +76,16 @@ # define libc_fesetenvl(ENV) libc_fesetenvf128 (ENV) #endif +#ifdef libc_feupdateenvf128 +# undef libc_feupdateenvl +# define libc_feupdateenvl(ENV) libc_feupdateenvf128 (ENV) +#endif + +#ifdef libc_fesetroundf128 +# undef libc_fesetroundl +# define libc_fesetroundl(RM) libc_fesetroundf128 (RM) +#endif + /* misc macros from the header below. */ #include <fix-fp-int-convert-overflow.h> #undef FIX_LDBL_LONG_CONVERT_OVERFLOW diff --git a/sysdeps/ieee754/ldbl-128/s_fmal.c b/sysdeps/ieee754/ldbl-128/s_fmal.c index 7475015bce..f5791b6a8a 100644 --- a/sysdeps/ieee754/ldbl-128/s_fmal.c +++ b/sysdeps/ieee754/ldbl-128/s_fmal.c @@ -23,6 +23,7 @@ #include <ieee754.h> #include <math-barriers.h> #include <math_private.h> +#include <fenv_private.h> #include <libm-alias-ldouble.h> #include <tininess.h> @@ -187,8 +188,7 @@ __fmal (_Float128 x, _Float128 y, _Float128 z) } fenv_t env; - feholdexcept (&env); - fesetround (FE_TONEAREST); + libc_feholdexcept_setroundl (&env, FE_TONEAREST); /* Multiplication m1 + m2 = x * y using Dekker's algorithm. */ #define C ((1LL << (LDBL_MANT_DIG + 1) / 2) + 1) @@ -216,41 +216,44 @@ __fmal (_Float128 x, _Float128 y, _Float128 z) /* If the result is an exact zero, ensure it has the correct sign. */ if (a1 == 0 && m2 == 0) { - feupdateenv (&env); + libc_feupdateenvl (&env); /* Ensure that round-to-nearest value of z + m1 is not reused. */ z = math_opt_barrier (z); return z + m1; } - fesetround (FE_TOWARDZERO); + libc_fesetroundl (FE_TOWARDZERO); /* Perform m2 + a2 addition with round to odd. */ u.d = a2 + m2; + if (__glibc_unlikely (adjust < 0)) + { + if ((u.ieee.mantissa3 & 1) == 0) + u.ieee.mantissa3 |= libc_fetestexceptl (FE_INEXACT) != 0; + v.d = a1 + u.d; + /* Ensure the addition is not scheduled after fetestexcept call. */ + math_force_eval (v.d); + } + + /* Reset rounding mode and test for inexact simultaneously. */ + int j = libc_feupdateenv_testl (&env, FE_INEXACT) != 0; + if (__glibc_likely (adjust == 0)) { if ((u.ieee.mantissa3 & 1) == 0 && u.ieee.exponent != 0x7fff) - u.ieee.mantissa3 |= fetestexcept (FE_INEXACT) != 0; - feupdateenv (&env); + u.ieee.mantissa3 |= j; /* Result is a1 + u.d. */ return a1 + u.d; } else if (__glibc_likely (adjust > 0)) { if ((u.ieee.mantissa3 & 1) == 0 && u.ieee.exponent != 0x7fff) - u.ieee.mantissa3 |= fetestexcept (FE_INEXACT) != 0; - feupdateenv (&env); + u.ieee.mantissa3 |= j; /* Result is a1 + u.d, scaled up. */ return (a1 + u.d) * L(0x1p113); } else { - if ((u.ieee.mantissa3 & 1) == 0) - u.ieee.mantissa3 |= fetestexcept (FE_INEXACT) != 0; - v.d = a1 + u.d; - /* Ensure the addition is not scheduled after fetestexcept call. */ - math_force_eval (v.d); - int j = fetestexcept (FE_INEXACT) != 0; - feupdateenv (&env); /* Ensure the following computations are performed in default rounding mode instead of just reusing the round to zero computation. */ asm volatile ("" : "=m" (u) : "m" (u)); diff --git a/sysdeps/x86/fpu/fenv_private.h b/sysdeps/x86/fpu/fenv_private.h index 23a430362a..8453aaa270 100644 --- a/sysdeps/x86/fpu/fenv_private.h +++ b/sysdeps/x86/fpu/fenv_private.h @@ -302,6 +302,8 @@ libc_feresetround_387 (fenv_t *e) # define libc_feupdateenv_testf128 libc_feupdateenv_test_sse # define libc_feholdexceptf128 libc_feholdexcept_sse # define libc_fesetenvf128 libc_fesetenv_sse +# define libc_feupdateenvf128 libc_feupdateenv_sse +# define libc_fesetroundf128 libc_fesetround_sse #else /* The 387 rounding mode is used by soft-fp for 32-bit, but whether 387 or SSE exceptions are used depends on whether libgcc was built @@ -310,6 +312,8 @@ libc_feresetround_387 (fenv_t *e) # define libc_feupdateenv_testf128 default_libc_feupdateenv_test # define libc_feholdexceptf128 default_libc_feholdexcept # define libc_fesetenvf128 default_libc_fesetenv +# define libc_feupdateenvf128 default_libc_feupdateenv +# define libc_fesetroundf128 default_libc_fesetround #endif /* We have support for rounding mode context. */
reply other threads:[~2020-04-20 18:52 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200420185255.87E203858D31@sourceware.org \ --to=azanella@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).