From patchwork Wed Mar 25 10:06:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Liebler X-Patchwork-Id: 38611 Return-Path: X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id E97FA3942007 for ; Wed, 25 Mar 2020 10:06:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E97FA3942007 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 02PA4BR8110710 for ; Wed, 25 Mar 2020 06:06:48 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ywbuwhgyh-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 25 Mar 2020 06:06:48 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 25 Mar 2020 10:06:45 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 25 Mar 2020 10:06:42 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 02PA6g7U44630222 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 25 Mar 2020 10:06:42 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 771C0A4057; Wed, 25 Mar 2020 10:06:42 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 54ED3A405D; Wed, 25 Mar 2020 10:06:42 +0000 (GMT) Received: from m35lp38.lnxne.boe (unknown [9.152.108.100]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 25 Mar 2020 10:06:42 +0000 (GMT) From: Stefan Liebler To: libc-alpha@sourceware.org Cc: Stefan Liebler Subject: [PATCH 2/4] Use libc_fe* macros in ldbl-128/s_fmal.c. Date: Wed, 25 Mar 2020 11:06:26 +0100 X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200325100628.883397-1-stli@linux.ibm.com> References: <20200325100628.883397-1-stli@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20032510-0012-0000-0000-0000039764E4 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20032510-0013-0000-0000-000021D45C01 Message-Id: <20200325100628.883397-2-stli@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.645 definitions=2020-03-25_01:2020-03-23, 2020-03-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 malwarescore=0 bulkscore=0 adultscore=0 mlxscore=0 phishscore=0 impostorscore=0 mlxlogscore=310 suspectscore=1 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2003250082 X-Spam-Status: No, score=-29.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Mar 2020 10:06:50 -0000 The calls to feholdexcept, fesetround, feupdateenv, fetestexcept are replaced by the libc_fe* macros as it is also done in dbl-64/s_fma.c. --- 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 #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 #include #include +#include #include #include @@ -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. */