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: 56942 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED6143858291 for ; Tue, 23 Aug 2022 10:34:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED6143858291 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661250841; 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=m0/9uiE1LhfrTEgGdlvhm6RwQIc9PyVORKFlaWI6K4kluq4cCkdx0DV6fjPd7g6ea HmSKr2EhF22ntblvIYkizVFNtzZAGYQYs/+SQAAzuJA6D0TMu8XgWljaLcK1uluEgT OcqWzCj6zpsrC/Ad0I+jNI5RZEFuAPNFRzgeuLN4= 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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);