*[PATCH] Add set/get functions for negative infinity in real.*@ 2022-08-23 10:33 Aldy Hernandez2022-08-26 15:43 ` Aldy Hernandez 2022-08-26 16:07 ` Jeff Law 0 siblings, 2 replies; 10+ messages in thread From: Aldy Hernandez @ 2022-08-23 10:33 UTC (permalink / raw) To: 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); -- 2.37.1 ^ permalink raw reply [flat|nested] 10+ messages in thread

*Re: [PATCH] Add set/get functions for negative infinity in real.*2022-08-23 10:33 [PATCH] Add set/get functions for negative infinity in real.* Aldy Hernandez@ 2022-08-26 15:43 ` Aldy Hernandez2022-08-26 15:43 ` Aldy Hernandez 2022-08-26 16:08 ` Jeff Law 2022-08-26 16:07 ` Jeff Law 1 sibling, 2 replies; 10+ messages in thread From: Aldy Hernandez @ 2022-08-26 15:43 UTC (permalink / raw) To: GCC patches, Jakub Jelinek;+Cc:Richard Biener, Andrew MacLeod [-- Attachment #1: Type: text/plain, Size: 3450 bytes --] Another real.* tweak. This time, adding a real_iszero() entry point to match the real_isnegzero. I could combine this patch with the negative infinity one in this thread if y'all would prefer. OK pending tests? p.s. I'd really like to go and benchmark all this real.* stuff (later), because I think we could inline a bunch of these functions in the header file. On Tue, Aug 23, 2022 at 12:33 PM Aldy Hernandez <aldyh@redhat.com> wrote: > > 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); > > -- > 2.37.1 > [-- Attachment #2: 0005-Add-real_iszero-to-real.patch --] [-- Type: text/x-patch, Size: 1849 bytes --] From 8bedd64a6b8df23caf78f5f411dc17e30ad35e88 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez <aldyh@redhat.com> Date: Fri, 26 Aug 2022 16:57:09 +0200 Subject: [PATCH] Add real_iszero to real.* We have real_isnegzero but no real_iszero. We could memcmp with 0, but that's just ugly. gcc/ChangeLog: * real.cc (real_iszero): New. * real.h (real_iszero): New. --- gcc/real.cc | 16 ++++++++++++++++ gcc/real.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/gcc/real.cc b/gcc/real.cc index f570ca8e85b..d362680fe9b 100644 --- a/gcc/real.cc +++ b/gcc/real.cc @@ -1272,6 +1272,22 @@ real_isneg (const REAL_VALUE_TYPE *r) return r->sign; } +/* Determine whether a floating-point value X is plus or minus zero. */ + +bool +real_iszero (const REAL_VALUE_TYPE *r) +{ + return r->cl == rvc_zero; +} + +/* Determine whether a floating-point value X is zero with SIGN. */ + +bool +real_iszero (const REAL_VALUE_TYPE *r, int sign) +{ + return real_iszero (r) && r->sign == sign; +} + /* Determine whether a floating-point value X is minus zero. */ bool diff --git a/gcc/real.h b/gcc/real.h index 76360b603fb..20d85378855 100644 --- a/gcc/real.h +++ b/gcc/real.h @@ -295,6 +295,12 @@ extern bool real_isneg (const REAL_VALUE_TYPE *); /* Determine whether a floating-point value X is minus zero. */ extern bool real_isnegzero (const REAL_VALUE_TYPE *); +/* Determine whether a floating-point value X is plus or minus zero. */ +extern bool real_iszero (const REAL_VALUE_TYPE *); + +/* Determine whether a floating-point value X is zero with SIGN. */ +extern bool real_iszero (const REAL_VALUE_TYPE *, int sign); + /* Test relationships between reals. */ extern bool real_identical (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *); extern bool real_equal (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *); -- 2.37.1 ^ permalink raw reply [flat|nested] 10+ messages in thread

*Re: [PATCH] Add set/get functions for negative infinity in real.*2022-08-26 15:43 ` Aldy Hernandez@ 2022-08-26 15:43 ` Aldy Hernandez2022-08-26 16:08 ` Jeff Law 1 sibling, 0 replies; 10+ messages in thread From: Aldy Hernandez @ 2022-08-26 15:43 UTC (permalink / raw) To: GCC patches, Jakub Jelinek [-- Attachment #1: Type: text/plain, Size: 3450 bytes --] Another real.* tweak. This time, adding a real_iszero() entry point to match the real_isnegzero. I could combine this patch with the negative infinity one in this thread if y'all would prefer. OK pending tests? p.s. I'd really like to go and benchmark all this real.* stuff (later), because I think we could inline a bunch of these functions in the header file. On Tue, Aug 23, 2022 at 12:33 PM Aldy Hernandez <aldyh@redhat.com> wrote: > > 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); > > -- > 2.37.1 > [-- Attachment #2: 0005-Add-real_iszero-to-real.patch --] [-- Type: text/x-patch, Size: 1849 bytes --] From 8bedd64a6b8df23caf78f5f411dc17e30ad35e88 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez <aldyh@redhat.com> Date: Fri, 26 Aug 2022 16:57:09 +0200 Subject: [PATCH] Add real_iszero to real.* We have real_isnegzero but no real_iszero. We could memcmp with 0, but that's just ugly. gcc/ChangeLog: * real.cc (real_iszero): New. * real.h (real_iszero): New. --- gcc/real.cc | 16 ++++++++++++++++ gcc/real.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/gcc/real.cc b/gcc/real.cc index f570ca8e85b..d362680fe9b 100644 --- a/gcc/real.cc +++ b/gcc/real.cc @@ -1272,6 +1272,22 @@ real_isneg (const REAL_VALUE_TYPE *r) return r->sign; } +/* Determine whether a floating-point value X is plus or minus zero. */ + +bool +real_iszero (const REAL_VALUE_TYPE *r) +{ + return r->cl == rvc_zero; +} + +/* Determine whether a floating-point value X is zero with SIGN. */ + +bool +real_iszero (const REAL_VALUE_TYPE *r, int sign) +{ + return real_iszero (r) && r->sign == sign; +} + /* Determine whether a floating-point value X is minus zero. */ bool diff --git a/gcc/real.h b/gcc/real.h index 76360b603fb..20d85378855 100644 --- a/gcc/real.h +++ b/gcc/real.h @@ -295,6 +295,12 @@ extern bool real_isneg (const REAL_VALUE_TYPE *); /* Determine whether a floating-point value X is minus zero. */ extern bool real_isnegzero (const REAL_VALUE_TYPE *); +/* Determine whether a floating-point value X is plus or minus zero. */ +extern bool real_iszero (const REAL_VALUE_TYPE *); + +/* Determine whether a floating-point value X is zero with SIGN. */ +extern bool real_iszero (const REAL_VALUE_TYPE *, int sign); + /* Test relationships between reals. */ extern bool real_identical (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *); extern bool real_equal (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *); -- 2.37.1 ^ permalink raw reply [flat|nested] 10+ messages in thread

*Re: [PATCH] Add set/get functions for negative infinity in real.*2022-08-23 10:33 [PATCH] Add set/get functions for negative infinity in real.* Aldy Hernandez 2022-08-26 15:43 ` Aldy Hernandez@ 2022-08-26 16:07 ` Jeff Law2022-08-26 16:24 ` Aldy Hernandez 1 sibling, 1 reply; 10+ messages in thread From: Jeff Law @ 2022-08-26 16:07 UTC (permalink / raw) To: gcc-patches On 8/23/2022 4:33 AM, Aldy Hernandez via Gcc-patches wrote: > 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. Funny in that I've fairly recently had the desire to do something a bit similar. Let's consider 0.5, which we have a dconsthalf, but we don't have dconstmhalf for -0.5. To get that value I create a dconsthalf object and flip its sign. Similarly for a variety of other special constants (particularly powers of two, but a few others as well). Consider making the "sign" argument a boolean. It's defined as a single bit bitfield in the real_value structure. We don't want folks to pass in values outside [0..1] for the sign if we can easily avoid it:-) jeff ^ permalink raw reply [flat|nested] 10+ messages in thread

*Re: [PATCH] Add set/get functions for negative infinity in real.*2022-08-26 15:43 ` Aldy Hernandez 2022-08-26 15:43 ` Aldy Hernandez@ 2022-08-26 16:08 ` Jeff Law2022-08-26 16:25 ` Aldy Hernandez 1 sibling, 1 reply; 10+ messages in thread From: Jeff Law @ 2022-08-26 16:08 UTC (permalink / raw) To: gcc-patches On 8/26/2022 9:43 AM, Aldy Hernandez via Gcc-patches wrote: > Another real.* tweak. This time, adding a real_iszero() entry point > to match the real_isnegzero. I could combine this patch with the > negative infinity one in this thread if y'all would prefer. > > OK pending tests? > > p.s. I'd really like to go and benchmark all this real.* stuff > (later), because I think we could inline a bunch of these functions in > the header file. Same comments as the INF patch. jeff ^ permalink raw reply [flat|nested] 10+ messages in thread

*Re: [PATCH] Add set/get functions for negative infinity in real.*2022-08-26 16:07 ` Jeff Law@ 2022-08-26 16:24 ` Aldy Hernandez2022-08-26 16:33 ` Jeff Law 0 siblings, 1 reply; 10+ messages in thread From: Aldy Hernandez @ 2022-08-26 16:24 UTC (permalink / raw) To: Jeff Law;+Cc:gcc-patches [-- Attachment #1: Type: text/plain, Size: 2073 bytes --] On Fri, Aug 26, 2022 at 6:08 PM Jeff Law via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > On 8/23/2022 4:33 AM, Aldy Hernandez via Gcc-patches wrote: > > 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. > > Funny in that I've fairly recently had the desire to do something a bit > similar. Let's consider 0.5, which we have a dconsthalf, but we don't > have dconstmhalf for -0.5. To get that value I create a dconsthalf > object and flip its sign. Similarly for a variety of other special > constants (particularly powers of two, but a few others as well). Ugh, yeah. I've been doing a lot of gymnastics in this space because frange's will have REAL_VALUE_TYPE endpoints. > > Consider making the "sign" argument a boolean. It's defined as a single > bit bitfield in the real_value structure. We don't want folks to pass > in values outside [0..1] for the sign if we can easily avoid it:-) I was trying to follow all the other functions in real.cc which have "int sign", though I suppose none of them are exported in the header file. OK pending tests? Aldy [-- Attachment #2: 0001-Add-set-get-functions-for-negative-infinity-in-real.patch --] [-- Type: text/x-patch, Size: 3003 bytes --] From 86664496f62f5d4d33da0347f5d5c017bd204513 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez <aldyh@redhat.com> Date: Sat, 20 Aug 2022 12:41:53 +0200 Subject: [PATCH] Add set/get functions for negative infinity in real.* 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); 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..dcf41b79f60 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, bool 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, bool 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..e01f9ed7282 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 *, bool 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 *, bool sign = false); extern bool real_nan (REAL_VALUE_TYPE *, const char *, int, format_helper); -- 2.37.1 ^ permalink raw reply [flat|nested] 10+ messages in thread

*Re: [PATCH] Add set/get functions for negative infinity in real.*2022-08-26 16:08 ` Jeff Law@ 2022-08-26 16:25 ` Aldy Hernandez2022-08-26 16:34 ` Jeff Law 0 siblings, 1 reply; 10+ messages in thread From: Aldy Hernandez @ 2022-08-26 16:25 UTC (permalink / raw) To: Jeff Law;+Cc:gcc-patches [-- Attachment #1: Type: text/plain, Size: 616 bytes --] On Fri, Aug 26, 2022 at 6:09 PM Jeff Law via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > > On 8/26/2022 9:43 AM, Aldy Hernandez via Gcc-patches wrote: > > Another real.* tweak. This time, adding a real_iszero() entry point > > to match the real_isnegzero. I could combine this patch with the > > negative infinity one in this thread if y'all would prefer. > > > > OK pending tests? > > > > p.s. I'd really like to go and benchmark all this real.* stuff > > (later), because I think we could inline a bunch of these functions in > > the header file. > Same comments as the INF patch. OK pending tests? Aldy [-- Attachment #2: 0002-Add-real_iszero-to-real.patch --] [-- Type: text/x-patch, Size: 1851 bytes --] From 23338ea7f2f079a35df52b240e7422ca2d449acd Mon Sep 17 00:00:00 2001 From: Aldy Hernandez <aldyh@redhat.com> Date: Fri, 26 Aug 2022 16:57:09 +0200 Subject: [PATCH] Add real_iszero to real.* We have real_isnegzero but no real_iszero. We could memcmp with 0, but that's just ugly. gcc/ChangeLog: * real.cc (real_iszero): New. * real.h (real_iszero): New. --- gcc/real.cc | 16 ++++++++++++++++ gcc/real.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/gcc/real.cc b/gcc/real.cc index dcf41b79f60..96f05ec68ca 100644 --- a/gcc/real.cc +++ b/gcc/real.cc @@ -1272,6 +1272,22 @@ real_isneg (const REAL_VALUE_TYPE *r) return r->sign; } +/* Determine whether a floating-point value X is plus or minus zero. */ + +bool +real_iszero (const REAL_VALUE_TYPE *r) +{ + return r->cl == rvc_zero; +} + +/* Determine whether a floating-point value X is zero with SIGN. */ + +bool +real_iszero (const REAL_VALUE_TYPE *r, bool sign) +{ + return real_iszero (r) && r->sign == sign; +} + /* Determine whether a floating-point value X is minus zero. */ bool diff --git a/gcc/real.h b/gcc/real.h index e01f9ed7282..ec78e8a8932 100644 --- a/gcc/real.h +++ b/gcc/real.h @@ -295,6 +295,12 @@ extern bool real_isneg (const REAL_VALUE_TYPE *); /* Determine whether a floating-point value X is minus zero. */ extern bool real_isnegzero (const REAL_VALUE_TYPE *); +/* Determine whether a floating-point value X is plus or minus zero. */ +extern bool real_iszero (const REAL_VALUE_TYPE *); + +/* Determine whether a floating-point value X is zero with SIGN. */ +extern bool real_iszero (const REAL_VALUE_TYPE *, bool sign); + /* Test relationships between reals. */ extern bool real_identical (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *); extern bool real_equal (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *); -- 2.37.1 ^ permalink raw reply [flat|nested] 10+ messages in thread

*Re: [PATCH] Add set/get functions for negative infinity in real.*2022-08-26 16:24 ` Aldy Hernandez@ 2022-08-26 16:33 ` Jeff Law2022-08-26 16:38 ` Aldy Hernandez 0 siblings, 1 reply; 10+ messages in thread From: Jeff Law @ 2022-08-26 16:33 UTC (permalink / raw) To: Aldy Hernandez;+Cc:gcc-patches On 8/26/2022 10:24 AM, Aldy Hernandez wrote: > On Fri, Aug 26, 2022 at 6:08 PM Jeff Law via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: >> >> >> On 8/23/2022 4:33 AM, Aldy Hernandez via Gcc-patches wrote: >>> 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. >> Funny in that I've fairly recently had the desire to do something a bit >> similar. Let's consider 0.5, which we have a dconsthalf, but we don't >> have dconstmhalf for -0.5. To get that value I create a dconsthalf >> object and flip its sign. Similarly for a variety of other special >> constants (particularly powers of two, but a few others as well). > Ugh, yeah. I've been doing a lot of gymnastics in this space because > frange's will have REAL_VALUE_TYPE endpoints. In our case we have instructions that can make of various FP constants, some of which may be negative. So we need to be able to recognize those constants. Leading to having to do similar gymnastics as what you're doing. > or > >> Consider making the "sign" argument a boolean. It's defined as a single >> bit bitfield in the real_value structure. We don't want folks to pass >> in values outside [0..1] for the sign if we can easily avoid it:-) > I was trying to follow all the other functions in real.cc which have > "int sign", though I suppose none of them are exported in the header > file. They probably pre-date using bool types in GCC. Feel free to update them if you need a mindless task at some point. > > OK pending tests? Of course. I should have noted that with such a change it'd pre-approved. jeff ^ permalink raw reply [flat|nested] 10+ messages in thread

*Re: [PATCH] Add set/get functions for negative infinity in real.*2022-08-26 16:25 ` Aldy Hernandez@ 2022-08-26 16:34 ` Jeff Law0 siblings, 0 replies; 10+ messages in thread From: Jeff Law @ 2022-08-26 16:34 UTC (permalink / raw) To: Aldy Hernandez;+Cc:gcc-patches On 8/26/2022 10:25 AM, Aldy Hernandez wrote: > On Fri, Aug 26, 2022 at 6:09 PM Jeff Law via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: >> >> >> On 8/26/2022 9:43 AM, Aldy Hernandez via Gcc-patches wrote: >>> Another real.* tweak. This time, adding a real_iszero() entry point >>> to match the real_isnegzero. I could combine this patch with the >>> negative infinity one in this thread if y'all would prefer. >>> >>> OK pending tests? >>> >>> p.s. I'd really like to go and benchmark all this real.* stuff >>> (later), because I think we could inline a bunch of these functions in >>> the header file. >> Same comments as the INF patch. > OK pending tests? Yes. Jeff ^ permalink raw reply [flat|nested] 10+ messages in thread

*2022-08-26 16:33 ` Jeff LawRe: [PATCH] Add set/get functions for negative infinity in real.*@ 2022-08-26 16:38 ` Aldy Hernandez0 siblings, 0 replies; 10+ messages in thread From: Aldy Hernandez @ 2022-08-26 16:38 UTC (permalink / raw) To: Jeff Law;+Cc:gcc-patches On Fri, Aug 26, 2022 at 6:34 PM Jeff Law <jeffreyalaw@gmail.com> wrote: > > > > On 8/26/2022 10:24 AM, Aldy Hernandez wrote: > > On Fri, Aug 26, 2022 at 6:08 PM Jeff Law via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > >> > >> > >> On 8/23/2022 4:33 AM, Aldy Hernandez via Gcc-patches wrote: > >>> 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. > >> Funny in that I've fairly recently had the desire to do something a bit > >> similar. Let's consider 0.5, which we have a dconsthalf, but we don't > >> have dconstmhalf for -0.5. To get that value I create a dconsthalf > >> object and flip its sign. Similarly for a variety of other special > >> constants (particularly powers of two, but a few others as well). > > Ugh, yeah. I've been doing a lot of gymnastics in this space because > > frange's will have REAL_VALUE_TYPE endpoints. > In our case we have instructions that can make of various FP constants, > some of which may be negative. So we need to be able to recognize those > constants. Leading to having to do similar gymnastics as what you're doing. It seems real.* needs some minor TLC. For one, a lot of these functions should be inlined. I suppose it wasn't meant to be abused the way we're about to in range-op-float.cc :-). Thanks. Aldy ^ permalink raw reply [flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-08-26 16:38 UTC | newest]Thread overview:10+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-08-23 10:33 [PATCH] Add set/get functions for negative infinity in real.* Aldy Hernandez 2022-08-26 15:43 ` Aldy Hernandez 2022-08-26 15:43 ` Aldy Hernandez 2022-08-26 16:08 ` Jeff Law 2022-08-26 16:25 ` Aldy Hernandez 2022-08-26 16:34 ` Jeff Law 2022-08-26 16:07 ` Jeff Law 2022-08-26 16:24 ` Aldy Hernandez 2022-08-26 16:33 ` Jeff Law 2022-08-26 16:38 ` Aldy Hernandez

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).