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 902C13858418 for ; Sat, 3 Sep 2022 13:48:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 902C13858418 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=1662212920; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=q0o21R1j4dKHGZXfAvGa6Gz6VZpYO4ghZZl7VGpZHr4=; b=Ak5PjJspUXFJ+DpA/jGQVLyq3ae3/FCOrJqXI5AlrJ91ZkUyw10zkkuVg5jL7vhsYFgiRK fvxKz5xX8307f7LDE0TQufdaG8B/7tpEMm7MWsu1JMSD98nEHuhwDx/F6I71kDjJdcb3IE jD+5MPOtPa1PDQ3keCzb/xzZl9885cU= 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 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Jakub Jelinek , Aldy Hernandez 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 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 List-Id: 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 *); -- 2.37.1