From patchwork Wed Dec 7 12:10:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 30815 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp141369wrr; Wed, 7 Dec 2022 04:11:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf6YylY+ITbA5jwk96b8AX71kK1fdAa1qeoy7OPRn4jnCJyeTQULmVxvTKmn+x5S7aPhtZYc X-Received: by 2002:aa7:dccf:0:b0:46d:66e6:5dd4 with SMTP id w15-20020aa7dccf000000b0046d66e65dd4mr1880902edu.373.1670415075064; Wed, 07 Dec 2022 04:11:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670415075; cv=none; d=google.com; s=arc-20160816; b=wHlfFUzwoaE59L4V4cjP9TpP9I/Ib1LcbKIjCgvEwpBiAqe6gwRRPNOCNlLOuxgVQ0 Nqalv2tV07UK/ViamoF+ckQtUPBBqx1SRFRtGmtTu8HfTQ952DCZmtBuKPJGfscENqd2 ZQXJifY7utoJov25f70TboCgngtDrgcIJaSHxGNLfgb3Wd8Sme5BGvtnO7bMz8Z2cQik cH6g39WfQyY1wFkLqnz9tmXgUmv3iHfYxAaguyfFct8i8zNmSED0NQne6FLKTEyxd2P1 cPd2Q9W6G/AaICrJm52sGUYa/KP/THps30KqahcTt2nvW0/VH968EDY3IK8BPc+tINR1 8/UQ== 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:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=rgHongArtKy9laZ6VdvWzcrqIw2hkf3M67TKcPxFh1o=; b=lKOyJfoeoaV68ZWYjzTMkHyzCyQtUSjDg8YX2KhwyU0oEmwxrHusI2WTraSQi+cdJP kuhtsr123cG4aZEtHkr46TFJc64MGWmJ6zsCry1NxbIDUtCB4UGtbhRtwDnIKfN4hLGN sYSI10mVk2D8FRakWDA7PJuS5jggfqyJzMGHhSRl3wrzpb4wF3v6MmFriVtnAHS6QpIw anJuGOiiIGENeiEuFzzTJXQIrxQS0PMHXwF13JONcmrjLqkFsmoQ4uGQn1qwrABO9YzY U36F+PWhZkHwx74VvNAwiNd4Cb/rKHtoM8MsAE5CZ3ihxA7AyUEZh5PdIaqgiskQM7UF vJvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=c0MX5Pve; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y19-20020a056402359300b0046d594327b8si1821358edc.319.2022.12.07.04.11.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 04:11:15 -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=c0MX5Pve; 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 1E10438B6362 for ; Wed, 7 Dec 2022 12:11:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E10438B6362 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670415074; bh=rgHongArtKy9laZ6VdvWzcrqIw2hkf3M67TKcPxFh1o=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=c0MX5Pveqj977yJiLiW6TXgDngJ23RgDIbk37UuA2UxFloU3sncTh3vSM09j/ehya iIVevRf33VbJaCrhqnXhwNCYfCtgKeyr8z6ILCzCCRVTNMk8yX3ChXu5/kcHc8sihN uaM/T6HLEiLaAgVaGe5nLt6roolJWCxNznL2ipIk= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 8799738B81F7 for ; Wed, 7 Dec 2022 12:10:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8799738B81F7 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-554-bCBDRsO1Mj63e5sKWN7Bzw-1; Wed, 07 Dec 2022 07:10:27 -0500 X-MC-Unique: bCBDRsO1Mj63e5sKWN7Bzw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CEB0A800186 for ; Wed, 7 Dec 2022 12:10:26 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E83D1415100; Wed, 7 Dec 2022 12:10:26 +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 2B7CAM5a091499 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 7 Dec 2022 13:10:22 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2B7CALeI091498; Wed, 7 Dec 2022 13:10:21 +0100 Date: Wed, 7 Dec 2022 13:10:21 +0100 To: Aldy Hernandez Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] range-op-float: frange_arithmetic tweaks for MODE_COMPOSITE_P Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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?1751557157961141065?= X-GMAIL-MSGID: =?utf-8?q?1751557157961141065?= Hi! As mentioned in PR107967, ibm-ldouble-format documents that +- has 1ulp accuracy, * 2ulps and / 3ulps. So, even if the result is exact, we need to widen the range a little bit. The following patch does that. I just wonder what it means for reverse division (the op1_range case), which we implement through multiplication, when division has 3ulps error and multiplication just 2ulps. In any case, this format is a mess and for non-default rounding modes can't be trusted at all, instead of +inf or something close to it it happily computes -inf. 2022-12-07 Jakub Jelinek * range-op-float.cc (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 12:50:40.812085139 +0100 @@ -344,22 +344,70 @@ frange_arithmetic (enum tree_code code, } } } - if (round && (inexact || !real_identical (&result, &value))) + if (!inexact && !real_identical (&result, &value)) + inexact = true; + if (round && (inexact || mode_composite)) { if (mode_composite) { - if (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); + if (inexact) + frange_nextafter (DFmode, tmp, inf); + switch (code) + { + case PLUS_EXPR: + case MINUS_EXPR: + // ibm-ldouble-format documents 1ulp for + and -. + frange_nextafter (DFmode, tmp, inf); + break; + case MULT_EXPR: + // ibm-ldouble-format documents 2ulps for *. + frange_nextafter (DFmode, tmp, inf); + frange_nextafter (DFmode, tmp, inf); + break; + case RDIV_EXPR: + // ibm-ldouble-format documents 3ulps for /. + frange_nextafter (DFmode, tmp, inf); + frange_nextafter (DFmode, tmp, inf); + frange_nextafter (DFmode, tmp, inf); + break; + default: + if (!inexact) + return; + break; + } real_convert (&result, mode, &tmp); return; } } - frange_nextafter (mode, result, inf); + if (inexact) + 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; + } } }