From patchwork Tue Aug 23 10:33:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 672 Return-Path: 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 (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 ; 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 ; 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 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez 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?1741947777662445628?= X-GMAIL-MSGID: =?utf-8?q?1741947777662445628?= 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);