From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670429160; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=y862ObR4on7CxJ3jBnJFfy4MsHXWTJF21EFlOrAVlbk=; b=Lt9jDINdciwnlvPywEuoeV9/vtc6oYxJcvigOy8mBxSCgP8S3CZ97LTNp9OxnSAvA10rdD ZFEVwF721DjoQ0ze9JQUdtVH9Zux2yejl7dx1J4yk9CxYfn70zQqlB+8Z7OnWaf1JseZ5x qbZEnZdTQrDZJUc7dg5iZoQPuWCFMCA= 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 From: Jakub Jelinek 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: Reply-To: Jakub Jelinek 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-Type: text/plain; charset=us-ascii 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 List-Id: 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. --- 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 Jakub