public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* unnormal Intel 80-bit long doubles and isnanl
@ 2020-11-24 10:53 Siddhesh Poyarekar
  2020-11-24 13:41 ` Szabolcs Nagy
  2020-11-24 21:28 ` Joseph Myers
  0 siblings, 2 replies; 17+ messages in thread
From: Siddhesh Poyarekar @ 2020-11-24 10:53 UTC (permalink / raw)
  To: gcc, Siddhesh Poyarekar via Libc-alpha, Florian Weimer,
	Carlos O'Donell, joseph

Hi,

The Intel 80-bit long double format has a concept of "unnormal" numbers 
that have a non-zero exponent and zero integer bit (i.e. bit 63) in the 
mantissa; all valid long double numbers have their integer bit set to 1. 
  Unnormal numbers are mentioned in "8.2.2 Unsupported Double 
Extended-Precision Floating-Point Encodings and Pseudo-Denormals" and 
listed in Table 8-3 in the Intel 64 and IA-32 Architectures Software 
Developer’s Manual Volume 1:Basic Architecture.

As per the manual, these numbers are considered unsupported and generate 
an invalid-operation exception if they are used as operands to any 
floating point instructions.  The question of this email is how the 
toolchain (including glibc) should treat these numbers since as things 
stand today, glibc and gcc disagree when it comes to isnanl.

glibc evaluates the bit pattern of the 80-bit long double and in the 
process, ignores the integer bit, i.e. bit 63.  As a result, it 
considers the unnormal number as a valid long double and isnanl returns 0.

gcc on the other hand, simply uses the number in a floating point 
comparison and uses the parity flag (which indicates an unordered 
compare, signalling a NaN) to decide if the number is a NaN.  The 
unnormal numbers behave like NaNs in this respect, in that they set the 
parity flag and with -fsignalling-nans, would result in an 
invalid-operation exception.  As a result, __builtin_isnanl returns 1 
for an unnormal number.

So the question is, which behaviour should be considered correct? 
Strictly speaking, unnormal numbers are listed separately from NaNs in 
the document and as such are distinct from NaNs.  So on the question of 
"is nan?" the answer ought to be "No".

On the flip side, the behaviour described (and experienced through code) 
is exactly the same as a NaN, i.e. a floating point operation sets the 
parity flag and generates an invalid-operation exception.  So if it 
looks like a NaN, behaves like a NaN, then even if the document hints 
(and it is just a hint right, since it doesn't specifically state it?) 
that it's different, it likely is a NaN.  What's more, one of the fixes 
to glibc[1] assumes that __builtin_isnanl will do the right thing.

The third alternative (which seems like a step back to me, but will 
concede that it is a valid resolution) is to state that unnormal input 
to isnanl would result in undefined behaviour and hence it is the 
responsibility of the application to ensure that inputs to isnanl are 
never unnormal.

Thoughts?

Siddhesh

[1] 
https://sourceware.org/git/?p=glibc.git;h=0474cd5de60448f31d7b872805257092faa626e4

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

end of thread, other threads:[~2020-11-27 17:40 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-24 10:53 unnormal Intel 80-bit long doubles and isnanl Siddhesh Poyarekar
2020-11-24 13:41 ` Szabolcs Nagy
2020-11-24 13:49   ` Florian Weimer
2020-11-24 13:59   ` Siddhesh Poyarekar
2020-11-24 14:16     ` Adhemerval Zanella
2020-11-24 14:28       ` Siddhesh Poyarekar
2020-11-24 14:43       ` Richard Biener
2020-11-24 16:12         ` Siddhesh Poyarekar
2020-11-24 14:23   ` Andreas Schwab
2020-11-24 21:28 ` Joseph Myers
2020-11-25  2:47   ` Siddhesh Poyarekar
2020-11-25 19:27     ` Joseph Myers
2020-11-26  0:23       ` Siddhesh Poyarekar
2020-11-27 11:31   ` Florian Weimer
2020-11-27 11:45     ` Siddhesh Poyarekar
2020-11-27 14:29       ` Florian Weimer
2020-11-27 17:40         ` Joseph Myers

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