public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgcc/116017] New: libgcc/riscv/softfp: Fix loss of sign when truncating NaN values
@ 2024-07-20 18:45 keithp at keithp dot com
  2024-07-20 19:07 ` [Bug libgcc/116017] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: keithp at keithp dot com @ 2024-07-20 18:45 UTC (permalink / raw)
  To: gcc-bugs

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;
        }

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

end of thread, other threads:[~2024-07-20 22:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-20 18:45 [Bug libgcc/116017] New: libgcc/riscv/softfp: Fix loss of sign when truncating NaN values keithp at keithp dot com
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

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