* [Bug target/113578] Incorrect sign printed for -nan on RISC-V
2024-01-24 11:40 [Bug target/113578] New: Incorrect signbit for -nan on RISC-V redi at gcc dot gnu.org
@ 2024-01-24 11:41 ` redi at gcc dot gnu.org
2024-01-24 12:28 ` jsm28 at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-24 11:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113578
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Incorrect signbit for -nan |Incorrect sign printed for
|on RISC-V |-nan on RISC-V
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
It could also be a glibc bug for RISC-V of course.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/113578] Incorrect sign printed for -nan on RISC-V
2024-01-24 11:40 [Bug target/113578] New: Incorrect signbit for -nan on RISC-V redi at gcc dot gnu.org
2024-01-24 11:41 ` [Bug target/113578] Incorrect sign printed " redi at gcc dot gnu.org
@ 2024-01-24 12:28 ` jsm28 at gcc dot gnu.org
2024-01-24 17:34 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2024-01-24 12:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113578
--- Comment #2 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
If a conversion from float to double (for passing in variable arguments) occurs
at runtime on RISC-V, that will produce a positive-signed NaN (that's what the
RISC-V floating-point instructions do). Cf.
https://sourceware.org/bugzilla/show_bug.cgi?id=29501 (for strfrom functions).
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/113578] Incorrect sign printed for -nan on RISC-V
2024-01-24 11:40 [Bug target/113578] New: Incorrect signbit for -nan on RISC-V redi at gcc dot gnu.org
2024-01-24 11:41 ` [Bug target/113578] Incorrect sign printed " redi at gcc dot gnu.org
2024-01-24 12:28 ` jsm28 at gcc dot gnu.org
@ 2024-01-24 17:34 ` pinskia at gcc dot gnu.org
2024-01-24 17:42 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-24 17:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113578
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
and since __builtin_printf is variadic function, floats are promoted to double
causing the removal of the payload of NaN on RISCV at runtime ...
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/113578] Incorrect sign printed for -nan on RISC-V
2024-01-24 11:40 [Bug target/113578] New: Incorrect signbit for -nan on RISC-V redi at gcc dot gnu.org
` (2 preceding siblings ...)
2024-01-24 17:34 ` pinskia at gcc dot gnu.org
@ 2024-01-24 17:42 ` redi at gcc dot gnu.org
2024-01-24 17:56 ` redi at gcc dot gnu.org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-24 17:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113578
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
So the reason the sign isn't lost for -O1 is that the conversion to double
happens at compile-time and a negative nan is compiled into the executable,
rather than being converted by the processor at runtime.
Huh, OK. I guess Matthias can close his Debian bug then.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/113578] Incorrect sign printed for -nan on RISC-V
2024-01-24 11:40 [Bug target/113578] New: Incorrect signbit for -nan on RISC-V redi at gcc dot gnu.org
` (3 preceding siblings ...)
2024-01-24 17:42 ` redi at gcc dot gnu.org
@ 2024-01-24 17:56 ` redi at gcc dot gnu.org
2024-05-10 11:48 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-24 17:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113578
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Maybe we could make it work for std::ostream with something like:
--- a/libstdc++-v3/include/std/ostream
+++ b/libstdc++-v3/include/std/ostream
@@ -233,7 +233,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 117. basic_ostream uses nonexistent num_put member functions.
+#ifdef __riscv
+ return _M_insert(__builtin_copysign((double)__f,
+ (double)-!!__builtin_signbit(__f));
+#else
return _M_insert(static_cast<double>(__f));
+#endif
}
__ostream_type&
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/113578] Incorrect sign printed for -nan on RISC-V
2024-01-24 11:40 [Bug target/113578] New: Incorrect signbit for -nan on RISC-V redi at gcc dot gnu.org
` (4 preceding siblings ...)
2024-01-24 17:56 ` redi at gcc dot gnu.org
@ 2024-05-10 11:48 ` redi at gcc dot gnu.org
2024-05-10 21:32 ` andrew at sifive dot com
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-10 11:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113578
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Joseph S. Myers from comment #2)
> If a conversion from float to double (for passing in variable arguments)
> occurs at runtime on RISC-V, that will produce a positive-signed NaN (that's
> what the RISC-V floating-point instructions do). Cf.
> https://sourceware.org/bugzilla/show_bug.cgi?id=29501 (for strfrom
> functions).
This seems to happen on Apple M1 chips too.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/113578] Incorrect sign printed for -nan on RISC-V
2024-01-24 11:40 [Bug target/113578] New: Incorrect signbit for -nan on RISC-V redi at gcc dot gnu.org
` (5 preceding siblings ...)
2024-05-10 11:48 ` redi at gcc dot gnu.org
@ 2024-05-10 21:32 ` andrew at sifive dot com
2024-05-13 11:09 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: andrew at sifive dot com @ 2024-05-10 21:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113578
Andrew Waterman <andrew at sifive dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrew at sifive dot com
--- Comment #7 from Andrew Waterman <andrew at sifive dot com> ---
In the case of the M1, I don't think the problem is that the sign bit isn't
making it to printf; I think printf is choosing not to print the sign. The
ARMv8 fcvt instruction preserves the sign bit when converting NaNs (unless the
processor is in default-NaN mode, which Mac OS does not seem to use).
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/113578] Incorrect sign printed for -nan on RISC-V
2024-01-24 11:40 [Bug target/113578] New: Incorrect signbit for -nan on RISC-V redi at gcc dot gnu.org
` (6 preceding siblings ...)
2024-05-10 21:32 ` andrew at sifive dot com
@ 2024-05-13 11:09 ` redi at gcc dot gnu.org
2024-05-13 22:36 ` andrew at sifive dot com
2024-05-15 11:13 ` redi at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-13 11:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113578
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Hmm, you could be right. It looks like the printf in Apple libc doesn't print
"-nan" even when not converting from float to double.
According to
https://developer.r-project.org/Blog/content/post/2020-11-02-apple-silicon.html
the Apple silicon NaN payloads are not propagated by default, but I don't know
if that means the signbit is not propagated. I assumed it meant they were
running in default NaN mode.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/113578] Incorrect sign printed for -nan on RISC-V
2024-01-24 11:40 [Bug target/113578] New: Incorrect signbit for -nan on RISC-V redi at gcc dot gnu.org
` (7 preceding siblings ...)
2024-05-13 11:09 ` redi at gcc dot gnu.org
@ 2024-05-13 22:36 ` andrew at sifive dot com
2024-05-15 11:13 ` redi at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: andrew at sifive dot com @ 2024-05-13 22:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113578
--- Comment #9 from Andrew Waterman <andrew at sifive dot com> ---
For my M1 running Ventura 13.6, NaN payloads _are_ propagated, sign bit
included. This test prints fffc0080:
int main()
{
volatile long long ll = 0xffff801000000000;
volatile double d;
memcpy((char*)&d, (char*)&ll, sizeof(ll));
volatile float f = d;
volatile int i;
memcpy((char*)&i, (char*)&f, sizeof(i));
printf("%x\n", i);
return 0;
}
So perhaps Apple has switched from default-NaN mode to NaN-propagating mode in
the time since that R blog post was written.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/113578] Incorrect sign printed for -nan on RISC-V
2024-01-24 11:40 [Bug target/113578] New: Incorrect signbit for -nan on RISC-V redi at gcc dot gnu.org
` (8 preceding siblings ...)
2024-05-13 22:36 ` andrew at sifive dot com
@ 2024-05-15 11:13 ` redi at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2024-05-15 11:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113578
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-05-15
Resolution|INVALID |---
Status|RESOLVED |REOPENED
Ever confirmed|0 |1
--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I'm reopening this to deal with it as a libstdc++ bug, because LWG seems to
support changing the standard so that this Just Works.
https://cplusplus.github.io/LWG/issue4101
^ permalink raw reply [flat|nested] 11+ messages in thread