public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: sgk@troutmask.apl.washington.edu,
	Harald Anlauf via Fortran <fortran@gcc.gnu.org>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fortran: fix compile-time simplification of SET_EXPONENT [PR109511]
Date: Fri, 14 Apr 2023 21:49:22 +0200	[thread overview]
Message-ID: <d1e090d6-e38b-1d59-52c0-57121ecd115c@gmx.de> (raw)
In-Reply-To: <ZDmqfsg+jIOOGqKY@troutmask.apl.washington.edu>

Hi Steve,

On 4/14/23 21:33, Steve Kargl via Gcc-patches wrote:
> On Fri, Apr 14, 2023 at 08:59:24PM +0200, Harald Anlauf via Fortran wrote:
>>
>> the compile-time simplification of intrinsic SET_EXPONENT was
>> broken since the early days of gfortran for argument X < 1
>> (including negative X) and for I < 0.  I identified and fixed
>> several issues in the implementation.  The testcase explores
>> argument space comparing compile-time and runtime results and
>> is checked against Intel.
>>
>> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
>>
>
> Yes, it is certainly better than the current situation.
>
>> This is not a regression, but can lead to wrong code.
>> Would it be OK to backport to open branches?
>
> Sure.  Looks simply and fairly specific.

OK, thanks, will proceed.


> I was wondering about the difference between set_exponent()
> and scale(), and found that set_exponent() talks about IEEE
> values while scale() doesn't.  I'm wondering if we should
> add the IEEE special cases to the testsuite.  Of particular
> note, I doubt that this is true:
>
>     If X is an IEEE NaN, the result is the same NaN.
>
> program foo
>     real x, y
>     x = 1
>     y = x - x
>     x = (x - x) / y
>     print '(F4.0,1X,Z8.8)', x, x
>     y = set_exponent(x,1)
>     print '(F4.0,1X,Z8.8)', y, y
> end program foo
>
>   gfcx -o z a.f90 && ./z
>   NaN FFC00000
>   NaN 7FC00000
>
> Those are not the same NaN.  The second is a qNaN.
> The first looks like a qNaN with the sign bit set.

Until now there was no testing at all of SET_EXPONENT in the testsuite.
It would be really good to have better coverage of compile-time and
runtime behavior of the intrinsics and checking consistency ... ;-)

I think you have much more experience in that area.  (Hint!)

Cheers,
Harald



WARNING: multiple messages have this Message-ID
From: Harald Anlauf <anlauf@gmx.de>
To: gcc-patches@gcc.gnu.org
Cc: fortran@gcc.gnu.org
Subject: Re: [PATCH] Fortran: fix compile-time simplification of SET_EXPONENT [PR109511]
Date: Fri, 14 Apr 2023 21:49:22 +0200	[thread overview]
Message-ID: <d1e090d6-e38b-1d59-52c0-57121ecd115c@gmx.de> (raw)
Message-ID: <20230414194922.b4DyOUfn-bTWCc7ZXNMrVv0y5yNIJYt_LfDdVZSp8HU@z> (raw)
In-Reply-To: <ZDmqfsg+jIOOGqKY@troutmask.apl.washington.edu>

Hi Steve,

On 4/14/23 21:33, Steve Kargl via Gcc-patches wrote:
> On Fri, Apr 14, 2023 at 08:59:24PM +0200, Harald Anlauf via Fortran wrote:
>>
>> the compile-time simplification of intrinsic SET_EXPONENT was
>> broken since the early days of gfortran for argument X < 1
>> (including negative X) and for I < 0.  I identified and fixed
>> several issues in the implementation.  The testcase explores
>> argument space comparing compile-time and runtime results and
>> is checked against Intel.
>>
>> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
>>
> 
> Yes, it is certainly better than the current situation.
> 
>> This is not a regression, but can lead to wrong code.
>> Would it be OK to backport to open branches?
> 
> Sure.  Looks simply and fairly specific.

OK, thanks, will proceed.


> I was wondering about the difference between set_exponent()
> and scale(), and found that set_exponent() talks about IEEE
> values while scale() doesn't.  I'm wondering if we should
> add the IEEE special cases to the testsuite.  Of particular
> note, I doubt that this is true:
> 
>     If X is an IEEE NaN, the result is the same NaN.
> 
> program foo
>     real x, y
>     x = 1
>     y = x - x
>     x = (x - x) / y
>     print '(F4.0,1X,Z8.8)', x, x
>     y = set_exponent(x,1)
>     print '(F4.0,1X,Z8.8)', y, y
> end program foo
> 
>   gfcx -o z a.f90 && ./z
>   NaN FFC00000
>   NaN 7FC00000
> 
> Those are not the same NaN.  The second is a qNaN.
> The first looks like a qNaN with the sign bit set.

Until now there was no testing at all of SET_EXPONENT in the testsuite.
It would be really good to have better coverage of compile-time and
runtime behavior of the intrinsics and checking consistency ... ;-)

I think you have much more experience in that area.  (Hint!)

Cheers,
Harald




  parent reply	other threads:[~2023-04-14 19:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14 18:59 Harald Anlauf
2023-04-14 19:33 ` Steve Kargl
2023-04-14 19:48   ` Steve Kargl
2023-04-14 19:49   ` Harald Anlauf [this message]
2023-04-14 19:49     ` Harald Anlauf
2023-04-14 21:19     ` Steve Kargl
2023-04-17 19:41 ` Bernhard Reutner-Fischer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d1e090d6-e38b-1d59-52c0-57121ecd115c@gmx.de \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=sgk@troutmask.apl.washington.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).