Message ID | 20220823103321.879429-1-aldyh@redhat.com |
---|---|
State | New, archived |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp881707wro; Tue, 23 Aug 2022 03:34:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR5U7sNNj5pwPp/N5+CT4C+n53qs9JhXUeAEr5iPi3yQun96ubMFfc4rDwy74c46iLiiDwyy X-Received: by 2002:a17:907:2816:b0:73d:7884:a399 with SMTP id eb22-20020a170907281600b0073d7884a399mr7247906ejc.125.1661250856023; Tue, 23 Aug 2022 03:34:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661250856; cv=none; d=google.com; s=arc-20160816; b=yvnjpYZAgH0GIR/rOSZXKABboPBlWwn+bjGXlHwXNgH5/SAlKO+iF48/vdndHl1y9B aiLjGW5L5AcX/swrnCcLzgTgsG43Bu/ONMh7nrFqdXLXvzN0htwDThHgJ4MkB2itYQB+ sTjuwdZyeau46QxEBzroIIuHvEFni978URa7946IX+lcmDokK/u8BCGgf3beTGSVcsdU S5WsZRjSWe3KR+svU/e0mgfGrX5QO+i9ltJpZdRDM4x6WcVYUmRNbDoV6YxjfYVrCSyh DFnCpyPfOUi7HKFegQKlYIEU45K9T5g1+y4vKFTtuEkPAzv5XbXvrlObwHHJEyvOfcio 9phA== 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-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=OmdBy/Wj4sdsdAq65SupVEEauKZJbEaCCk5igz/vbZM=; b=a8DKYLP1NJGaJL7vetp1VJhQoevkrBtn8bW3Q93b8wgtksAYhs5P+2T0e0FDrciQt6 EdpmxBhermlBLCTvrog83+bEQRzFTsQjfWYCmBVvdB9MWP/MoVQ2ffIoVg+16ZKJuP1S 47if/N11sWhjL7ABKtcyCBy/8Lgt15CHQeIBq++7K9fjGHPCIq+CYyF4PUBpFFXiI0w+ YeITVOAoWI9/E0IsEU+QQbT9Be2HmATzW4TOKjk1LPzNAYFQxSeKDRhNfk8hBpn6fGeg Ewukihp1lOpeiXDE68w9XgrNSVjadxefUZ2Z0unicWLa5Lh30qDw1bjBqi1GGiceeLV5 /sKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kLmckV9a; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f1-20020a1709064dc100b0073d5ed5bdfdsi7277742ejw.377.2022.08.23.03.34.15 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 03:34:16 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kLmckV9a; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 B44513858014 for <ouuuleilei@gmail.com>; Tue, 23 Aug 2022 10:34:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B44513858014 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661250854; bh=OmdBy/Wj4sdsdAq65SupVEEauKZJbEaCCk5igz/vbZM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kLmckV9aJLjPhoM+a7RyckzRDqmkGGyIMuz3DI67aPcWn77G7ljwiyDJi2nQxgNpZ IV4RPyHobl3iZO3cwy0FC1N5g2cKPNJ3dowGBlDxfGb0GiHv7sPJBDlD77W6QHv5/9 kiWyyY9YpPSka+Upr/84SikInau76Dtl6cBFT8tI= 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 26C0A3858D32 for <gcc-patches@gcc.gnu.org>; Tue, 23 Aug 2022 10:33:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 26C0A3858D32 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-497-wACDdraqO7uwSKzJWfgIFQ-1; Tue, 23 Aug 2022 06:33:29 -0400 X-MC-Unique: wACDdraqO7uwSKzJWfgIFQ-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 45AEA802526; Tue, 23 Aug 2022 10:33:29 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.193.180]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E59A1121315; Tue, 23 Aug 2022 10:33:27 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 27NAXOCO879473 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 12:33:24 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 27NAXOB1879472; Tue, 23 Aug 2022 12:33:24 +0200 To: GCC patches <gcc-patches@gcc.gnu.org> Subject: [PATCH] Add set/get functions for negative infinity in real.* Date: Tue, 23 Aug 2022 12:33:21 +0200 Message-Id: <20220823103321.879429-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Aldy Hernandez via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Aldy Hernandez <aldyh@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741947777662445628?= X-GMAIL-MSGID: =?utf-8?q?1741947777662445628?= |
Series |
Add set/get functions for negative infinity in real.*
|
|
Commit Message
Aldy Hernandez
Aug. 23, 2022, 10:33 a.m. UTC
For the frange implementation with endpoints I'm about to contribute, we need to set REAL_VALUE_TYPEs with negative infinity. The support is already there in real.cc, but it is awkward to get at. One could call real_inf() and then negate the value, but I've added the ability to pass the sign argument like many of the existing real.* functions. I've declared the functions in such a way to avoid changes to the existing code base: // Unchanged function returning true for either +-INF. bool real_isinf (const REAL_VALUE_TYPE *r); // New overload to be able to specify the sign. bool real_isinf (const REAL_VALUE_TYPE *r, int sign); // Replacement function for setting INF, defaults to +INF. void real_inf (REAL_VALUE_TYPE *, int sign = 0); Tested on x86-64 Linux. OK? gcc/ChangeLog: * real.cc (real_isinf): New overload. (real_inf): Add sign argument. * real.h (real_isinf): New overload. (real_inf): Add sign argument. --- gcc/real.cc | 14 +++++++++++--- gcc/real.h | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-)
Comments
Another real.* tweak. This time, adding a real_iszero() entry point to match the real_isnegzero. I could combine this patch with the negative infinity one in this thread if y'all would prefer. OK pending tests? p.s. I'd really like to go and benchmark all this real.* stuff (later), because I think we could inline a bunch of these functions in the header file. On Tue, Aug 23, 2022 at 12:33 PM Aldy Hernandez <aldyh@redhat.com> wrote: > > For the frange implementation with endpoints I'm about to contribute, > we need to set REAL_VALUE_TYPEs with negative infinity. The support > is already there in real.cc, but it is awkward to get at. One could > call real_inf() and then negate the value, but I've added the ability > to pass the sign argument like many of the existing real.* functions. > > I've declared the functions in such a way to avoid changes to the > existing code base: > > // Unchanged function returning true for either +-INF. > bool real_isinf (const REAL_VALUE_TYPE *r); > // New overload to be able to specify the sign. > bool real_isinf (const REAL_VALUE_TYPE *r, int sign); > // Replacement function for setting INF, defaults to +INF. > void real_inf (REAL_VALUE_TYPE *, int sign = 0); > > Tested on x86-64 Linux. > > OK? > > gcc/ChangeLog: > > * real.cc (real_isinf): New overload. > (real_inf): Add sign argument. > * real.h (real_isinf): New overload. > (real_inf): Add sign argument. > --- > gcc/real.cc | 14 +++++++++++--- > gcc/real.h | 5 ++++- > 2 files changed, 15 insertions(+), 4 deletions(-) > > diff --git a/gcc/real.cc b/gcc/real.cc > index 4e63b1449c5..f570ca8e85b 100644 > --- a/gcc/real.cc > +++ b/gcc/real.cc > @@ -1234,6 +1234,14 @@ real_isinf (const REAL_VALUE_TYPE *r) > return (r->cl == rvc_inf); > } > > +/* Determine whether a floating-point value X is infinite with SIGN. */ > + > +bool > +real_isinf (const REAL_VALUE_TYPE *r, int sign) > +{ > + return real_isinf (r) && r->sign == sign; > +} > + > /* Determine whether a floating-point value X is a NaN. */ > > bool > @@ -2484,12 +2492,12 @@ dconst_sqrt2_ptr (void) > return &value; > } > > -/* Fills R with +Inf. */ > +/* Fills R with Inf with SIGN. */ > > void > -real_inf (REAL_VALUE_TYPE *r) > +real_inf (REAL_VALUE_TYPE *r, int sign) > { > - get_inf (r, 0); > + get_inf (r, sign); > } > > /* Fills R with a NaN whose significand is described by STR. If QUIET, > diff --git a/gcc/real.h b/gcc/real.h > index 845ef29e3a4..76360b603fb 100644 > --- a/gcc/real.h > +++ b/gcc/real.h > @@ -277,6 +277,9 @@ extern bool real_compare (int, const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *) > /* Determine whether a floating-point value X is infinite. */ > extern bool real_isinf (const REAL_VALUE_TYPE *); > > +/* Determine whether a floating-point value X is infinite with SIGN. */ > +extern bool real_isinf (const REAL_VALUE_TYPE *, int sign); > + > /* Determine whether a floating-point value X is a NaN. */ > extern bool real_isnan (const REAL_VALUE_TYPE *); > > @@ -331,7 +334,7 @@ extern long real_to_target (long *, const REAL_VALUE_TYPE *, format_helper); > extern void real_from_target (REAL_VALUE_TYPE *, const long *, > format_helper); > > -extern void real_inf (REAL_VALUE_TYPE *); > +extern void real_inf (REAL_VALUE_TYPE *, int sign = 0); > > extern bool real_nan (REAL_VALUE_TYPE *, const char *, int, format_helper); > > -- > 2.37.1 >
On 8/23/2022 4:33 AM, Aldy Hernandez via Gcc-patches wrote: > For the frange implementation with endpoints I'm about to contribute, > we need to set REAL_VALUE_TYPEs with negative infinity. The support > is already there in real.cc, but it is awkward to get at. One could > call real_inf() and then negate the value, but I've added the ability > to pass the sign argument like many of the existing real.* functions. > > I've declared the functions in such a way to avoid changes to the > existing code base: > > // Unchanged function returning true for either +-INF. > bool real_isinf (const REAL_VALUE_TYPE *r); > // New overload to be able to specify the sign. > bool real_isinf (const REAL_VALUE_TYPE *r, int sign); > // Replacement function for setting INF, defaults to +INF. > void real_inf (REAL_VALUE_TYPE *, int sign = 0); > > Tested on x86-64 Linux. > > OK? > > gcc/ChangeLog: > > * real.cc (real_isinf): New overload. > (real_inf): Add sign argument. > * real.h (real_isinf): New overload. > (real_inf): Add sign argument. Funny in that I've fairly recently had the desire to do something a bit similar. Let's consider 0.5, which we have a dconsthalf, but we don't have dconstmhalf for -0.5. To get that value I create a dconsthalf object and flip its sign. Similarly for a variety of other special constants (particularly powers of two, but a few others as well). Consider making the "sign" argument a boolean. It's defined as a single bit bitfield in the real_value structure. We don't want folks to pass in values outside [0..1] for the sign if we can easily avoid it:-) jeff
On 8/26/2022 9:43 AM, Aldy Hernandez via Gcc-patches wrote: > Another real.* tweak. This time, adding a real_iszero() entry point > to match the real_isnegzero. I could combine this patch with the > negative infinity one in this thread if y'all would prefer. > > OK pending tests? > > p.s. I'd really like to go and benchmark all this real.* stuff > (later), because I think we could inline a bunch of these functions in > the header file. Same comments as the INF patch. jeff
On Fri, Aug 26, 2022 at 6:08 PM Jeff Law via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > On 8/23/2022 4:33 AM, Aldy Hernandez via Gcc-patches wrote: > > For the frange implementation with endpoints I'm about to contribute, > > we need to set REAL_VALUE_TYPEs with negative infinity. The support > > is already there in real.cc, but it is awkward to get at. One could > > call real_inf() and then negate the value, but I've added the ability > > to pass the sign argument like many of the existing real.* functions. > > > > I've declared the functions in such a way to avoid changes to the > > existing code base: > > > > // Unchanged function returning true for either +-INF. > > bool real_isinf (const REAL_VALUE_TYPE *r); > > // New overload to be able to specify the sign. > > bool real_isinf (const REAL_VALUE_TYPE *r, int sign); > > // Replacement function for setting INF, defaults to +INF. > > void real_inf (REAL_VALUE_TYPE *, int sign = 0); > > > > Tested on x86-64 Linux. > > > > OK? > > > > gcc/ChangeLog: > > > > * real.cc (real_isinf): New overload. > > (real_inf): Add sign argument. > > * real.h (real_isinf): New overload. > > (real_inf): Add sign argument. > > Funny in that I've fairly recently had the desire to do something a bit > similar. Let's consider 0.5, which we have a dconsthalf, but we don't > have dconstmhalf for -0.5. To get that value I create a dconsthalf > object and flip its sign. Similarly for a variety of other special > constants (particularly powers of two, but a few others as well). Ugh, yeah. I've been doing a lot of gymnastics in this space because frange's will have REAL_VALUE_TYPE endpoints. > > Consider making the "sign" argument a boolean. It's defined as a single > bit bitfield in the real_value structure. We don't want folks to pass > in values outside [0..1] for the sign if we can easily avoid it:-) I was trying to follow all the other functions in real.cc which have "int sign", though I suppose none of them are exported in the header file. OK pending tests? Aldy
On Fri, Aug 26, 2022 at 6:09 PM Jeff Law via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > On 8/26/2022 9:43 AM, Aldy Hernandez via Gcc-patches wrote: > > Another real.* tweak. This time, adding a real_iszero() entry point > > to match the real_isnegzero. I could combine this patch with the > > negative infinity one in this thread if y'all would prefer. > > > > OK pending tests? > > > > p.s. I'd really like to go and benchmark all this real.* stuff > > (later), because I think we could inline a bunch of these functions in > > the header file. > Same comments as the INF patch. OK pending tests? Aldy
On 8/26/2022 10:24 AM, Aldy Hernandez wrote: > On Fri, Aug 26, 2022 at 6:08 PM Jeff Law via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: >> >> >> On 8/23/2022 4:33 AM, Aldy Hernandez via Gcc-patches wrote: >>> For the frange implementation with endpoints I'm about to contribute, >>> we need to set REAL_VALUE_TYPEs with negative infinity. The support >>> is already there in real.cc, but it is awkward to get at. One could >>> call real_inf() and then negate the value, but I've added the ability >>> to pass the sign argument like many of the existing real.* functions. >>> >>> I've declared the functions in such a way to avoid changes to the >>> existing code base: >>> >>> // Unchanged function returning true for either +-INF. >>> bool real_isinf (const REAL_VALUE_TYPE *r); >>> // New overload to be able to specify the sign. >>> bool real_isinf (const REAL_VALUE_TYPE *r, int sign); >>> // Replacement function for setting INF, defaults to +INF. >>> void real_inf (REAL_VALUE_TYPE *, int sign = 0); >>> >>> Tested on x86-64 Linux. >>> >>> OK? >>> >>> gcc/ChangeLog: >>> >>> * real.cc (real_isinf): New overload. >>> (real_inf): Add sign argument. >>> * real.h (real_isinf): New overload. >>> (real_inf): Add sign argument. >> Funny in that I've fairly recently had the desire to do something a bit >> similar. Let's consider 0.5, which we have a dconsthalf, but we don't >> have dconstmhalf for -0.5. To get that value I create a dconsthalf >> object and flip its sign. Similarly for a variety of other special >> constants (particularly powers of two, but a few others as well). > Ugh, yeah. I've been doing a lot of gymnastics in this space because > frange's will have REAL_VALUE_TYPE endpoints. In our case we have instructions that can make of various FP constants, some of which may be negative. So we need to be able to recognize those constants. Leading to having to do similar gymnastics as what you're doing. > or > >> Consider making the "sign" argument a boolean. It's defined as a single >> bit bitfield in the real_value structure. We don't want folks to pass >> in values outside [0..1] for the sign if we can easily avoid it:-) > I was trying to follow all the other functions in real.cc which have > "int sign", though I suppose none of them are exported in the header > file. They probably pre-date using bool types in GCC. Feel free to update them if you need a mindless task at some point. > > OK pending tests? Of course. I should have noted that with such a change it'd pre-approved. jeff
On 8/26/2022 10:25 AM, Aldy Hernandez wrote: > On Fri, Aug 26, 2022 at 6:09 PM Jeff Law via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: >> >> >> On 8/26/2022 9:43 AM, Aldy Hernandez via Gcc-patches wrote: >>> Another real.* tweak. This time, adding a real_iszero() entry point >>> to match the real_isnegzero. I could combine this patch with the >>> negative infinity one in this thread if y'all would prefer. >>> >>> OK pending tests? >>> >>> p.s. I'd really like to go and benchmark all this real.* stuff >>> (later), because I think we could inline a bunch of these functions in >>> the header file. >> Same comments as the INF patch. > OK pending tests? Yes. Jeff
On Fri, Aug 26, 2022 at 6:34 PM Jeff Law <jeffreyalaw@gmail.com> wrote: > > > > On 8/26/2022 10:24 AM, Aldy Hernandez wrote: > > On Fri, Aug 26, 2022 at 6:08 PM Jeff Law via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > >> > >> > >> On 8/23/2022 4:33 AM, Aldy Hernandez via Gcc-patches wrote: > >>> For the frange implementation with endpoints I'm about to contribute, > >>> we need to set REAL_VALUE_TYPEs with negative infinity. The support > >>> is already there in real.cc, but it is awkward to get at. One could > >>> call real_inf() and then negate the value, but I've added the ability > >>> to pass the sign argument like many of the existing real.* functions. > >>> > >>> I've declared the functions in such a way to avoid changes to the > >>> existing code base: > >>> > >>> // Unchanged function returning true for either +-INF. > >>> bool real_isinf (const REAL_VALUE_TYPE *r); > >>> // New overload to be able to specify the sign. > >>> bool real_isinf (const REAL_VALUE_TYPE *r, int sign); > >>> // Replacement function for setting INF, defaults to +INF. > >>> void real_inf (REAL_VALUE_TYPE *, int sign = 0); > >>> > >>> Tested on x86-64 Linux. > >>> > >>> OK? > >>> > >>> gcc/ChangeLog: > >>> > >>> * real.cc (real_isinf): New overload. > >>> (real_inf): Add sign argument. > >>> * real.h (real_isinf): New overload. > >>> (real_inf): Add sign argument. > >> Funny in that I've fairly recently had the desire to do something a bit > >> similar. Let's consider 0.5, which we have a dconsthalf, but we don't > >> have dconstmhalf for -0.5. To get that value I create a dconsthalf > >> object and flip its sign. Similarly for a variety of other special > >> constants (particularly powers of two, but a few others as well). > > Ugh, yeah. I've been doing a lot of gymnastics in this space because > > frange's will have REAL_VALUE_TYPE endpoints. > In our case we have instructions that can make of various FP constants, > some of which may be negative. So we need to be able to recognize those > constants. Leading to having to do similar gymnastics as what you're doing. It seems real.* needs some minor TLC. For one, a lot of these functions should be inlined. I suppose it wasn't meant to be abused the way we're about to in range-op-float.cc :-). Thanks. Aldy
diff --git a/gcc/real.cc b/gcc/real.cc index 4e63b1449c5..f570ca8e85b 100644 --- a/gcc/real.cc +++ b/gcc/real.cc @@ -1234,6 +1234,14 @@ real_isinf (const REAL_VALUE_TYPE *r) return (r->cl == rvc_inf); } +/* Determine whether a floating-point value X is infinite with SIGN. */ + +bool +real_isinf (const REAL_VALUE_TYPE *r, int sign) +{ + return real_isinf (r) && r->sign == sign; +} + /* Determine whether a floating-point value X is a NaN. */ bool @@ -2484,12 +2492,12 @@ dconst_sqrt2_ptr (void) return &value; } -/* Fills R with +Inf. */ +/* Fills R with Inf with SIGN. */ void -real_inf (REAL_VALUE_TYPE *r) +real_inf (REAL_VALUE_TYPE *r, int sign) { - get_inf (r, 0); + get_inf (r, sign); } /* Fills R with a NaN whose significand is described by STR. If QUIET, diff --git a/gcc/real.h b/gcc/real.h index 845ef29e3a4..76360b603fb 100644 --- a/gcc/real.h +++ b/gcc/real.h @@ -277,6 +277,9 @@ extern bool real_compare (int, const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *) /* Determine whether a floating-point value X is infinite. */ extern bool real_isinf (const REAL_VALUE_TYPE *); +/* Determine whether a floating-point value X is infinite with SIGN. */ +extern bool real_isinf (const REAL_VALUE_TYPE *, int sign); + /* Determine whether a floating-point value X is a NaN. */ extern bool real_isnan (const REAL_VALUE_TYPE *); @@ -331,7 +334,7 @@ extern long real_to_target (long *, const REAL_VALUE_TYPE *, format_helper); extern void real_from_target (REAL_VALUE_TYPE *, const long *, format_helper); -extern void real_inf (REAL_VALUE_TYPE *); +extern void real_inf (REAL_VALUE_TYPE *, int sign = 0); extern bool real_nan (REAL_VALUE_TYPE *, const char *, int, format_helper);