From patchwork Wed Dec 7 16:05:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 30909 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp269138wrr; Wed, 7 Dec 2022 08:06:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf76osq4FI8kVZPngrvcjotzUqsfhHKyUVg9qw3kOTrLW+m1eNQA0OzGUgnfpI9z1pjmAQhj X-Received: by 2002:a17:906:a10c:b0:78d:8bcf:bb47 with SMTP id t12-20020a170906a10c00b0078d8bcfbb47mr62058769ejy.525.1670429205779; Wed, 07 Dec 2022 08:06:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670429205; cv=none; d=google.com; s=arc-20160816; b=Vnuu9rlAJ7/DKBg9rL3X3TkH+5te7bCoRPDKRTIEzT5oBwYquwVjLbhpRN3fARvBvx poI6Ymy4GheYKcLgSffBBbKUwXPeDa4eoY3r6ZC4/dBOvzoswotIS/2JrGSbpVQ63KQP qgXlT7BkHLN5xOpa1VY/5x5AQnqGMHHb6WlgXWjIbv/lJcAa4utx9/jly/dK59ftVFJ5 T7lpsgPxIyUq58mEai5GkEZi+ekCOny5g0NdHtexGeEx2hRjIqvfbiz8lm3sI8z8yv4Z NQddTe8A2ZxTo1ah5b1HWD9Z/ShYz7vVtZvyIUp3D1sQTrlYb10uuM4TLBaA3HTiwIoJ DC8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:in-reply-to:mime-version:references:message-id :subject:cc:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=y862ObR4on7CxJ3jBnJFfy4MsHXWTJF21EFlOrAVlbk=; b=ns+S5zSghP8tNlBpmRL4f9tswtv7fdtwgLITc1DW2rP/Ggkx/5zjfbUe44Sd9ZWw+w 2NlFli+HkW5cFuZ7l8Xm3GQfFS9hvfZWihePpFIGkPaNrgzKA3T8Y1+cxvMmmUsqw2RW iK+GVpbRcPjQ1QF9XimnzvLttHGPaW2muziV5KJeGGv/nMbYvPOHO61CpDpCY8lrV7xj bJYzIE41zXIQwFh/e2yFi5Z7iZNKG+1APF7UxmhRxG3Ak7CXiPPkLyRy7qTGgnxBJez/ tT1sMQMG9PPnObikAQfkGnmgvbJC6SEWnqgMqE32LKBxqI0Q75EaysrnT5ZwPruInx7d xXeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DjCt8E3I; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v6-20020a056402348600b00469322471e2si5933977edc.534.2022.12.07.08.06.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 08:06:45 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DjCt8E3I; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C54F5382E449 for ; Wed, 7 Dec 2022 16:06:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C54F5382E449 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670429204; bh=y862ObR4on7CxJ3jBnJFfy4MsHXWTJF21EFlOrAVlbk=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=DjCt8E3Ipn+leoQylin+sa0JJT5+Rf8XLUY9kR+5EBYra/7PQ2zi8DrH6CSMsIoS3 Zga/zMG79wZSDX+jBW/ftJT+HqUTCDtIjEvI/vwm29ZgjD48QdgXeLKD8y6fZE5oG1 sFnHtv29MEs0XJGw+LZfd4/xzfHhP5xCnsIz3vRA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id C207F382E443 for ; Wed, 7 Dec 2022 16:06:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C207F382E443 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-557-usdqxdLEPKu-B6KLAePtMw-1; Wed, 07 Dec 2022 11:05:58 -0500 X-MC-Unique: usdqxdLEPKu-B6KLAePtMw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AA6061012440 for ; Wed, 7 Dec 2022 16:05:58 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A27E1121314; Wed, 7 Dec 2022 16:05:58 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 2B7G5rWa098617 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 7 Dec 2022 17:05:54 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2B7G5rnB098616; Wed, 7 Dec 2022 17:05:53 +0100 Date: Wed, 7 Dec 2022 17:05:53 +0100 To: Aldy Hernandez Cc: gcc-patches@gcc.gnu.org, Andrew MacLeod Subject: [PATCH] range-op-float, v2: frange_arithmetic tweaks for MODE_COMPOSITE_P Message-ID: References: <851fe74e-e4da-7151-247d-41da27628b4e@redhat.com> <6b629fef-c03a-f323-9408-d8d2ad7b37b9@redhat.com> MIME-Version: 1.0 In-Reply-To: <6b629fef-c03a-f323-9408-d8d2ad7b37b9@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751571974987141302?= X-GMAIL-MSGID: =?utf-8?q?1751571974987141302?= On Wed, Dec 07, 2022 at 04:38:14PM +0100, Aldy Hernandez wrote: > > So, perhaps a combination of that, change frange_nextafter to do the above > > and change frange_arithmetic for the initial inexact rounding only to > > do it by hand using range_nextafter and starting from value. > > Either way is fine. Whatever is cleaner. Now in patch form: 2022-12-07 Jakub Jelinek * range-op-float.cc (frange_nextafter): For MODE_COMPOSITE_P from denormal or zero, use real_nextafter on DFmode with conversions around it. (frange_arithmetic): For mode_composite, on top of rounding in the right direction accept extra 1ulp error for PLUS/MINUS_EXPR, extra 2ulps error for MULT_EXPR and extra 3ulps error for RDIV_EXPR. Jakub --- gcc/range-op-float.cc.jj 2022-12-07 12:46:01.536123757 +0100 +++ gcc/range-op-float.cc 2022-12-07 16:58:02.406062286 +0100 @@ -254,10 +254,21 @@ frange_nextafter (enum machine_mode mode REAL_VALUE_TYPE &value, const REAL_VALUE_TYPE &inf) { - const real_format *fmt = REAL_MODE_FORMAT (mode); - REAL_VALUE_TYPE tmp; - real_nextafter (&tmp, fmt, &value, &inf); - value = tmp; + if (MODE_COMPOSITE_P (mode) + && (real_isdenormal (&value, mode) || real_iszero (&value))) + { + // IBM extended denormals only have DFmode precision. + REAL_VALUE_TYPE tmp, tmp2; + real_convert (&tmp2, DFmode, &value); + real_nextafter (&tmp, REAL_MODE_FORMAT (DFmode), &tmp2, &inf); + real_convert (&value, mode, &tmp); + } + else + { + REAL_VALUE_TYPE tmp; + real_nextafter (&tmp, REAL_MODE_FORMAT (mode), &value, &inf); + value = tmp; + } } // Like real_arithmetic, but round the result to INF if the operation @@ -324,21 +335,40 @@ frange_arithmetic (enum tree_code code, } if (round && (inexact || !real_identical (&result, &value))) { - if (mode_composite) + if (mode_composite + && (real_isdenormal (&result, mode) || real_iszero (&result))) { - if (real_isdenormal (&result, mode) - || real_iszero (&result)) - { - // IBM extended denormals only have DFmode precision. - REAL_VALUE_TYPE tmp; - real_convert (&tmp, DFmode, &value); - frange_nextafter (DFmode, tmp, inf); - real_convert (&result, mode, &tmp); - return; - } + // IBM extended denormals only have DFmode precision. + REAL_VALUE_TYPE tmp, tmp2; + real_convert (&tmp2, DFmode, &value); + real_nextafter (&tmp, REAL_MODE_FORMAT (DFmode), &tmp2, &inf); + real_convert (&result, mode, &tmp); } - frange_nextafter (mode, result, inf); + else + frange_nextafter (mode, result, inf); } + if (mode_composite) + switch (code) + { + case PLUS_EXPR: + case MINUS_EXPR: + // ibm-ldouble-format documents 1ulp for + and -. + frange_nextafter (mode, result, inf); + break; + case MULT_EXPR: + // ibm-ldouble-format documents 2ulps for *. + frange_nextafter (mode, result, inf); + frange_nextafter (mode, result, inf); + break; + case RDIV_EXPR: + // ibm-ldouble-format documents 3ulps for /. + frange_nextafter (mode, result, inf); + frange_nextafter (mode, result, inf); + frange_nextafter (mode, result, inf); + break; + default: + break; + } } // Crop R to [-INF, MAX] where MAX is the maximum representable number