public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "keithp at keithp dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libgcc/116017] New: libgcc/riscv/softfp: Fix loss of sign when truncating NaN values
Date: Sat, 20 Jul 2024 18:45:24 +0000	[thread overview]
Message-ID: <bug-116017-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116017

            Bug ID: 116017
           Summary: libgcc/riscv/softfp: Fix loss of sign when truncating
                    NaN values
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgcc
          Assignee: unassigned at gcc dot gnu.org
          Reporter: keithp at keithp dot com
  Target Milestone: ---

Created attachment 58714
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58714&action=edit
Proposed patch

Using soft float to truncate 128-bit -nan to 64-bit float loses the sign bit.
When _FP_KEEP_NANFRACP is not set, the fraction *and sign* of a NaN value are
discarded in _FP_PACK_SEMIRAW causing this problem.

I'll note that riscv is the only target which doesn't set this value, so it
could also be that the _FP_KEEPNANFRACP code is just broken?

Test application:

        #include <stdio.h>
        #include <math.h>

        int main(void)
        {
            volatile long double    ld;
            volatile double d;

            ld = (long double) NAN;
            ld = -ld;
            d = ld;
            printf("%a\n", d);
            return signbit(d) ? 0 : 1;
        }

             reply	other threads:[~2024-07-20 18:45 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-20 18:45 keithp at keithp dot com [this message]
2024-07-20 19:07 ` [Bug libgcc/116017] " pinskia at gcc dot gnu.org
2024-07-20 19:31 ` pinskia at gcc dot gnu.org
2024-07-20 19:33 ` pinskia at gcc dot gnu.org
2024-07-20 19:34 ` pinskia at gcc dot gnu.org
2024-07-20 22:38 ` keithp at keithp dot com

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=bug-116017-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).