From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hall.aurel32.net (hall.aurel32.net [IPv6:2001:bc8:30d7:100::1]) by sourceware.org (Postfix) with ESMTPS id 35166385802E for ; Sat, 22 Oct 2022 10:14:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 35166385802E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=aurel32.net Authentication-Results: sourceware.org; spf=none smtp.mailfrom=aurel32.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aurel32.net ; s=202004.hall; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Content-Transfer-Encoding:From:Reply-To: Subject:Content-ID:Content-Description:X-Debbugs-Cc; bh=fc0aXgsNM95fsV2VHQsRNWWmSyKKtwvq3tsneswTGNo=; b=aR4h/CGZKhBUdU/xom4ytIqs6x gMhcrUXFL8502V0+sbHsenXeXejunHmrfn/auMH+OSoF1riyP49SlFdo0hbjisCOI8Ugfhwarw5Ib uIpzva0CFvCmtAPefiJr/fmyImUAzeUq7rIHzALyomuPBc0RAHKTNHB5ps6o1RJGzfRcWlWybJ/K/ 3nZR1fYCTdaLcAVIoFXuL9/qjJUE+ei410lKNj765Ai4YnbhaW1RcCgxvcmuMui6+SGDHyv/SA3Mi FvnYvlwMcEMYlAudlgIO3qv1OqtxXogvz/9K97vFcA7a3tQqHVgNwaLCS0G2bvvzKUTua+OYaV4ZC 9JpCU9mQ==; Received: from [2a01:e34:ec5d:a741:8a4c:7c4e:dc4c:1787] (helo=ohm.rr44.fr) by hall.aurel32.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1omBWp-00CBbS-Of; Sat, 22 Oct 2022 12:14:55 +0200 Received: from aurel32 by ohm.rr44.fr with local (Exim 4.96) (envelope-from ) id 1omBWp-006MSl-1E; Sat, 22 Oct 2022 12:14:55 +0200 Date: Sat, 22 Oct 2022 12:14:55 +0200 From: Aurelien Jarno To: libc-alpha@sourceware.org Cc: Tulio Magno Quites Machado Filho , Joseph Myers Subject: Re: [PATCH v3] Avoid undefined behaviour in ibm128 implementation of llroundl (BZ #29488) Message-ID: Mail-Followup-To: libc-alpha@sourceware.org, Tulio Magno Quites Machado Filho , Joseph Myers References: <20221010060050.3741173-1-aurelien@aurel32.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221010060050.3741173-1-aurelien@aurel32.net> User-Agent: Mutt/2.2.7 (2022-08-07) X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Ping. Tulio (as powerpc machine maintainer) or Joseph (as math component maintainer), could you please have a look at this patch? On 2022-10-10 08:00, Aurelien Jarno wrote: > Detecting an overflow edge case depended on signed overflow of a long > long. Replace the additions and the overflow checks by > __builtin_add_overflow(). > --- > sysdeps/ieee754/ldbl-128ibm/s_llroundl.c | 21 +++++++++------------ > 1 file changed, 9 insertions(+), 12 deletions(-) > > This patch is based on the original patch from Michael Hudson-Doyle, > using __builtin_add_overflow() as suggested by Florian Weimer > > It passes all tests on ppc64el with gcc 12 with both -O2 and -O3. > > diff --git a/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c b/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c > index d85154e73a..d8c0de1faf 100644 > --- a/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c > +++ b/sysdeps/ieee754/ldbl-128ibm/s_llroundl.c > @@ -66,38 +66,35 @@ __llroundl (long double x) > /* Peg at max/min values, assuming that the above conversions do so. > Strictly speaking, we can return anything for values that overflow, > but this is more useful. */ > - res = hi + lo; > - > - /* This is just sign(hi) == sign(lo) && sign(res) != sign(hi). */ > - if (__glibc_unlikely (((~(hi ^ lo) & (res ^ hi)) < 0))) > + if (__glibc_unlikely (__builtin_add_overflow (hi, lo, &res))) > goto overflow; > > xh -= lo; > ldbl_canonicalize (&xh, &xl); > > - hi = res; > if (xh > 0.5) > { > - res += 1; > + if (__glibc_unlikely (__builtin_add_overflow (res, 1, &res))) > + goto overflow; > } > else if (xh == 0.5) > { > if (xl > 0.0 || (xl == 0.0 && res >= 0)) > - res += 1; > + if (__glibc_unlikely (__builtin_add_overflow (res, 1, &res))) > + goto overflow; > } > else if (-xh > 0.5) > { > - res -= 1; > + if (__glibc_unlikely (__builtin_add_overflow (res, -1, &res))) > + goto overflow; > } > else if (-xh == 0.5) > { > if (xl < 0.0 || (xl == 0.0 && res <= 0)) > - res -= 1; > + if (__glibc_unlikely (__builtin_add_overflow (res, -1, &res))) > + goto overflow; > } > > - if (__glibc_unlikely (((~(hi ^ (res - hi)) & (res ^ hi)) < 0))) > - goto overflow; > - > return res; > } > else > -- > 2.35.1 > > -- Aurelien Jarno GPG: 4096R/1DDD8C9B aurelien@aurel32.net http://www.aurel32.net