From patchwork Wed Nov 7 00:29:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 993991 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-489198-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="W0Eg7Th6"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42qS3Z0Z9Zz9sDN for ; Wed, 7 Nov 2018 11:29:44 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=Gu1IkW/5K5VNDsxO92jvxpVvwuJ4Ub+UGXOxLg5ylNYSSOq8KrN8g awTlxUz6NanT9v/Y6JeNCytSOv4TcdmTYhOvSBWKXI1ILoVNiLVtpqwE+ndrMs4g TwzRyWfCkzTq11A1K5AfUS0Gdg5TklQcNEYeAoARFCjTSIhjztGR1Y= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=nF6c4gZfZshhm9+wl5Ae4XM/X/c=; b=W0Eg7Th6kB9q1R9zUwcN gJrQuBV/avErs/qA0Q3A62ve+zzt80kXo9seldd/ojfahSjX6KZXtQH+fPLR83Fk ZaHtUh0xLt0U2L0UzvclDyp8EX3KghdmYeI3nbDWDtEONKQwcluNY4O9ncwZ0cTj NTmm3ur88HSbEmFX+vH3Lfo= Received: (qmail 20006 invoked by alias); 7 Nov 2018 00:29:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 19962 invoked by uid 89); 7 Nov 2018 00:29:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=sticky, UD:fmaq.c, 3415, fmaqc X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 07 Nov 2018 00:29:29 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-03.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1gKBio-0007Zx-Q7 from joseph_myers@mentor.com for gcc-patches@gcc.gnu.org; Tue, 06 Nov 2018 16:29:27 -0800 Received: from digraph.polyomino.org.uk (137.202.0.90) by SVR-IES-MBX-03.mgc.mentorg.com (139.181.222.3) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Wed, 7 Nov 2018 00:29:22 +0000 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.90_1) (envelope-from ) id 1gKBij-0004hd-So for gcc-patches@gcc.gnu.org; Wed, 07 Nov 2018 00:29:21 +0000 Date: Wed, 7 Nov 2018 00:29:21 +0000 From: Joseph Myers To: Subject: Update libquadmath fmaq from glibc, fix nanq issues Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 This patch extends update-quadmath.py to update fmaq from glibc. The issue in that function was that quadmath-imp.h had a struct in a union with mant_high and mant_low fields (up to 64-bit) whereas glibc has mantissa0, mantissa1, mantissa2 and mantissa3 (up to 32-bit). The patch changes those fields to be the same as in glibc, moving printf / strtod code that also uses those fields back to closer to the glibc form. This allows fmaq to be updated automatically from glibc (which brings in at least one bug fix from glibc from 2015). nanq was also using the mant_high field name, and had other issues: it only partly initialized the union from which a value was returned, and setting mant_high to 1 meant a signaling NaN would be returned rather than a quiet NaN. This patch fixes those issues as part of updating it to use the changed interfaces (but does not fix the issue of not using the argument). Bootstrapped with no regressions on x86_64-pc-linux-gnu. 2018-11-06 Joseph Myers * quadmath-imp.h (ieee854_float128): Use mantissa0, mantissa1, mantissa2 and mantissa3 fields instead of mant_high and mant_low. Change nan field to ieee_nan. * update-quadmath.py (update_sources): Also update fmaq.c. * math/nanq.c (nanq): Use ieee_nan field of union. Zero-initialize f. Set quiet_nan field. * printf/flt1282mpn.c, printf/printf_fphex.c, strtod/mpn2flt128.c, strtod/strtoflt128.c: Use mantissa0, mantissa1, mantissa2 and mantissa3 fields. Use ieee_nan and quiet_nan field. * math/fmaq.c: Regenerate from glibc sources with update-quadmath.py. Index: libquadmath/math/fmaq.c =================================================================== --- libquadmath/math/fmaq.c (revision 265822) +++ libquadmath/math/fmaq.c (working copy) @@ -1,5 +1,5 @@ /* Compute x * y + z as ternary operation. - Copyright (C) 2010-2017 Free Software Foundation, Inc. + Copyright (C) 2010-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek , 2010. @@ -18,16 +18,6 @@ . */ #include "quadmath-imp.h" -#include -#include -#ifdef HAVE_FENV_H -# include -# if defined HAVE_FEHOLDEXCEPT && defined HAVE_FESETROUND \ - && defined HAVE_FEUPDATEENV && defined HAVE_FETESTEXCEPT \ - && defined FE_TOWARDZERO && defined FE_INEXACT -# define USE_FENV_H -# endif -#endif /* This implementation uses rounding to odd to avoid problems with double rounding. See a paper by Boldo and Melquiond: @@ -73,7 +63,7 @@ if (u.ieee.exponent + v.ieee.exponent > 0x7fff + IEEE854_FLOAT128_BIAS) return x * y; - /* If x * y is less than 1/4 of FLT128_DENORM_MIN, neither the + /* If x * y is less than 1/4 of FLT128_TRUE_MIN, neither the result nor whether there is underflow depends on its exact value, only on its sign. */ if (u.ieee.exponent + v.ieee.exponent @@ -94,8 +84,10 @@ : (w.ieee.exponent == 0 || (w.ieee.exponent == 1 && w.ieee.negative != neg - && w.ieee.mant_low == 0 - && w.ieee.mant_high == 0))) + && w.ieee.mantissa3 == 0 + && w.ieee.mantissa2 == 0 + && w.ieee.mantissa1 == 0 + && w.ieee.mantissa0 == 0))) { __float128 force_underflow = x * y; math_force_eval (force_underflow); @@ -124,7 +116,7 @@ very small, adjust them up to avoid spurious underflows, rather than down. */ if (u.ieee.exponent + v.ieee.exponent - <= IEEE854_FLOAT128_BIAS + FLT128_MANT_DIG) + <= IEEE854_FLOAT128_BIAS + 2 * FLT128_MANT_DIG) { if (u.ieee.exponent > v.ieee.exponent) u.ieee.exponent += 2 * FLT128_MANT_DIG + 2; @@ -181,17 +173,15 @@ } /* Ensure correct sign of exact 0 + 0. */ - if (__builtin_expect ((x == 0 || y == 0) && z == 0, 0)) + if (__glibc_unlikely ((x == 0 || y == 0) && z == 0)) { x = math_opt_barrier (x); return x * y + z; } -#ifdef USE_FENV_H fenv_t env; feholdexcept (&env); fesetround (FE_TONEAREST); -#endif /* Multiplication m1 + m2 = x * y using Dekker's algorithm. */ #define C ((1LL << (FLT128_MANT_DIG + 1) / 2) + 1) @@ -214,62 +204,46 @@ /* Ensure the arithmetic is not scheduled after feclearexcept call. */ math_force_eval (m2); math_force_eval (a2); -#ifdef USE_FENV_H feclearexcept (FE_INEXACT); -#endif /* If the result is an exact zero, ensure it has the correct sign. */ if (a1 == 0 && m2 == 0) { -#ifdef USE_FENV_H feupdateenv (&env); -#endif /* Ensure that round-to-nearest value of z + m1 is not reused. */ z = math_opt_barrier (z); return z + m1; } -#ifdef USE_FENV_H fesetround (FE_TOWARDZERO); -#endif /* Perform m2 + a2 addition with round to odd. */ u.value = a2 + m2; - if (__builtin_expect (adjust == 0, 1)) + if (__glibc_likely (adjust == 0)) { -#ifdef USE_FENV_H - if ((u.ieee.mant_low & 1) == 0 && u.ieee.exponent != 0x7fff) - u.ieee.mant_low |= fetestexcept (FE_INEXACT) != 0; + if ((u.ieee.mantissa3 & 1) == 0 && u.ieee.exponent != 0x7fff) + u.ieee.mantissa3 |= fetestexcept (FE_INEXACT) != 0; feupdateenv (&env); -#endif /* Result is a1 + u.value. */ return a1 + u.value; } - else if (__builtin_expect (adjust > 0, 1)) + else if (__glibc_likely (adjust > 0)) { -#ifdef USE_FENV_H - if ((u.ieee.mant_low & 1) == 0 && u.ieee.exponent != 0x7fff) - u.ieee.mant_low |= fetestexcept (FE_INEXACT) != 0; + if ((u.ieee.mantissa3 & 1) == 0 && u.ieee.exponent != 0x7fff) + u.ieee.mantissa3 |= fetestexcept (FE_INEXACT) != 0; feupdateenv (&env); -#endif /* Result is a1 + u.value, scaled up. */ return (a1 + u.value) * 0x1p113Q; } else { -#ifdef USE_FENV_H - if ((u.ieee.mant_low & 1) == 0) - u.ieee.mant_low |= fetestexcept (FE_INEXACT) != 0; -#endif + if ((u.ieee.mantissa3 & 1) == 0) + u.ieee.mantissa3 |= fetestexcept (FE_INEXACT) != 0; v.value = a1 + u.value; /* Ensure the addition is not scheduled after fetestexcept call. */ - asm volatile ("" : : "m" (v.value)); -#ifdef USE_FENV_H + math_force_eval (v.value); int j = fetestexcept (FE_INEXACT) != 0; feupdateenv (&env); -#else - int j = 0; -#endif /* 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)); @@ -281,11 +255,11 @@ rounding will occur. */ if (v.ieee.exponent > 228) return (a1 + u.value) * 0x1p-228Q; - /* If v.value * 0x1p-228Q with round to zero is a subnormal above - or equal to FLT128_MIN / 2, then v.value * 0x1p-228Q shifts mantissa - down just by 1 bit, which means v.ieee.mant_low |= j would + /* If v.value * 0x1p-228L with round to zero is a subnormal above + or equal to FLT128_MIN / 2, then v.value * 0x1p-228L shifts mantissa + down just by 1 bit, which means v.ieee.mantissa3 |= j would change the round bit, not sticky or guard bit. - v.value * 0x1p-228Q never normalizes by shifting up, + v.value * 0x1p-228L never normalizes by shifting up, so round bit plus sticky bit should be already enough for proper rounding. */ if (v.ieee.exponent == 228) @@ -301,18 +275,18 @@ if (w.ieee.exponent == 229) return w.value * 0x1p-228Q; } - /* v.ieee.mant_low & 2 is LSB bit of the result before rounding, - v.ieee.mant_low & 1 is the round bit and j is our sticky - bit. */ - w.value = 0.0Q; - w.ieee.mant_low = ((v.ieee.mant_low & 3) << 1) | j; + /* v.ieee.mantissa3 & 2 is LSB bit of the result before rounding, + v.ieee.mantissa3 & 1 is the round bit and j is our sticky + bit. */ + w.value = 0; + w.ieee.mantissa3 = ((v.ieee.mantissa3 & 3) << 1) | j; w.ieee.negative = v.ieee.negative; - v.ieee.mant_low &= ~3U; + v.ieee.mantissa3 &= ~3U; v.value *= 0x1p-228Q; w.value *= 0x1p-2Q; return v.value + w.value; } - v.ieee.mant_low |= j; + v.ieee.mantissa3 |= j; return v.value * 0x1p-228Q; } } Index: libquadmath/math/nanq.c =================================================================== --- libquadmath/math/nanq.c (revision 265822) +++ libquadmath/math/nanq.c (working copy) @@ -4,8 +4,8 @@ nanq (const char *tagp __attribute__ ((unused))) { // FIXME -- we should use the argument - ieee854_float128 f; - f.ieee.exponent = 0x7fff; - f.ieee.mant_high = 0x1; + ieee854_float128 f = { 0 }; + f.ieee_nan.exponent = 0x7fff; + f.ieee_nan.quiet_nan = 0x1; return f.value; } Index: libquadmath/printf/flt1282mpn.c =================================================================== --- libquadmath/printf/flt1282mpn.c (revision 265822) +++ libquadmath/printf/flt1282mpn.c (working copy) @@ -39,14 +39,14 @@ *expt = (int) u.ieee.exponent - IEEE854_FLOAT128_BIAS; #if BITS_PER_MP_LIMB == 32 - res_ptr[0] = u.ieee.mant_low; /* Low-order 32 bits of fraction. */ - res_ptr[1] = (u.ieee.mant_low >> 32); - res_ptr[2] = u.ieee.mant_high; - res_ptr[3] = (u.ieee.mant_high >> 32); /* High-order 32 bits. */ + res_ptr[0] = u.ieee.mantissa3; /* Low-order 32 bits of fraction. */ + res_ptr[1] = u.ieee.mantissa2; + res_ptr[2] = u.ieee.mantissa1; + res_ptr[3] = u.ieee.mantissa0; /* High-order 32 bits. */ #define N 4 #elif BITS_PER_MP_LIMB == 64 - res_ptr[0] = u.ieee.mant_low; - res_ptr[1] = u.ieee.mant_high; + res_ptr[0] = ((mp_limb_t) u.ieee.mantissa2 << 32) | u.ieee.mantissa3; + res_ptr[1] = ((mp_limb_t) u.ieee.mantissa0 << 32) | u.ieee.mantissa1; #define N 2 #else #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for" Index: libquadmath/printf/printf_fphex.c =================================================================== --- libquadmath/printf/printf_fphex.c (revision 265822) +++ libquadmath/printf/printf_fphex.c (working copy) @@ -235,8 +235,10 @@ assert (sizeof (long double) == 16); - num0 = fpnum.ieee.mant_high; - num1 = fpnum.ieee.mant_low; + num0 = (((unsigned long long int) fpnum.ieee.mantissa0) << 32 + | fpnum.ieee.mantissa1); + num1 = (((unsigned long long int) fpnum.ieee.mantissa2) << 32 + | fpnum.ieee.mantissa3); zero_mantissa = (num0|num1) == 0; Index: libquadmath/quadmath-imp.h =================================================================== --- libquadmath/quadmath-imp.h (revision 265822) +++ libquadmath/quadmath-imp.h (working copy) @@ -96,11 +96,15 @@ #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ unsigned negative:1; unsigned exponent:15; - uint64_t mant_high:48; - uint64_t mant_low:64; + unsigned mantissa0:16; + unsigned mantissa1:32; + unsigned mantissa2:32; + unsigned mantissa3:32; #else - uint64_t mant_low:64; - uint64_t mant_high:48; + unsigned mantissa3:32; + unsigned mantissa2:32; + unsigned mantissa1:32; + unsigned mantissa0:16; unsigned exponent:15; unsigned negative:1; #endif @@ -142,16 +146,20 @@ unsigned negative:1; unsigned exponent:15; unsigned quiet_nan:1; - uint64_t mant_high:47; - uint64_t mant_low:64; + unsigned mantissa0:15; + unsigned mantissa1:32; + unsigned mantissa2:32; + unsigned mantissa3:32; #else - uint64_t mant_low:64; - uint64_t mant_high:47; + unsigned mantissa3:32; + unsigned mantissa2:32; + unsigned mantissa1:32; + unsigned mantissa0:15; unsigned quiet_nan:1; unsigned exponent:15; unsigned negative:1; #endif - } nan; + } ieee_nan; } ieee854_float128; Index: libquadmath/strtod/mpn2flt128.c =================================================================== --- libquadmath/strtod/mpn2flt128.c (revision 265822) +++ libquadmath/strtod/mpn2flt128.c (working copy) @@ -34,15 +34,17 @@ u.ieee.negative = sign; u.ieee.exponent = expt + IEEE854_FLOAT128_BIAS; #if BITS_PER_MP_LIMB == 32 - u.ieee.mant_low = (((uint64_t) frac_ptr[1]) << 32) - | (frac_ptr[0] & 0xffffffff); - u.ieee.mant_high = (((uint64_t) frac_ptr[3] - & (((mp_limb_t) 1 << (FLT128_MANT_DIG - 96)) - 1)) - << 32) | (frac_ptr[2] & 0xffffffff); + u.ieee.mantissa3 = frac_ptr[0]; + u.ieee.mantissa2 = frac_ptr[1]; + u.ieee.mantissa1 = frac_ptr[2]; + u.ieee.mantissa0 = frac_ptr[3] & (((mp_limb_t) 1 + << (FLT128_MANT_DIG - 96)) - 1); #elif BITS_PER_MP_LIMB == 64 - u.ieee.mant_low = frac_ptr[0]; - u.ieee.mant_high = frac_ptr[1] - & (((mp_limb_t) 1 << (FLT128_MANT_DIG - 64)) - 1); + u.ieee.mantissa3 = frac_ptr[0] & (((mp_limb_t) 1 << 32) - 1); + u.ieee.mantissa2 = frac_ptr[0] >> 32; + u.ieee.mantissa1 = frac_ptr[1] & (((mp_limb_t) 1 << 32) - 1); + u.ieee.mantissa0 = (frac_ptr[1] >> 32) & (((mp_limb_t) 1 + << (FLT128_MANT_DIG - 96)) - 1); #else #error "mp_limb size " BITS_PER_MP_LIMB "not accounted for" #endif Index: libquadmath/strtod/strtoflt128.c =================================================================== --- libquadmath/strtod/strtoflt128.c (revision 265822) +++ libquadmath/strtod/strtoflt128.c (working copy) @@ -30,12 +30,15 @@ #endif #define MPN2FLOAT mpn_construct_float128 #define FLOAT_HUGE_VAL HUGE_VALQ -#define SET_MANTISSA(flt, mant) \ - do { ieee854_float128 u; \ - u.value = (flt); \ - u.ieee.mant_high = 0x800000000000ULL; \ - u.ieee.mant_low = mant; \ - (flt) = u.value; \ +#define SET_MANTISSA(flt, mant) \ + do { ieee854_float128 u; \ + u.value = (flt); \ + u.ieee_nan.mantissa0 = 0; \ + u.ieee_nan.mantissa1 = 0; \ + u.ieee_nan.mantissa2 = (mant) >> 32; \ + u.ieee_nan.mantissa3 = (mant); \ + u.ieee_nan.quiet_nan = 1; \ + (flt) = u.value; \ } while (0) static inline __attribute__((__always_inline__)) Index: libquadmath/update-quadmath.py =================================================================== --- libquadmath/update-quadmath.py (revision 265822) +++ libquadmath/update-quadmath.py (working copy) @@ -143,8 +143,7 @@ # Replace all #includes with a single include of quadmath-imp.h. repl_map['(\n+#include[^\n]*)+\n+'] = '\n\n#include "quadmath-imp.h"\n\n' # Omitted from this list because code comes from more than one - # glibc source file: rem_pio2. Omitted because of a union not - # currently provided in libquadmath: fma. + # glibc source file: rem_pio2. ldbl_files = { 'e_acoshl.c': 'acoshq.c', 'e_acosl.c': 'acosq.c', 's_asinhl.c': 'asinhq.c', 'e_asinl.c': 'asinq.c', @@ -155,7 +154,7 @@ 's_erfl.c': 'erfq.c', 's_expm1l.c': 'expm1q.c', 'e_expl.c': 'expq.c', 't_expl.h': 'expq_table.h', 's_fabsl.c': 'fabsq.c', 's_finitel.c': 'finiteq.c', 's_floorl.c': 'floorq.c', - 'e_fmodl.c': 'fmodq.c', 's_frexpl.c': 'frexpq.c', + 's_fmal.c': 'fmaq.c', 'e_fmodl.c': 'fmodq.c', 's_frexpl.c': 'frexpq.c', 'e_lgammal_r.c': 'lgammaq.c', 'lgamma_negl.c': 'lgammaq_neg.c', 'lgamma_productl.c': 'lgammaq_product.c', 'e_hypotl.c': 'hypotq.c', 'e_ilogbl.c': 'ilogbq.c', 's_isinfl.c': 'isinfq.c',