public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Add real_isdenormal.
@ 2022-09-03 13:48 Aldy Hernandez
  2022-09-03 18:44 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Aldy Hernandez @ 2022-09-03 13:48 UTC (permalink / raw)
  To: GCC patches; +Cc: Andrew MacLeod, Jakub Jelinek, Aldy Hernandez

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Add real_isdenormal.
  2022-09-03 13:48 [PATCH] Add real_isdenormal Aldy Hernandez
@ 2022-09-03 18:44 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2022-09-03 18:44 UTC (permalink / raw)
  To: gcc-patches



On 9/3/2022 7:48 AM, Aldy Hernandez via Gcc-patches wrote:
> 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.
OK.  And if there's any followups where you're doing similar kinds of 
factoring of duplicated real.* code, consider such changes pre-approved.

jeff


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-03 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-03 13:48 [PATCH] Add real_isdenormal Aldy Hernandez
2022-09-03 18:44 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).