From patchwork Sat Sep 3 13:48:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 948 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1189308wro; Sat, 3 Sep 2022 06:49:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Oi4+88HwrIhQTGf8E/yeA4qfTrGzz/bmez4rqD1eBy1eUhCDwcV5Druu6l3WlH3Y0IhVy X-Received: by 2002:a05:6402:1f02:b0:445:f674:eac0 with SMTP id b2-20020a0564021f0200b00445f674eac0mr35681126edb.370.1662212963685; Sat, 03 Sep 2022 06:49:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662212963; cv=none; d=google.com; s=arc-20160816; b=bv3LEwRVIeY56wF8OUajKNfJ3li0A7tkdF78FhHMfD4eRoeIaTI0yoqGKqH9NEfqOD MtRtjb8rzCf0PIxyqN+HhLfa7YFIhYpPLO40uvSCadvat6vA8RbgiOqW5ADwziMyuyiK XQ36fuVveVpTVR0yNM6BoOXYT1uxg5CgLQNOXH/auHltIyUzR4F0RO8OQmNlg8QX1c58 RQ+HxfYT/k4VtSCZz2WWXrxqAK/XEiGIvX3+VpB3g2KC2fMQx6zVfZAEUC5dGJwBhlwG gZJiGGjIP6Ty8MdQAwZVDSpD2SLd34LKXrH2Lz6e3k9YztS3T1v5GJmbs5ukNNHoXw80 lSZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=q0o21R1j4dKHGZXfAvGa6Gz6VZpYO4ghZZl7VGpZHr4=; b=RXj/eIhiSO0OS87YVIjOJWuYKn7a02S0DgH9bYL7RReYDCzLwBODW3wAqcEedlv3oc swO02PLXdjNX3PGpCKjUZgP3L7lgJHeAyqubt/G1TyVXAv+S8RuR5AbCv05xBi2QlZ2n q7sbzLY9MKHrPk70MVVKsfADL6bs3ZR7GZeZEVXka/QhanUf3AmftPiTDgz/ldRN+RTF IRJbJ3HyKTv3L4Hn988ajYB7z49MKZLSNCptpp/t9MhHQLVq+03yEwHbCnyAjghJrVLQ Bppp1NdtY82VD+7Up+a4RpzIvzbJC5hyktrdG7aqErX3bXZ40mePCzxVpUcO0Fl8pz53 NeZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=b1xUU5mL; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x7-20020a05640226c700b00448786a19fcsi4266346edd.426.2022.09.03.06.49.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Sep 2022 06:49:23 -0700 (PDT) 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=b1xUU5mL; 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 BC1D9385741C for ; Sat, 3 Sep 2022 13:49:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC1D9385741C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662212962; bh=q0o21R1j4dKHGZXfAvGa6Gz6VZpYO4ghZZl7VGpZHr4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=b1xUU5mLVzKqgQxMfWLvAR6N1V4Dr7Bx6AgGHDx9iNsPQrspJtat2DeiW9esa9PQh qdyTTIVtdYtKyvW3CvELqFNanb5MGcpx1Qg3Au7BKru69XDCH0SXiQei74vI9XbyHk nG/Z7u8bNyR+yNAYV7B5dlcvgtEGHtnErvddCZTE= 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 902C13858418 for ; Sat, 3 Sep 2022 13:48:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 902C13858418 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-173-z9vkFyX8Np6tLRRSogSjZw-1; Sat, 03 Sep 2022 09:48:38 -0400 X-MC-Unique: z9vkFyX8Np6tLRRSogSjZw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8C821185A794 for ; Sat, 3 Sep 2022 13:48:38 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 30482492C3B; Sat, 3 Sep 2022 13:48:38 +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 283DmZrZ3038812 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 3 Sep 2022 15:48:35 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 283DmZqq3038811; Sat, 3 Sep 2022 15:48:35 +0200 To: GCC patches Subject: [PATCH] Add real_isdenormal. Date: Sat, 3 Sep 2022 15:48:27 +0200 Message-Id: <20220903134827.3038778-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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 Cc: 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?1742956620693323187?= X-GMAIL-MSGID: =?utf-8?q?1742956620693323187?= There are 6 idioms of the same check and I'd like to add more. It seems there are macros as well as functions for things like REAL_VALUE_ISINF and REAL_VALUE_NEGATIVE. I don't know if there was historical need for this duplicity, but I think it's cleaner if we start gravitating towards inline functions only. OK? gcc/ChangeLog: * real.cc (encode_ieee_single): Use real_isdenormal. (encode_ieee_double): Same. (encode_ieee_extended): Same. (encode_ieee_quad): Same. (encode_ieee_half): Same. (encode_arm_bfloat_half): Same. * real.h (real_isdenormal): New. --- gcc/real.cc | 12 ++++++------ gcc/real.h | 7 +++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gcc/real.cc b/gcc/real.cc index 96f05ec68ca..73bbac645d9 100644 --- a/gcc/real.cc +++ b/gcc/real.cc @@ -2954,7 +2954,7 @@ encode_ieee_single (const struct real_format *fmt, long *buf, { unsigned long image, sig, exp; unsigned long sign = r->sign; - bool denormal = (r->sig[SIGSZ-1] & SIG_MSB) == 0; + bool denormal = real_isdenormal (r); image = sign << 31; sig = (r->sig[SIGSZ-1] >> (HOST_BITS_PER_LONG - 24)) & 0x7fffff; @@ -3175,7 +3175,7 @@ encode_ieee_double (const struct real_format *fmt, long *buf, { unsigned long image_lo, image_hi, sig_lo, sig_hi, exp; unsigned long sign = r->sign; - bool denormal = (r->sig[SIGSZ-1] & SIG_MSB) == 0; + bool denormal = real_isdenormal (r); image_hi = sign << 31; image_lo = 0; @@ -3433,7 +3433,7 @@ encode_ieee_extended (const struct real_format *fmt, long *buf, const REAL_VALUE_TYPE *r) { unsigned long image_hi, sig_hi, sig_lo; - bool denormal = (r->sig[SIGSZ-1] & SIG_MSB) == 0; + bool denormal = real_isdenormal (r); image_hi = r->sign << 15; sig_hi = sig_lo = 0; @@ -3964,7 +3964,7 @@ encode_ieee_quad (const struct real_format *fmt, long *buf, { unsigned long image3, image2, image1, image0, exp; unsigned long sign = r->sign; - bool denormal = (r->sig[SIGSZ-1] & SIG_MSB) == 0; + bool denormal = real_isdenormal (r); REAL_VALUE_TYPE u; image3 = sign << 31; @@ -4721,7 +4721,7 @@ encode_ieee_half (const struct real_format *fmt, long *buf, { unsigned long image, sig, exp; unsigned long sign = r->sign; - bool denormal = (r->sig[SIGSZ-1] & SIG_MSB) == 0; + bool denormal = real_isdenormal (r); image = sign << 15; sig = (r->sig[SIGSZ-1] >> (HOST_BITS_PER_LONG - 11)) & 0x3ff; @@ -4835,7 +4835,7 @@ encode_arm_bfloat_half (const struct real_format *fmt, long *buf, { unsigned long image, sig, exp; unsigned long sign = r->sign; - bool denormal = (r->sig[SIGSZ-1] & SIG_MSB) == 0; + bool denormal = real_isdenormal (r); image = sign << 15; sig = (r->sig[SIGSZ-1] >> (HOST_BITS_PER_LONG - 8)) & 0x7f; diff --git a/gcc/real.h b/gcc/real.h index 2f490ef9b72..f9528d765ec 100644 --- a/gcc/real.h +++ b/gcc/real.h @@ -286,6 +286,13 @@ extern bool real_isnan (const REAL_VALUE_TYPE *); /* Determine whether a floating-point value X is a signaling NaN. */ extern bool real_issignaling_nan (const REAL_VALUE_TYPE *); +/* Determine whether a floating-point value X is a denormal. */ +inline bool +real_isdenormal (const REAL_VALUE_TYPE *r) +{ + return (r->sig[SIGSZ-1] & SIG_MSB) == 0; +} + /* Determine whether a floating-point value X is finite. */ extern bool real_isfinite (const REAL_VALUE_TYPE *);